3
sys.path.append("python_hand_library/")
12
from Grasp import Grasp
13
from grasps_parser import GraspParser
16
class StepPlayer(wx.StaticBox):
18
A GUI widget diplaying tools to replay recorded grasps from an xml file.
20
def __init__(self, parent, id, title,hand):
22
Initializes all the variables needed by the widget
24
@param parent : the wx.window component containing the widget
25
@param id : the identifying number of the widget
26
@param title : the title of the widget shown on the border
27
@param hand : the library connecting to ROS
29
wx.StaticBox.__init__(self,parent,id, title)
30
self.myShadowHand = hand
31
self.panel = wx.Panel(parent, id)
32
self.file_to_play_tf = 0
36
self.button_browse = 0
42
def drawStepPlayer(self):
44
Actually draws the component
46
sizer = wx.FlexGridSizer(rows=2, cols=1, hgap=5, vgap = 5)
47
#sizer_top = wx.FlexGridSizer(cols=2)
48
sizer_down = wx.GridSizer(cols=2)
49
sizer_down_left = wx.FlexGridSizer(rows=2)
51
#self.file_to_play_tf = wx.TextCtrl(self.panel, -1)
52
#self.file_to_play_tf.SetEditable(False)
54
self.button_play = wx.Button(self.panel, -1, 'Play')
55
self.button_play.Enable(False)
56
self.button_browse = wx.FilePickerCtrl(self.panel, -1)
57
self.frequency_cb = wx.CheckBox(self.panel, -1, label='Play all the file')
58
self.frequency_tf = wx.TextCtrl(self.panel, -1)
59
self.frequency_tf.SetValue('Speed')
60
self.frequency_tf.Enable(False)
62
sizer.Add(self.button_browse, flag=wx.EXPAND)
63
sizer_down_left.Add(self.frequency_cb)
64
sizer_down_left.Add(self.frequency_tf)
65
sizer_down.Add(sizer_down_left)
66
sizer_down.Add(self.button_play, 0, wx.ALIGN_CENTER)
68
#sizer.Add(sizer_top, flag= wx.EXPAND)
70
border = wx.BoxSizer()
71
border.Add(sizer, 0, wx.ALL, 15)
72
self.panel.SetSizer(border)
74
self.frequency_cb.Bind(wx.EVT_CHECKBOX, self.checkBoxEvent)
75
self.button_play.Bind(wx.EVT_BUTTON, self.playEvent)
76
self.button_browse.Bind(wx.EVT_FILEPICKER_CHANGED, self.chooseEvent)
78
def checkBoxEvent(self, event):
80
Binds the checkbox control, activates the speed field
82
@param event : the event thrown by the checkbox when clicked
84
if self.frequency_cb.IsChecked():
85
self.frequency_tf.Enable(True)
87
self.frequency_tf.Enable(False)
89
def chooseEvent(self, event):
91
Binds the browser to its action : parsing the choosen file
93
@param event : the event thrown when the button is clicked
95
parser = GraspParser()
96
parser.parse_tree(self.button_browse.GetPath())
97
grasps = parser.grasps
98
for key, value in grasps.items():
99
self.toSend.append(value)
101
self.button_play.Enable(True)
103
def playEvent(self, event):
105
Binds the play button to its action : reading the file with the specified options
107
@param event : the event thrown when the button is clicked
109
print self.button_browse.GetPath()
111
if self.frequency_cb.IsChecked() and self.ready:
112
speed = float(self.frequency_tf.GetValue())
113
for index in range(0, len(self.toSend)):
115
self.myShadowHand.sendupdate_from_dict(self.toSend[index].joints_and_positions)
116
if (not self.frequency_cb.IsChecked()) and self.ready:
117
if self.lastSent != len(self.toSend)-1:
118
self.lastSent = self.lastSent+1