3
sys.path.append("python_hand_library/")
4
import roslib; roslib.load_manifest('sr_control_gui')
6
from shadowhand_ros import ShadowHand_ROS
7
from hand_joint_sliders import JointSliders
8
from hand_grasps_controller import GraspsSaver
9
from hand_joint_chooser import JointChooser
10
from hand_visualisation_manager import VisualisationManager
11
from hand_step_recorder import StepRecorder
12
from hand_step_player import StepPlayer
13
from hand_accessories import Accessories
14
from cyberglove_library import Cyberglove
15
from arm_joint_sliders import ArmJointSliders
16
from glove import Glove
18
#import the wxpython GUI package
25
class MainWindow(wx.Frame):
27
The main window of the GUI, displaying all the information about the
30
def __init__(self, parent, id, title):
32
Initializes the window and create all the widgets and the menu
34
@param parent : the window containing the program. Should be None
35
@param id : the identifying number the the frame
36
@param title : the title displayed on the window
38
wx.Frame.__init__(self, parent, id, title, size=(1280,600))
40
self.myShadowHand = ShadowHand_ROS()
42
self.myCyberglove = Cyberglove()
48
fil.Append(MENU_EXIT,"Exit","Quit")
50
rec.Append(MENU_RECORD,"Record","Record steps")
51
menubar.Append(fil,"File")
52
menubar.Append(rec,"Record")
53
wx.EVT_MENU(self, MENU_EXIT, self.menuListener)
54
wx.EVT_MENU(self, MENU_RECORD, self.menuListener)
55
self.SetMenuBar(menubar)
58
self.tabs = wx.Notebook(self, -1, style=(wx.NB_TOP))
60
#Create pages and layouts
61
page1 = wx.Panel(self.tabs,-1)
62
layout1 = wx.FlexGridSizer(cols=1, rows=2, vgap=20)
63
page1.SetSizer(layout1, True)
64
#if self.myShadowHand.has_arm():
65
#subPage0 = wx.Panel(page1,-1)
66
#sublayout0 = wx.FlexGridSizer(cols=2, hgap=10)
67
#subPage0.SetSizer(sublayout0, True)
68
subPage1 = wx.Panel(page1, -1)
69
sublayout1 = wx.FlexGridSizer(cols=2, rows=1, vgap=20)
70
subPage1.SetSizer(sublayout1, True)
71
page2 = wx.Panel(self.tabs,-1)
72
layout2 = wx.FlexGridSizer(cols=1, rows=2, vgap=20)
73
page2.SetSizer(layout2, True)
74
page3 = wx.Panel(self.tabs,-1)
75
layout3 = wx.FlexGridSizer(cols=1, rows=2, vgap=20)
76
page3.SetSizer(layout3, True)
77
page4 = wx.Panel(self.tabs,-1)
78
layout4 = wx.FlexGridSizer(cols=1, rows=2, hgap = 20,vgap=20)
79
page4.SetSizer(layout4, True)
82
#if self.myShadowHand.has_arm():
83
#jointSliders = JointSliders(subPage0, -1,"Joints",self.myShadowHand)
85
#jointSliders = JointSliders(page1, -1,"Joints",self.myShadowHand)
86
jointSliders = JointSliders(page1, -1,"Joints",self.myShadowHand)
87
jointChooser = JointChooser(subPage1,-1,"Joint Chooser", self.myShadowHand)
88
self.grasps = GraspsSaver(subPage1, -1, "Grasps", self.myShadowHand, jointChooser)
89
visualisation = VisualisationManager(page2, -1, "Visualisation", self.myShadowHand)
90
self.step = StepRecorder(self,-1,'Step recorder', self.myShadowHand, self.grasps)
91
self.player = StepPlayer(page3,-1,'Step Player', self.myShadowHand)
93
self.accessories = Accessories(page4,-1,'Accessories', self.myShadowHand)
94
if self.myCyberglove.has_glove():
95
self.glove = Glove(page4,-1,'Cyberglove', self.myCyberglove)
97
if self.myShadowHand.has_arm():
98
arm_slider = ArmJointSliders(page4, -1, "Arm", self.myShadowHand)
100
#Add the widgets to display
101
self.addControler(layout1, jointSliders)
102
layout1.Add(subPage1)
103
self.addControler(sublayout1, self.grasps)
104
self.addControler(sublayout1, jointChooser)
106
self.addControler(layout2, visualisation)
107
self.addControler(layout3, self.player)
108
self.addControler(layout4, self.accessories)
109
if self.myShadowHand.has_arm():
110
self.addControler(layout4, arm_slider)
112
layout4.Add(wx.Panel(page4,-1))
113
if self.myCyberglove.has_glove():
114
self.addControler(layout4, self.glove)
116
layout4.Add(wx.Panel(page4,-1))
118
self.tabs.AddPage(page1,'Hand control')
119
self.tabs.AddPage(page2, 'Visualisation')
120
self.tabs.AddPage(page3, 'Player')
121
self.tabs.AddPage(page4, 'Accessories')
123
if self.myShadowHand.has_arm():
124
print "Arm detected."
126
if self.myCyberglove.has_glove():
127
print "Glove detected."
130
def addControler(self,container,controler, flag = wx.ALIGN_CENTER):
132
Adds a widget to the window
134
@param container : the sizer which should contain the widget
135
@param controler : the widget to add
137
sizertmp=wx.StaticBoxSizer(controler,wx.HORIZONTAL)
138
sizertmp.Add(controler.panel,0,wx.ALL,2)
139
container.Add(sizertmp, flag)
141
def menuListener(self, event):
143
Bind the menu to its action
145
@param event : the event thrown by the clicked component
147
if event.GetId() == MENU_EXIT :
149
if event.GetId() == MENU_RECORD :
150
#self.step = StepRecorder(self,-1,'Step recorder', self.myShadowHand, self.grasps)
158
frame = MainWindow(None,-1, "ShadowHand controller")
161
self.SetTopWindow(frame)
170
if __name__ == "__main__":