def fill_param_box(self, widget, data=None): self.task_param_hbox.hide_all() taskname = self.task_combobox.get_active_text() for c in self.task_param_hbox.get_children(): self.task_param_hbox.remove(c) selected_task = None for t in tasks.get_all_tasks(): if t.__name__ == taskname: selected_task = t args = inspect.getargspec(selected_task.__init__)[0] defaults = inspect.getargspec(selected_task.__init__)[3] reslist = [] for i in range(len(args)): a = args[i] if a != "self" and a != "drone" and a != "callback" and a != "context": l = gtk.Label(a) e = gtk.Entry(10) e.set_width_chars(10) if defaults is not None and len(defaults) > 0 and i >= (len(args) - len(defaults)): e.set_text(str(defaults[i - (len(args) - len(defaults))])) e.set_visibility(True) reslist.append((a, e)) self.task_param_hbox.pack_start(l, False, False, 3) self.task_param_hbox.pack_start(e, False, False, 3) self.task_param_hbox.resize_children() self.task_param_hbox.show_all() self.task_param_hbox.show()
def build_gui(self): self.colormap = gtk.gdk.colormap_get_system() window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.set_title("Tour Creator 1.0") window.connect("destroy", self.stop) window.set_size_request(800, 600) self.video_window = presenter.VideoWindow(self.drone) self.video_window.hide_on_delete() # self.video_window.connect("delete_event", self.toggle_video_window) import tabbed self.tabs = tabbed.Tabs() self.tabs.connect("switch-page", self.set_mode, "set mode") # Layout boxes self.master_vbox = gtk.VBox(False, 2) self.master_vbox.set_border_width(5) self.world_action_hbox = gtk.HBox(False, 2) self.world_action_hbox.set_border_width(5) self.tour_action_hbox = gtk.HBox(True, 2) self.tour_action_hbox.set_border_width(5) self.task_vbox = gtk.VBox(False, 2) self.task_vbox.set_border_width(5) self.task_action_hbox = gtk.HBox(True, 2) self.task_action_hbox.set_border_width(5) self.task_param_hbox = gtk.HBox(False, 2) self.task_param_hbox.set_border_width(5) self.task_vbox.add(self.task_action_hbox) self.task_vbox.add(self.task_param_hbox) # Action buttons - world edit self.world_select_button = gtk.ToggleButton("Select/Move") self.world_select_button.connect("clicked", self.pushed_action, "world select") self.add_button = gtk.ToggleButton("Add Position") self.add_button.connect("clicked", self.pushed_action, "add") self.del_button = gtk.ToggleButton("Remove Position") self.del_button.connect("clicked", self.pushed_action, "del") self.add_wifi_button = gtk.ToggleButton("Add/Update WIFI Sample") self.add_wifi_button.connect("clicked", self.pushed_action, "add wifi") self.clear_wifi_button = gtk.ToggleButton("Clear WIFI Sample") self.clear_wifi_button.connect("clicked", self.pushed_action, "clear wifi") self.world_action_hbox.pack_start(self.world_select_button, False, False, 2) self.world_action_hbox.pack_start(self.add_button, False, False, 2) self.world_action_hbox.pack_start(self.del_button, False, False, 2) self.world_action_hbox.pack_start(self.add_wifi_button, False, False, 2) self.world_action_hbox.pack_start(self.clear_wifi_button, False, False, 2) # Action buttons - tour edit self.tour_select_button = gtk.ToggleButton("Select/Move") self.tour_select_button.connect("clicked", self.pushed_action, "tour select") self.tour_add_a_button = gtk.Button("Add/Remove A") self.tour_add_a_button.connect("clicked", self.pushed_action, "add a") self.tour_add_b_button = gtk.Button("Add/Remove B") self.tour_add_b_button.connect("clicked", self.pushed_action, "add b") self.tour_del_segment_button = gtk.Button("Delete segment") self.tour_del_segment_button.connect("clicked", self.pushed_action, "del segment") self.tour_action_hbox.add(self.tour_select_button) self.tour_action_hbox.add(self.tour_add_a_button) self.tour_action_hbox.add(self.tour_add_b_button) self.tour_action_hbox.add(self.tour_del_segment_button) # Action buttons - task edit self.task_combobox = gtk.combo_box_new_text() for t in tasks.get_all_tasks(): self.task_combobox.append_text(str(t.__name__)) self.task_combobox.set_active(0) self.task_combobox.connect("changed", self.fill_param_box) self.task_add_button = gtk.Button("Add task") self.task_add_button.connect("clicked", self.pushed_action, "add task") self.task_exe_button = gtk.Button("Execute task") self.task_exe_button.connect("clicked", self.pushed_action, "exe task") self.task_del_task_button = gtk.Button("Delete task") self.task_del_task_button.connect("clicked", self.pushed_action, "del task") self.task_kill_all_button = gtk.Button("Delete task") self.task_kill_all_button.connect("clicked", self.pushed_action, "kill task") self.task_action_hbox.add(self.task_combobox) self.task_action_hbox.add(self.task_add_button) self.task_action_hbox.add(self.task_exe_button) self.task_action_hbox.add(self.task_del_task_button) self.task_action_hbox.add(self.task_kill_all_button) self.fill_param_box(None, None) self.area = gtk.DrawingArea() self.area.set_size_request(800, 600) self.pixmap = None self.pangolayout = self.area.create_pango_layout("") self.sw = gtk.ScrolledWindow() self.sw.add_with_viewport(self.area) self.table = gtk.Table(2, 2) self.hruler = gtk.HRuler() self.vruler = gtk.VRuler() self.hruler.set_range(0, 400, 0, 400) self.vruler.set_range(0, 300, 0, 300) self.table.attach(self.hruler, 1, 2, 0, 1, yoptions=0) self.table.attach(self.vruler, 0, 1, 1, 2, xoptions=0) self.table.attach(self.sw, 1, 2, 1, 2) self.area.set_events( gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK ) # self.master_vbox.pack_start(self.mode_hbox, False, False) # self.master_vbox.pack_start(self.world_action_hbox, False, False) # self.master_vbox.pack_start(self.tour_action_hbox, False, False) # self.master_vbox.pack_start(self.task_action_hbox, False, False) # self.master_vbox.pack_start(self.task_param_hbox, False, False) self.master_vbox.pack_start(self.tabs, False, False, 2) self.master_vbox.pack_start(self.table, True, True) self.master_vbox.show_all() # self.tour_action_hbox.hide() # self.task_action_hbox.hide() # self.task_param_hbox.hide() self.tabs.create_tab("Edit Tasks", self.task_vbox) self.tabs.create_tab("Edit Tour", self.tour_action_hbox) self.tabs.create_tab("Edit World", self.world_action_hbox) self.world_select_button.set_active(True) window.add(self.master_vbox) def motion_notify(ruler, event): return ruler.emit("motion_notify_event", event) self.area.connect_object("motion_notify_event", motion_notify, self.hruler) self.area.connect_object("motion_notify_event", motion_notify, self.vruler) self.area.connect("configure_event", self.configure_event) self.area.connect("expose-event", self.area_expose_cb) self.area.connect("button_press_event", self.pushed) self.area.connect("button_release_event", self.released) self.area.connect("motion_notify_event", self.motion) self.hadj = self.sw.get_hadjustment() self.vadj = self.sw.get_vadjustment() def val_cb(adj, ruler, horiz): if horiz: span = self.sw.get_allocation()[3] else: span = self.sw.get_allocation()[2] l, u, p, m = ruler.get_range() v = adj.value ruler.set_range(v, v + span, p, m) while gtk.events_pending(): gtk.main_iteration() self.hadj.connect("value-changed", val_cb, self.hruler, True) self.vadj.connect("value-changed", val_cb, self.vruler, False) def size_allocate_cb(wid, allocation): x, y, w, h = allocation l, u, p, m = self.hruler.get_range() m = max(m, w) self.hruler.set_range(l, l + w, p, m) l, u, p, m = self.vruler.get_range() m = max(m, h) self.vruler.set_range(l, l + h, p, m) self.sw.connect("size-allocate", size_allocate_cb) self.area.show() self.hruler.show() self.vruler.show() self.sw.show() self.table.show() window.show()
def pushed_action(self, widget, data): self.clear() if isinstance(widget, gtk.ToggleButton) and not widget.get_active(): return if data == "add": # print 'add' if self.add_button.get_active(): self.world_select_button.set_active(False) self.del_button.set_active(False) self.add_wifi_button.set_active(False) self.clear_wifi_button.set_active(False) self.world_mode_sub = self.add_mode if data == "add wifi": if self.add_wifi_button.get_active(): self.world_select_button.set_active(False) self.del_button.set_active(False) self.add_button.set_active(False) self.add_wifi_button.set_active(False) self.world_mode_sub = self.add_wifi_mode if data == "clear wifi": if self.clear_wifi_button.get_active(): self.world_select_button.set_active(False) self.del_button.set_active(False) self.add_button.set_active(False) self.world_mode_sub = self.clear_wifi_mode elif data == "del": # print 'del' if self.del_button.get_active(): self.clear_wifi_button.set_active(False) self.add_button.set_active(False) self.world_select_button.set_active(False) self.add_wifi_button.set_active(False) self.world_mode_sub = self.del_mode elif data == "world select": # print 'select' if self.world_select_button.get_active(): self.clear_wifi_button.set_active(False) self.add_button.set_active(False) self.del_button.set_active(False) self.add_wifi_button.set_active(False) self.world_mode_sub = self.select_mode elif data == "tour select": pass # self.world_mode_sub = self.select_mode elif data == "add a": if self.selected_segment is not None: if not "a" in self.selected_segment[2]: self.selected_segment[2].append("a") else: self.selected_segment[2].remove("a") elif data == "add b": if self.selected_segment is not None: if not "b" in self.selected_segment[2]: self.selected_segment[2].append("b") else: self.selected_segment[2].remove("b") elif data == "del segment": if self.selected_segment is not None: self.posmap.remove_tour_segment(self.selected_segment) self.selected_segment = None elif data == "add task": params = [self.drone, None, None] for c in self.task_param_hbox.get_children(): if type(c) is gtk.Entry: text = c.get_text() if text == "None": val = None else: val = self.parseStr(text) params.append(val) print params, "\r" taskname = self.task_combobox.get_active_text() selected_task = None for t in tasks.get_all_tasks(): if t.__name__ == taskname: selected_task = t inst = selected_task(*params) x = 200 + random.randint(-50, 50) y = 100 + random.randint(-50, 50) # tasks.append(t) self.selected_task = self.add_task(inst, x, y) elif data == "exe task": if self.selected_task is not None: exe = self.selected_task task_manager = self.drone.get_task_manager() # .get_controller(settings.AUTOCONTROL) # def cb(caller): # task_manager.task_done(caller) # self.toggle_video_window(None, None) exe[2].callback = task_manager.task_done # if not self.video_window.get_visible(): # self.toggle_video_window(None, None) handle = task_manager.start_task(exe[2]) elif data == "del task": if self.selected_task is not None: for t in self.tasks: if issubclass(t[2].__class__, tasks.CompoundTask): if self.selected_task[2] in t[2].subtasks: t[2].remove_subtask(self.selected_task[2]) self.tasks.remove(self.selected_task) self.area.queue_draw()