icub-client
drive_control_gui.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from collections import OrderedDict
4 from Tkinter import *
5 import sys, getopt
6 argv = sys.argv[1:]
7 
8 x = 40
9 y = 40
10 h = 200
11 w = 400
12 
13 try:
14  opts, args = getopt.getopt(argv,"w:h:x:y:",["width=","height=","x=","y="])
15 except getopt.GetoptError:
16  print 'drive_control_gui -w <width> -h <height> -x <x> -y <y>'
17  sys.exit(2)
18 for opt, arg in opts:
19  if opt in ('-h', '--height'):
20  h=int(arg)
21  elif opt in ('-w', '--weight'):
22  w=int(arg)
23  elif opt in ('-x'):
24  x=int(arg)
25  elif opt in ('-y'):
26  y=int(arg)
27 
28 
29 from drive_control_rpc import pointing, tagging, reset_all, freeze_all, unfreeze_all, narrate, manual_mode, automatic_mode, close_ports, updateDriveList, trigger_behavior, updateBehaviorList
30 
31 window = Tk()
32 
33 def on_closing():
34  window.destroy()
35  close_ports()
36 
38  for button in driveButtons.keys():
39 
40  driveButtons[button].destroy()
41  driveList = updateDriveList()
42  for i,drive in enumerate(driveList):
43  driveButtons[drive]=Button(window, text=drive, command=lambda: trigger_behavior(drive))
44  driveButtons[drive].grid(row=i+3, column=1)
46  for button in behaviorButtons.keys():
47 
48  behaviorButtons[button].destroy()
49  behaviorList = updateBehaviorList()
50  for i,beh in enumerate(behaviorList):
51  behaviorButtons[beh]=Button(window, text=beh, command=lambda: trigger_behavior(beh))
52  behaviorButtons[beh].grid(row=i+3, column=2)
53 def please():
54  print 'Pleaes Update'
55 title = Label(window, text="Manual drive control").grid(row=0,column=1)
56 
57 labels = OrderedDict()
58 
59 labels["General Control:"] = Label(window,text="General Control:").grid(row=1,column=0)
60 labels["Drive Control:"] = Label(window,text="Drive Control:").grid(row=1,column=1)
61 labels["Behavior Control:"] = Label(window,text="Behavior Control:").grid(row=1,column=2)
62 
63 
64 
65 fixed_buttons = OrderedDict()
66 update_buttons = OrderedDict()
67 driveButtons = OrderedDict()
68 behaviorButtons = OrderedDict()
69 update_buttons["Update drive list"] = Button(window, text="Update list", command=updateDriveButtons).grid(row=2,column=1)
70 update_buttons["Update behavior list"] = Button(window, text="Update list", command=updateBehaviorButtons).grid(row=2,column=2)
71 
72 fixed_buttons["Manual mode"] = Button(window, text="Manual mode", command=manual_mode)
73 fixed_buttons["Autonomous mode"] = Button(window, text="Autonomous mode", command=automatic_mode)
74 fixed_buttons["freeze"] = Button(window, text="Freeze", command=freeze_all)
75 fixed_buttons["unfreeze"] = Button(window, text="Unfreeze", command=unfreeze_all)
76 fixed_buttons["reset"] = Button(window, text="Reset", command=reset_all)
77 driveButtons["dummyButtonD"] = Button(window, text="dummyButton", command=please)
78 behaviorButtons["dummyButtonB"] = Button(window, text="dummyButton", command=please)
79 
80 
81 
82 for i,b in enumerate(fixed_buttons.values()):
83  b.grid(row=i+2, column=0)
84 
85 for i,b in enumerate(driveButtons.values()):
86  b.grid(row=i+3, column=1)
87 for i,b in enumerate(behaviorButtons.values()):
88  b.grid(row=i+3, column=2)
89 
90 window.geometry('%dx%d+%d+%d' % (w, h, x, y))
91 window.protocol("WM_DELETE_WINDOW", on_closing)
92 window.mainloop()
def trigger_behavior(behavior)