def __mk_right_vbox(self): self.right_vbox = gtk.VBox(homogeneous=False, spacing=0) self.general_settings_vb = gtk.VBox(homogeneous=False, spacing=0) self.update_general_settings() self.right_vbox.pack_start(self.general_settings_vb, expand=False, fill=False, padding=0) self.settings_vb = gtk.VBox(homogeneous=False, spacing=0) self.right_vbox.pack_start(self.settings_vb, expand=False, fill=False, padding=0) self.layer_objects_label = gtk.Label("Layer objects") self.lo_scrolled_window = gtk.ScrolledWindow() self.lo_gtklist = gtk.List() self.lo_gtklist.connect("selection_changed", lambda *args: ep.push_event(EVEnum.general_selection_changed, {"lst": args, "callback": ep.layer_objects_selection_changed, "enumerable": state.get_active_layer().get_proxy_lst()})) self.lo_scrolled_window.add_with_viewport(self.lo_gtklist) self.right_vbox.pack_start(self.layer_objects_label, expand=False, fill=False, padding=0) self.right_vbox.pack_start(self.lo_scrolled_window, expand=True, fill=True, padding=0) self.layer_object_add_button = gtk.Button("Add meta") self.layer_object_add_button.connect("clicked", lambda *args: ep.push_event(EVEnum.layer_object_add_meta_button_click, None)) self.layer_object_add_button.set_sensitive(False) self.right_vbox.pack_start(self.layer_object_add_button, expand=False, fill=False, padding=0) self.layer_set_child_button = gtk.Button("Set child") self.layer_set_child_button.connect("clicked", lambda *args: ep.push_event(EVEnum.layer_set_child_button_click, None)) self.layer_set_child_button.set_sensitive(False) self.right_vbox.pack_start(self.layer_set_child_button, expand=False, fill=False, padding=0) self.layer_delete_object_button = gtk.Button("Delete object") self.layer_delete_object_button.connect("clicked", lambda *args: ep.push_event(EVEnum.layer_delete_object_button_click, None)) self.right_vbox.pack_start(self.layer_delete_object_button, expand=False, fill=False, padding=0)
def __mk_left_vbox(self): self.left_vbox = gtk.VBox(homogeneous=False, spacing=0) self.sprites_label = gtk.Label("Sprites") self.sp_scrolled_window = gtk.ScrolledWindow() self.sp_gtklist = gtk.List() self.sp_gtklist.connect("selection_changed", lambda *args: ep.push_event(EVEnum.sprites_selection_changed, args)) self.sp_scrolled_window.add_with_viewport(self.sp_gtklist) self.left_vbox.pack_start(self.sprites_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.sp_scrolled_window, expand=True, fill=True, padding=0) self.sprite_put_button = gtk.Button("Put sprite") self.sprite_put_button.connect("clicked", lambda *args: ep.push_event(EVEnum.sprite_put_button_click, None)) self.sprite_put_button.set_sensitive(False) self.left_vbox.pack_start(self.sprite_put_button, expand=False, fill=False, padding=0) self.layer_label = gtk.Label("Layers") self.l_scrolled_window = gtk.ScrolledWindow() self.l_gtklist = gtk.List() self.l_gtklist.connect("selection_changed", lambda *args: ep.push_event(EVEnum.general_selection_changed, {"lst":args, "callback": ep.layers_selection_changed, "enumerable": state.get_layers()})) self.l_scrolled_window.add_with_viewport(self.l_gtklist) self.left_vbox.pack_start(self.layer_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.l_scrolled_window, expand=True, fill=True, padding=0) self.layer_add_button = gtk.Button("Add layer") self.layer_add_button.connect("clicked", lambda *args: ep.push_event(EVEnum.layer_add_button_click, None)) self.left_vbox.pack_start(self.layer_add_button, expand=False, fill=False, padding=0) self.layer_remove_button = gtk.Button("Delete layer") self.layer_remove_button.connect("clicked", lambda *args: ep.push_event(EVEnum.layer_delete_button_click, None)) self.left_vbox.pack_start(self.layer_remove_button, expand=False, fill=False, padding=0)
def key_press_event(self, widget, event): print "key press:", event.keyval if event.keyval == 65307: # ESC ep.push_event(EVEnum.deselect_all, (None)) elif event.keyval == 65505: # shift ep.push_event(EVEnum.shift_press, (None)) elif event.keyval == 65507: # ctrl ep.push_event(EVEnum.ctrl_press, (None)) elif event.keyval == 65535: # delete ep.push_event(EVEnum.delete_press, (None)) elif event.keyval == 115: # s key (start selection) ep.push_event(EVEnum.set_selection_mode, (None))
def __mk_labeled_checkbox(self, dct, mlabel, data=None, callback=None, default=False): hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.show() dct["hbox"] = hbox check = gtk.CheckButton(mlabel) check.connect("clicked", lambda *args: ep.push_event(EVEnum.update_settings, (data, args))) check.show() dct["check"] = check hbox.pack_start(check, expand=True, fill=True, padding=0) return hbox
def __mk_right_vbox(self): self.right_vbox = gtk.VBox(homogeneous=False, spacing=0) self.sprite_label = gtk.Label("Sprite images") self.sprite_window = gtk.ScrolledWindow() self.sprite_gtklist = gtk.List() self.sprite_gtklist.connect("selection_changed", lambda *args: ep.push_event(EVEnum.sprite_elements_list_selection_changed, args)) self.sprite_window.add_with_viewport(self.sprite_gtklist) self.sprite_updown_hbox = gtk.HBox(homogeneous=False, spacing=0) self.sprite_up_button = gtk.Button(u"▲") self.sprite_down_button = gtk.Button(u"▼") self.sprite_up_button.connect("clicked", lambda *args: ep.push_event(EVEnum.sprite_image_up_click, args)) self.sprite_down_button.connect("clicked", lambda *args: ep.push_event(EVEnum.sprite_image_down_click, args)) self.sprite_updown_hbox.pack_start(self.sprite_up_button, expand=True, fill=True, padding=0) self.sprite_updown_hbox.pack_start(self.sprite_down_button, expand=True, fill=True, padding=0) self.right_vbox.pack_start(self.sprite_label, expand=False, fill=False, padding=0) self.right_vbox.pack_start(self.sprite_window, expand=True, fill=True, padding=0) self.right_vbox.pack_start(self.sprite_updown_hbox, expand=False, fill=False, padding=0) self.sprite_image_remove_button = gtk.Button("Remove image from sprite") self.sprite_image_remove_button.connect("clicked", lambda *args: ep.push_event(EVEnum.sprite_image_remove_button_click, None)) self.right_vbox.pack_start(self.sprite_image_remove_button, expand=False, fill=False, padding=0) self.tool_label = gtk.Label("General settings") self.right_vbox.pack_start(self.tool_label, expand=False, fill=False, padding=0) settings_lst = state.get_settings_list() if settings_lst != None: print settings_lst for s in settings_lst: dct = {} if s.type == "int": w = self.__mk_labeled_spin(dct, s.display_name, s, None, s.default, s.min, s.max) self.right_vbox.pack_start(w, expand=False, fill=False, padding=0) self.settings_vb = gtk.VBox(homogeneous=False, spacing=0) self.right_vbox.pack_start(self.settings_vb, expand=False, fill=False, padding=0)
def __mk_labeled_checkbox(self, dct, mlabel, data=None, callback=None, default=False): hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.show() dct["hbox"] = hbox check = gtk.CheckButton(mlabel) check.connect( "clicked", lambda *args: ep.push_event(EVEnum.update_settings, (data, args))) check.show() dct["check"] = check hbox.pack_start(check, expand=True, fill=True, padding=0) return hbox
def add_item_to_list(self, lst, label_text, event): check_button = gtk.CheckButton("") check_button.set_active(True) check_button.unset_flags(gtk.CAN_FOCUS) check_button.show() if event != None: check_button.connect("clicked", lambda *args: ep.push_event(event, (label_text, args))) label = gtk.Label(label_text) label.show() hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.pack_start(check_button, expand=False, fill=False, padding=0) hbox.pack_start(label, expand=False, fill=False, padding=0) hbox.show() list_item = gtk.ListItem() list_item.show() list_item.add(hbox) lst.add(list_item)
def __mk_labeled_spin(self, dct, mlabel, data=None, callback=None, value=8, lower=-999.0, upper=999.0, step_incr=1.0, page_incr=5.0): if lower == None: lower = -999.0 if upper == None: upper = 999.0 if step_incr == None: step_incr = 1.0 if page_incr == None: page_incr = 0.5 hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.show() dct["hbox"] = hbox label = gtk.Label(mlabel) label.show() dct["label"] = label spin = gtk.SpinButton(adjustment=gtk.Adjustment(value=value, lower=lower, upper=upper, step_incr=step_incr, page_incr=page_incr, page_size=0), climb_rate=0.01, digits=3) spin.connect( "value-changed", lambda *args: ep.push_event(EVEnum.update_settings, (data, args))) spin.show() dct["spin"] = spin hbox.pack_start(label, expand=False, fill=False, padding=0) hbox.pack_start(spin, expand=True, fill=True, padding=0) return hbox
def __mk_labeled_spin(self, dct, mlabel, data=None, callback=None, value=8, lower=-999.0, upper=999.0, step_incr=1.0, page_incr=5.0): if lower == None: lower = -999.0 if upper == None: upper = 999.0 if step_incr == None: step_incr = 1.0 if page_incr == None: page_incr = 0.5 hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.show() dct["hbox"] = hbox label = gtk.Label(mlabel) label.show() dct["label"] = label spin = gtk.SpinButton(adjustment=gtk.Adjustment(value=value, lower=lower, upper=upper, step_incr=step_incr, page_incr=page_incr, page_size=0), climb_rate=0.01, digits=0) spin.connect("value-changed", lambda *args: ep.push_event(EVEnum.update_settings, (data, args))) spin.show() dct["spin"] = spin hbox.pack_start(label, expand=False, fill=False, padding=0) hbox.pack_start(spin, expand=True, fill=True, padding=0) return hbox
def add_item_to_list(self, lst, label_text, event): check_button = gtk.CheckButton("") check_button.set_active(True) check_button.unset_flags(gtk.CAN_FOCUS) check_button.show() if event != None: check_button.connect( "clicked", lambda *args: ep.push_event(event, (label_text, args))) label = gtk.Label(label_text) label.show() hbox = gtk.HBox(homogeneous=False, spacing=0) hbox.pack_start(check_button, expand=False, fill=False, padding=0) hbox.pack_start(label, expand=False, fill=False, padding=0) hbox.show() list_item = gtk.ListItem() list_item.show() list_item.add(hbox) lst.add(list_item)
def __mk_left_vbox(self): self.left_vbox = gtk.VBox(homogeneous=False, spacing=0) self.new_sprite_button = gtk.Button("New sprite from selection") self.new_sprite_button.connect("clicked", lambda *args: ep.push_event(EVEnum.new_sprite_click, args)) self.left_vbox.pack_start(self.new_sprite_button, expand=False, fill=False, padding=0) self.add_to_selected_sprite_button = gtk.Button("Add to selected sprite") self.add_to_selected_sprite_button.connect("clicked", lambda *args: ep.push_event(EVEnum.add_to_selected_sprite_click, args)) self.left_vbox.pack_start(self.add_to_selected_sprite_button, expand=False, fill=False, padding=0) self.load_image_button = gtk.Button("Load image") self.load_image_button.connect("clicked", lambda *args: ep.push_event(EVEnum.load_image_click, args)) self.left_vbox.pack_start(self.load_image_button, expand=False, fill=False, padding=0) self.images_label = gtk.Label("Source images") self.scrolled_window = gtk.ScrolledWindow() self.gtklist = gtk.List() self.gtklist.connect("selection_changed", lambda *args: ep.push_event(EVEnum.image_list_selection_changed, args)) self.scrolled_window.add_with_viewport(self.gtklist) self.left_vbox.pack_start(self.images_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.scrolled_window, expand=True, fill=True, padding=0) self.image_delete_button = gtk.Button("Delete image") self.image_delete_button.connect("clicked", lambda *args: ep.push_event(EVEnum.delete_image_button_click, None)) self.left_vbox.pack_start(self.image_delete_button, expand=False, fill=False, padding=0) self.sprites_label = gtk.Label("Sprites") self.sp_scrolled_window = gtk.ScrolledWindow() self.sp_gtklist = gtk.List() self.sp_gtklist.connect("selection_changed", lambda *args: ep.push_event(EVEnum.sprites_selection_changed, args)) self.sp_scrolled_window.add_with_viewport(self.sp_gtklist) self.left_vbox.pack_start(self.sprites_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.sp_scrolled_window, expand=True, fill=True, padding=0) self.sprite_delete_button = gtk.Button("Delete sprite") self.sprite_delete_button.connect("clicked", lambda *args: ep.push_event(EVEnum.sprite_delete_button_click, None)) self.left_vbox.pack_start(self.sprite_delete_button, expand=False, fill=False, padding=0)
def button_release_event(self, widget, event): if event.button == 1: ep.push_event(EVEnum.screen_left_release, (event.x, event.y))
def key_release_event(self, widget, event): if event.keyval == 65505: # shift ep.push_event(EVEnum.shift_release, (None))
def key_press_event(self, widget, event): print "key press:", event.keyval if event.keyval == 65307: # ESC ep.push_event(EVEnum.deselect_all, (None)) elif event.keyval == 65505: # shift ep.push_event(EVEnum.shift_press, (None))
def button_press_event(self, widget, event): print "button press:", event.button if event.button == 1: ep.push_event(EVEnum.screen_left_press, (event.x, event.y))
def scroll_event(self, widget, event): print "event:", event if event.direction == gtk.gdk.SCROLL_UP: ep.push_event(EVEnum.scroll_up, (None)) elif event.direction == gtk.gdk.SCROLL_DOWN: ep.push_event(EVEnum.scroll_down, (None))
def __mk_left_vbox(self): self.left_vbox = gtk.VBox(homogeneous=False, spacing=0) self.sprites_label = gtk.Label("Sprites") self.sp_scrolled_window = gtk.ScrolledWindow() self.sp_gtklist = gtk.List() self.sp_gtklist.connect( "selection_changed", lambda *args: ep.push_event( EVEnum.sprites_selection_changed, args)) self.sp_scrolled_window.add_with_viewport(self.sp_gtklist) self.left_vbox.pack_start(self.sprites_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.sp_scrolled_window, expand=True, fill=True, padding=0) self.sprite_put_button = gtk.Button("Put sprite") self.sprite_put_button.connect( "clicked", lambda *args: ep.push_event(EVEnum.sprite_put_button_click, None)) self.sprite_put_button.set_sensitive(False) self.left_vbox.pack_start(self.sprite_put_button, expand=False, fill=False, padding=0) self.layer_label = gtk.Label("Layers") self.l_scrolled_window = gtk.ScrolledWindow() self.l_gtklist = gtk.List() self.l_gtklist.connect( "selection_changed", lambda *args: ep.push_event( EVEnum.general_selection_changed, { "lst": args, "callback": ep.layers_selection_changed, "enumerable": state.get_layers() })) self.l_scrolled_window.add_with_viewport(self.l_gtklist) self.left_vbox.pack_start(self.layer_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.l_scrolled_window, expand=True, fill=True, padding=0) self.layer_add_button = gtk.Button("Add layer") self.layer_add_button.connect( "clicked", lambda *args: ep.push_event(EVEnum.layer_add_button_click, None)) self.left_vbox.pack_start(self.layer_add_button, expand=False, fill=False, padding=0) self.layer_remove_button = gtk.Button("Delete layer") self.layer_remove_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.layer_delete_button_click, None)) self.left_vbox.pack_start(self.layer_remove_button, expand=False, fill=False, padding=0)
def key_release_event(self, widget, event): if event.keyval == 65505: # shift ep.push_event(EVEnum.shift_release, (None)) elif event.keyval == 65507: # ctrl ep.push_event(EVEnum.ctrl_release, (None))
def __mk_right_vbox(self): self.right_vbox = gtk.VBox(homogeneous=False, spacing=0) self.sprite_label = gtk.Label("Sprite images") self.sprite_window = gtk.ScrolledWindow() self.sprite_gtklist = gtk.List() self.sprite_gtklist.connect( "selection_changed", lambda *args: ep.push_event( EVEnum.sprite_elements_list_selection_changed, args)) self.sprite_window.add_with_viewport(self.sprite_gtklist) self.sprite_updown_hbox = gtk.HBox(homogeneous=False, spacing=0) self.sprite_up_button = gtk.Button(u"▲") self.sprite_down_button = gtk.Button(u"▼") self.sprite_up_button.connect( "clicked", lambda *args: ep.push_event(EVEnum.sprite_image_up_click, args)) self.sprite_down_button.connect( "clicked", lambda *args: ep.push_event(EVEnum.sprite_image_down_click, args)) self.sprite_updown_hbox.pack_start(self.sprite_up_button, expand=True, fill=True, padding=0) self.sprite_updown_hbox.pack_start(self.sprite_down_button, expand=True, fill=True, padding=0) self.right_vbox.pack_start(self.sprite_label, expand=False, fill=False, padding=0) self.right_vbox.pack_start(self.sprite_window, expand=True, fill=True, padding=0) self.right_vbox.pack_start(self.sprite_updown_hbox, expand=False, fill=False, padding=0) self.sprite_image_remove_button = gtk.Button( "Remove image from sprite") self.sprite_image_remove_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.sprite_image_remove_button_click, None)) self.right_vbox.pack_start(self.sprite_image_remove_button, expand=False, fill=False, padding=0) self.tool_label = gtk.Label("General settings") self.right_vbox.pack_start(self.tool_label, expand=False, fill=False, padding=0) settings_lst = state.get_settings_list() if settings_lst != None: print settings_lst for s in settings_lst: dct = {} if s.type == "int": w = self.__mk_labeled_spin(dct, s.display_name, s, None, s.default, s.min, s.max) self.right_vbox.pack_start(w, expand=False, fill=False, padding=0) self.settings_vb = gtk.VBox(homogeneous=False, spacing=0) self.right_vbox.pack_start(self.settings_vb, expand=False, fill=False, padding=0)
def scroll_event(self, widget, event): print "event:", event if event.direction == gtk.gdk.SCROLL_UP: ep.push_event(EVEnum.scroll_up, (None)) elif event.direction == gtk.gdk.SCROLL_DOWN: ep.push_event(EVEnum.scroll_down, (None))
def __init__(self, w, h, Widget): self.window = gtk.Window() self.window.resize(w, h) self.window.connect("delete-event", gtk.main_quit) self.menu_bar = gtk.MenuBar() self.file_menu = gtk.Menu() self.file_item = gtk.MenuItem("File") self.file_item.set_submenu(self.file_menu) self.menu_bar.append(self.file_item) self.open_project_item = gtk.MenuItem("Open project ...") self.save_project_item = gtk.MenuItem("Save project ...") sep_export_import = gtk.SeparatorMenuItem() self.import_item = gtk.MenuItem("Import tileset ...") self.export_item = gtk.MenuItem("Export ...") self.quit_item = gtk.MenuItem("Quit") sep_quit = gtk.SeparatorMenuItem() self.file_menu.append(self.open_project_item) self.file_menu.append(self.save_project_item) self.file_menu.append(sep_export_import) self.file_menu.append(self.import_item) self.file_menu.append(self.export_item) self.file_menu.append(sep_quit) self.file_menu.append(self.quit_item) self.import_item.connect("activate", lambda *args: ep.push_event(EVEnum.import_click, args)) self.export_item.connect("activate", lambda *args: ep.push_event(EVEnum.export_click, args)) self.open_project_item.connect("activate", lambda *args: ep.push_event(EVEnum.load_project_click, args)) self.save_project_item.connect("activate", lambda *args: ep.push_event(EVEnum.save_project_click, args)) self.quit_item.connect("activate", lambda *args: ep.push_event(EVEnum.quit_click, args)) self.window_vbox = gtk.VBox(homogeneous=False, spacing=0) self.window_vbox.pack_start(self.menu_bar, expand=False, fill=False, padding=0) self.window.add(self.window_vbox) self.widget = Widget() self.widget.connect("button_press_event", self.widget.button_press_event) self.widget.connect("button_release_event", self.widget.button_release_event) self.widget.connect("motion_notify_event", self.widget.motion_notify_event) self.widget.connect("scroll_event", self.widget.scroll_event) self.window.connect("key_press_event", self.widget.key_press_event) self.window.connect("key_release_event", self.widget.key_release_event) self.window.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK) self.widget.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK) self.__mk_left_vbox() self.hbox = gtk.HBox(homogeneous=False, spacing=0) self.hbox.pack_start(self.left_vbox, expand=False, fill=False, padding=0) self.widget_hbox = gtk.HBox(homogeneous=False, spacing=0) self.widget_vbox = gtk.VBox(homogeneous=False, spacing=0) self.widget_hscroll = gtk.HScrollbar(gtk.Adjustment(0.0, 0.0, 0.0, 10.0, 100.0, 1.0)) self.widget_hscroll.connect("value-changed", lambda *args: ep.push_event(EVEnum.hscroll, (args))) self.widget_vscroll = gtk.VScrollbar(gtk.Adjustment(0.0, 0.0, 0.0, 10.0, 100.0, 1.0)) self.widget_vscroll.connect("value-changed", lambda *args: ep.push_event(EVEnum.vscroll, (args))) self.widget_hbox.pack_start(self.widget, expand=True, fill=True, padding=0) self.widget_hbox.pack_start(self.widget_vscroll, expand=False, fill=False, padding=0) self.widget_vbox.pack_start(self.widget_hbox, expand=True, fill=True) self.widget_vbox.pack_start(self.widget_hscroll, expand=False, fill=False, padding=0) self.hbox.pack_start(self.widget_vbox, expand=True, fill=True, padding=0) self.status_hbox = gtk.HBox(homogeneous=False, spacing = 5) self.cursor_pos_label = gtk.Label("") self.scale_label = gtk.Label("") self.mode_label = gtk.Label("") self.status_hbox.pack_start(self.cursor_pos_label, expand=False, fill=False) self.status_hbox.pack_start(self.scale_label, expand=False, fill=False) self.status_hbox.pack_start(self.mode_label, expand=False, fill=False) self.widget_vbox.pack_start(self.status_hbox, expand=False, fill=False) self.__mk_right_vbox() self.hbox.pack_start(self.right_vbox, expand=False, fill=False, padding=0) gobject.timeout_add(30, self.widget.periodic) self.window_vbox.pack_start(self.hbox, expand=True, fill=True, padding=0)
def __mk_right_vbox(self): self.right_vbox = gtk.VBox(homogeneous=False, spacing=0) self.general_settings_vb = gtk.VBox(homogeneous=False, spacing=0) self.update_general_settings() self.right_vbox.pack_start(self.general_settings_vb, expand=False, fill=False, padding=0) self.settings_vb = gtk.VBox(homogeneous=False, spacing=0) self.right_vbox.pack_start(self.settings_vb, expand=False, fill=False, padding=0) self.layer_objects_label = gtk.Label("Layer objects") self.lo_scrolled_window = gtk.ScrolledWindow() self.lo_gtklist = gtk.List() self.lo_gtklist.connect( "selection_changed", lambda *args: ep.push_event( EVEnum.general_selection_changed, { "lst": args, "callback": ep.layer_objects_selection_changed, "enumerable": state.get_active_layer().get_proxy_lst() })) self.lo_scrolled_window.add_with_viewport(self.lo_gtklist) self.right_vbox.pack_start(self.layer_objects_label, expand=False, fill=False, padding=0) self.right_vbox.pack_start(self.lo_scrolled_window, expand=True, fill=True, padding=0) self.layer_object_add_button = gtk.Button("Add meta") self.layer_object_add_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.layer_object_add_meta_button_click, None)) self.layer_object_add_button.set_sensitive(False) self.right_vbox.pack_start(self.layer_object_add_button, expand=False, fill=False, padding=0) self.layer_set_child_button = gtk.Button("Set child") self.layer_set_child_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.layer_set_child_button_click, None)) self.layer_set_child_button.set_sensitive(False) self.right_vbox.pack_start(self.layer_set_child_button, expand=False, fill=False, padding=0) self.layer_delete_object_button = gtk.Button("Delete object") self.layer_delete_object_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.layer_delete_object_button_click, None)) self.right_vbox.pack_start(self.layer_delete_object_button, expand=False, fill=False, padding=0)
def motion_notify_event(self, widget, event): ep.push_event(EVEnum.pointer_motion, (event.x, event.y))
def __init__(self, w, h, Widget): self.window = gtk.Window() self.window.resize(w, h) self.window.connect("delete-event", gtk.main_quit) self.menu_bar = gtk.MenuBar() self.file_menu = gtk.Menu() self.file_item = gtk.MenuItem("File") self.file_item.set_submenu(self.file_menu) self.menu_bar.append(self.file_item) self.open_project_item = gtk.MenuItem("Open project ...") self.save_project_item = gtk.MenuItem("Save project ...") sep_export_import = gtk.SeparatorMenuItem() self.export_item = gtk.MenuItem("Export ...") self.quit_item = gtk.MenuItem("Quit") sep_quit = gtk.SeparatorMenuItem() self.file_menu.append(self.open_project_item) self.file_menu.append(self.save_project_item) self.file_menu.append(sep_export_import) self.file_menu.append(self.export_item) self.file_menu.append(sep_quit) self.file_menu.append(self.quit_item) self.export_item.connect( "activate", lambda *args: ep.push_event(EVEnum.export_click, args)) self.open_project_item.connect( "activate", lambda *args: ep.push_event(EVEnum.load_project_click, args)) self.save_project_item.connect( "activate", lambda *args: ep.push_event(EVEnum.save_project_click, args)) self.quit_item.connect( "activate", lambda *args: ep.push_event(EVEnum.quit_click, args)) self.window_vbox = gtk.VBox(homogeneous=False, spacing=0) self.window_vbox.pack_start(self.menu_bar, expand=False, fill=False, padding=0) self.window.add(self.window_vbox) self.widget = Widget() self.widget.connect("button_press_event", self.widget.button_press_event) self.widget.connect("button_release_event", self.widget.button_release_event) self.widget.connect("motion_notify_event", self.widget.motion_notify_event) self.widget.connect("scroll_event", self.widget.scroll_event) self.window.connect("key_press_event", self.widget.key_press_event) self.window.connect("key_release_event", self.widget.key_release_event) self.window.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK) self.widget.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK) self.__mk_left_vbox() self.hbox = gtk.HBox(homogeneous=False, spacing=0) self.hbox.pack_start(self.left_vbox, expand=False, fill=False, padding=0) self.widget_hbox = gtk.HBox(homogeneous=False, spacing=0) self.widget_vbox = gtk.VBox(homogeneous=False, spacing=0) self.widget_hscroll = gtk.HScrollbar( gtk.Adjustment(0.0, -1000.0, 1000.0, 0.1, 1.0, 1.0)) self.widget_hscroll.connect( "value-changed", lambda *args: ep.push_event(EVEnum.hscroll, (args))) self.widget_vscroll = gtk.VScrollbar( gtk.Adjustment(0.0, -1000.0, 1000.0, 0.1, 1.0, 1.0)) self.widget_vscroll.connect( "value-changed", lambda *args: ep.push_event(EVEnum.vscroll, (args))) self.widget_hbox.pack_start(self.widget, expand=True, fill=True, padding=0) self.widget_hbox.pack_start(self.widget_vscroll, expand=False, fill=False, padding=0) self.widget_vbox.pack_start(self.widget_hbox, expand=True, fill=True) self.widget_vbox.pack_start(self.widget_hscroll, expand=False, fill=False, padding=0) self.hbox.pack_start(self.widget_vbox, expand=True, fill=True, padding=0) self.cursor_pos_label = gtk.Label("") self.widget_vbox.pack_start(self.cursor_pos_label, expand=False, fill=False) self.__mk_right_vbox() self.hbox.pack_start(self.right_vbox, expand=False, fill=False, padding=0) gobject.timeout_add(30, self.widget.periodic) self.window_vbox.pack_start(self.hbox, expand=True, fill=True, padding=0)
def button_release_event(self, widget, event): if event.button == 1: ep.push_event(EVEnum.screen_left_release, (event.x, event.y))
def button_press_event(self, widget, event): print "button press:", event.button if event.button == 1: ep.push_event(EVEnum.screen_left_press, (event.x, event.y))
def motion_notify_event(self, widget, event): ep.push_event(EVEnum.pointer_motion, (event.x, event.y))
def __mk_left_vbox(self): self.left_vbox = gtk.VBox(homogeneous=False, spacing=0) self.new_sprite_button = gtk.Button("New sprite from selection") self.new_sprite_button.connect( "clicked", lambda *args: ep.push_event(EVEnum.new_sprite_click, args)) self.left_vbox.pack_start(self.new_sprite_button, expand=False, fill=False, padding=0) self.add_to_selected_sprite_button = gtk.Button( "Add to selected sprite") self.add_to_selected_sprite_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.add_to_selected_sprite_click, args)) self.left_vbox.pack_start(self.add_to_selected_sprite_button, expand=False, fill=False, padding=0) self.load_image_button = gtk.Button("Load image") self.load_image_button.connect( "clicked", lambda *args: ep.push_event(EVEnum.load_image_click, args)) self.left_vbox.pack_start(self.load_image_button, expand=False, fill=False, padding=0) self.images_label = gtk.Label("Source images") self.scrolled_window = gtk.ScrolledWindow() self.gtklist = gtk.List() self.gtklist.connect( "selection_changed", lambda *args: ep.push_event( EVEnum.image_list_selection_changed, args)) self.scrolled_window.add_with_viewport(self.gtklist) self.left_vbox.pack_start(self.images_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.scrolled_window, expand=True, fill=True, padding=0) self.image_delete_button = gtk.Button("Delete image") self.image_delete_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.delete_image_button_click, None)) self.left_vbox.pack_start(self.image_delete_button, expand=False, fill=False, padding=0) self.sprites_label = gtk.Label("Sprites") self.sp_scrolled_window = gtk.ScrolledWindow() self.sp_gtklist = gtk.List() self.sp_gtklist.connect( "selection_changed", lambda *args: ep.push_event( EVEnum.sprites_selection_changed, args)) self.sp_scrolled_window.add_with_viewport(self.sp_gtklist) self.left_vbox.pack_start(self.sprites_label, expand=False, fill=False, padding=0) self.left_vbox.pack_start(self.sp_scrolled_window, expand=True, fill=True, padding=0) self.sprite_delete_button = gtk.Button("Delete sprite") self.sprite_delete_button.connect( "clicked", lambda *args: ep.push_event( EVEnum.sprite_delete_button_click, None)) self.left_vbox.pack_start(self.sprite_delete_button, expand=False, fill=False, padding=0)
def key_press_event(self, widget, event): print "key press:", event.keyval if event.keyval == 65307: # ESC ep.push_event(EVEnum.deselect_all, (None)) elif event.keyval == 65505: # shift ep.push_event(EVEnum.shift_press, (None))