18 from threading
import Thread
20 from gi
import pygtkcompat
22 pygtkcompat.enable_gtk(version=
'3.0')
23 gi.require_version(
'Gdk',
'3.0')
24 gi.require_version(
'Gtk',
'3.0')
33 from cob_msgs.msg
import EmergencyStopState
34 from simple_script_server
import *
35 from command_gui_buttons
import command_gui_buttons
37 planning_enabled =
False 38 base_diff_enabled =
False 39 confirm_commands_enabled =
True 48 global planning_enabled
49 global base_diff_enabled
50 global confirm_commands_enabled
51 execute_command =
True 54 if confirm_commands_enabled
and ((func.__name__ !=
"stop")
and (largs[1] !=
'stop')):
55 confirm_dialog = gtk.MessageDialog(
None, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,
"Execute Command?")
56 if confirm_dialog.run() == gtk.RESPONSE_NO:
57 execute_command =
False 58 confirm_dialog.destroy()
60 if(largs[0] ==
"arm"):
62 largs.append(
"planned")
63 if(largs[0] ==
"base"):
64 if(base_diff_enabled):
68 Thread(target=func, args=tuple(largs)).
start()
73 if not result.success:
74 result_dialog = gtk.MessageDialog(
None, 0, gtk.MESSAGE_ERROR,
76 "Executing " + func.__name__ +
"(" + args[0] +
") failed!")
77 gtk.gdk.threads_enter()
78 result_dialog.format_secondary_text(result.message)
79 gtk.gdk.threads_leave()
80 gtk.gdk.threads_enter()
82 gtk.gdk.threads_leave()
83 gtk.gdk.threads_enter()
84 result_dialog.destroy()
85 gtk.gdk.threads_leave()
95 gtk.Frame.__init__(self)
97 self.set_label(
"general")
98 self.set_shadow_type(gtk.SHADOW_IN)
99 self.
vbox = gtk.VBox(
False, 0)
108 hbox=gtk.HBox(
True, 0)
114 self.vbox.pack_start(hbox,
False,
False, 5)
116 butstop = gtk.Button(
"Stop all")
117 butstop.connect(
"clicked",
lambda w: self.
stop_all(buttons.stop_buttons))
118 self.vbox.pack_start(butstop,
False,
False, 5)
120 butinit = gtk.Button(
"Init all")
121 butinit.connect(
"clicked",
lambda w: self.
init_all(buttons.init_buttons))
122 self.vbox.pack_start(butinit,
False,
False, 5)
124 butrec = gtk.Button(
"Recover all")
125 butrec.connect(
"clicked",
lambda w: self.
recover_all(buttons.recover_buttons))
126 self.vbox.pack_start(butrec,
False,
False, 5)
128 butrec = gtk.Button(
"Halt all")
129 butrec.connect(
"clicked",
lambda w: self.
halt_all(buttons.halt_buttons))
130 self.vbox.pack_start(butrec,
False,
False, 5)
132 plan_check = gtk.CheckButton(
"Planning")
134 self.vbox.pack_start(plan_check,
False,
False, 5)
136 base_mode_check = gtk.CheckButton(
"Base Diff")
138 self.vbox.pack_start(base_mode_check,
False,
False, 5)
140 confirm_com_check = gtk.CheckButton(
"Confirm Commands")
141 confirm_com_check.set_active(confirm_commands_enabled)
143 self.vbox.pack_start(confirm_com_check,
False,
False, 5)
145 but = gtk.Button(stock=gtk.STOCK_QUIT )
146 but.connect(
"clicked",
lambda w: gtk.main_quit())
147 self.vbox.pack_start(but,
False,
False, 5)
151 for component_name
in component_names:
152 self.sss.stop(component_name,blocking=
False)
155 for component_name
in component_names:
156 self.sss.init(component_name,
False)
159 for component_name
in component_names:
160 self.sss.recover(component_name,
False)
163 for component_name
in component_names:
164 self.sss.halt(component_name,
False)
170 gtk.gdk.threads_enter()
171 self.status_image.set_from_file(roslib.packages.get_pkg_dir(
"cob_command_gui") +
"/common/files/icons/error.png")
172 self.status_label.set_text(
"EM Stop !")
173 gtk.gdk.threads_leave()
178 self.status_image.set_from_file(roslib.packages.get_pkg_dir(
"cob_command_gui") +
"/common/files/icons/ok.png")
179 gtk.gdk.threads_enter()
180 self.status_label.set_text(
"Status OK")
181 gtk.gdk.threads_leave()
186 global planning_enabled
187 if(planning_enabled):
188 planning_enabled =
False 190 planning_enabled =
True 193 global base_diff_enabled
194 if(base_diff_enabled):
195 base_diff_enabled =
False 197 base_diff_enabled =
True 200 global confirm_commands_enabled
201 if(confirm_commands_enabled):
202 confirm_commands_enabled =
False 204 confirm_commands_enabled =
True 209 gtk.Frame.__init__(self)
210 self.set_label(labeltext)
211 self.set_shadow_type(gtk.SHADOW_IN)
216 but = gtk.Button(text)
217 but.connect(
"clicked", startGTK, command)
219 self.vbox.pack_start(but,
False,
False, 5)
230 self.gpanel.setEMStop(msg.emergency_state)
234 rospy.init_node(
'cob_knoeppkes')
235 rospy.Subscriber(
"/emergency_stop_state", EmergencyStopState, self.
emcb)
237 self.
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
239 self.window.set_title(
"cob command gui")
240 self.window.set_size_request(1000, 500)
241 vbox = gtk.VBox(
False, 1)
243 vbox.pack_start(self.
hbox,
True,
True, 0)
246 self.hbox.pack_start(self.
gpanel,
True,
True, 3)
248 for pname, actions
in panels:
250 for aname, func, args
in actions:
251 panel.addButton(text=aname, command=
lambda f=func, a=args:
start(f, a))
252 self.hbox.pack_start(panel,
True,
True, 3)
255 context_id = self.status_bar.get_context_id(
"Statusbar")
256 string =
"Connected to $ROS_MASTER_URI=" + os.environ.get(
"ROS_MASTER_URI")
257 self.status_bar.push(context_id, string)
258 vbox.pack_start(self.
status_bar,
False,
False, 0)
259 self.window.add(vbox)
260 self.window.show_all()
261 gtk.gdk.threads_init()
262 gtk.gdk.threads_enter()
264 gtk.gdk.threads_leave()
270 if __name__ ==
"__main__":
271 signal.signal(signal.SIGINT, signal_handler)
def base_mode_toggle(self, b)
def recover_all(self, component_names)
def signal_handler(signal, frame)
def confirm_com_toggle(self, b)
Implementation of knoeppkes command gui.
def __init__(self, buttons)
def halt_all(self, component_names)
def planned_toggle(self, b)
def __init__(self, master=None, labeltext="")
def startGTK(widget, data)
def start(func, args)
Executes a button click in a new thread.
Class for gtk panel implementation.
def stop_all(self, component_names)
def call_thread(func, args)
use this function in order to evaluate result of action_handle, i.e.
Class for general gtk panel implementation.
def addButton(self, text, command)
def delete_event(self, widget, event, data=None)
def init_all(self, component_names)