Mercurial > MadButterfly
changeset 1331:5da64f67d00d
Rename components and timelines with context menu
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 31 Jan 2011 16:26:21 +0800 |
parents | c2a693a27eb9 |
children | a0d3a4f8e99d |
files | pyink/comp_dock.py pyink/component_dock.glade pyink/domview.py pyink/domview_ui.py |
diffstat | 4 files changed, 171 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/pyink/comp_dock.py Mon Jan 31 14:08:47 2011 +0800 +++ b/pyink/comp_dock.py Mon Jan 31 16:26:21 2011 +0800 @@ -22,7 +22,9 @@ components_model = builder.get_object('components_model') timelines_model = builder.get_object('timelines_model') components_treeview = builder.get_object('treeview_components') + components_menu = builder.get_object('components_menu') timelines_treeview = builder.get_object('treeview_timelines') + timelines_menu = builder.get_object('timelines_menu') dock_top_parent = dock_top.get_parent() dock_top_parent.remove(dock_top) @@ -36,7 +38,9 @@ self._components_model = components_model self._timelines_model = timelines_model self._components_treeview = components_treeview + self._components_menu = components_menu self._timelines_treeview = timelines_treeview + self._timelines_menu = timelines_menu self._cur_component = -1 self._cur_timeline = -1 @@ -250,6 +254,16 @@ self._rm_component() pass + def on_treeview_components_button_press_event(self, widget, event, *args): + if event.type != gtk.gdk.BUTTON_PRESS: + return + + if event.button != 3: # not right button + return + + self._components_menu.popup(None, None, None, event.button, event.time) + pass + def on_treeview_components_row_activated(self, *args): domview_ui = self._domview_ui @@ -261,9 +275,36 @@ desktop.setCurrentLayer(group.spitem) pass + ## \brief Handle of changing component name. + # def on_cellrenderer_comp_edited(self, renderer, path, new_text, *args): - print '%s - %s' % (path, new_text) + model = self._components_model + itr = model.get_iter(path) + + old_name = model.get_value(itr, 0) + + model.set_value(itr, 0, new_text) + model.set_value(itr, 1, False) + + self._domview_ui.rename_component(old_name, new_text) + pass + + def on_rename_component_activate(self, *args): + treeview = self._components_treeview + path, col = treeview.get_cursor() + + model = self._components_model + itr = model.get_iter(path) + model.set_value(itr, 1, True) + + treeview.set_cursor(path, col, True) + pass + + def on_link_component_activate(self, *args): + pass + + def on_switch_component_activate(self, *args): pass def on_add_timeline_clicked(self, *args): @@ -274,6 +315,16 @@ self._rm_timeline() pass + def on_treeview_timelines_button_press_event(self, widget, event, *args): + if event.type != gtk.gdk.BUTTON_PRESS: + return + + if event.button != 3: # not right button + return + + self._timelines_menu.popup(None, None, None, event.button, event.time) + pass + def on_treeview_timelines_row_activated(self, *args): domview_ui = self._domview_ui @@ -283,7 +334,32 @@ def on_cellrenderer_timelines_edited(self, renderer, path, new_text, *args): - print '%s - %s' % (path, new_text) + model = self._timelines_model + itr = model.get_iter(path) + + old_name = model.get_value(itr, 0) + + model.set_value(itr, 0, new_text) + model.set_value(itr, 1, False) + + self._domview_ui.rename_timeline(old_name, new_text) + pass + + def on_rename_timeline_activate(self, *args): + treeview = self._timelines_treeview + path, col = treeview.get_cursor() + + model = self._timelines_model + itr = model.get_iter(path) + model.set_value(itr, 1, True) + + treeview.set_cursor(path, col, True) + pass + + def on_link_timeline_activate(self, *args): + pass + + def on_switch_timeline_activate(self, *args): pass pass
--- a/pyink/component_dock.glade Mon Jan 31 14:08:47 2011 +0800 +++ b/pyink/component_dock.glade Mon Jan 31 16:26:21 2011 +0800 @@ -33,6 +33,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="model">components_model</property> + <signal name="button_press_event" handler="on_treeview_components_button_press_event"/> <signal name="row_activated" handler="on_treeview_components_row_activated"/> <child> <object class="GtkTreeViewColumn" id="treeviewcolumn1"> @@ -127,6 +128,7 @@ <property name="search_column">1</property> <property name="level_indentation">9</property> <property name="enable_grid_lines">horizontal</property> + <signal name="button_press_event" handler="on_treeview_timelines_button_press_event"/> <signal name="row_activated" handler="on_treeview_timelines_row_activated"/> <child> <object class="GtkTreeViewColumn" id="treeviewcolumn2"> @@ -201,4 +203,50 @@ <object class="GtkActionGroup" id="actiongroup1"/> <object class="GtkActionGroup" id="actiongroup2"/> <object class="GtkActionGroup" id="actiongroup3"/> + <object class="GtkMenu" id="components_menu"> + <property name="visible">True</property> + <child> + <object class="GtkMenuItem" id="rename_component"> + <property name="visible">True</property> + <property name="label" translatable="yes">Rename</property> + <property name="use_underline">True</property> + <signal name="activate" handler="on_rename_component_activate"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="link_component"> + <property name="visible">True</property> + <property name="label" translatable="yes">Link</property> + <property name="use_underline">True</property> + <signal name="activate" handler="on_link_component_activate"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="switch_component"> + <property name="visible">True</property> + <property name="label" translatable="yes">Switch to</property> + <property name="use_underline">True</property> + <signal name="activate" handler="on_switch_component_activate"/> + </object> + </child> + </object> + <object class="GtkMenu" id="timelines_menu"> + <property name="visible">True</property> + <child> + <object class="GtkMenuItem" id="rename_timeline"> + <property name="visible">True</property> + <property name="label" translatable="yes">Rename</property> + <property name="use_underline">True</property> + <signal name="activate" handler="on_rename_timeline_activate"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="switch_timeline"> + <property name="visible">True</property> + <property name="label" translatable="yes">Switch to</property> + <property name="use_underline">True</property> + <signal name="activate" handler="on_switch_timeline_activate"/> + </object> + </child> + </object> </interface>
--- a/pyink/domview.py Mon Jan 31 14:08:47 2011 +0800 +++ b/pyink/domview.py Mon Jan 31 16:26:21 2011 +0800 @@ -36,6 +36,11 @@ def name(self): name = self.scenes_node.getAttribute('name') return name + + def rename(self, new_name): + scenes_node = self.scenes_node + scenes_node.setAttribute('name', new_name) + pass pass @@ -153,6 +158,18 @@ return pass raise ValueError, 'try to remove a non-existed timeline - %s' % (name) + + def rename_timeline(self, timeline_name, new_name): + for i, tl in enumerate(self.timelines): + if tl.name() == timeline_name: + tl.rename(new_name) + return + pass + raise ValueError, 'try to remove a non-existed timeline - %s' % (name) + + def rename(self, new_name): + self.node.setAttribute('name', new_name) + pass pass @@ -444,6 +461,11 @@ self._components_node.removeChild(comp_node) self._components_group.removeChild(comp_group) pass + + def rename_component(self, comp_name, new_name): + comp = self._get_component(comp_name) + comp.rename(new_name) + pass def get_component_group(self, comp_name): comp = self._get_component(comp_name) @@ -477,6 +499,16 @@ self._cur_comp.rm_timeline(timeline_name) pass + def rename_timeline_of_component(self, timeline_name, new_name, comp_name): + comp = self._get_component(comp_name) + comp.rename_timeline(timeline_name, new_name) + pass + + def rename_timeline(self, timeline_name, new_name): + comp_name = self._cur_comp.name() + self.rename_timeline_of_component(timeline_name, new_name, comp_name) + pass + def all_timeline_names(self): r = self._cur_comp.all_timeline_names() return r
--- a/pyink/domview_ui.py Mon Jan 31 14:08:47 2011 +0800 +++ b/pyink/domview_ui.py Mon Jan 31 16:26:21 2011 +0800 @@ -469,6 +469,19 @@ def link_to_component(self, comp_name, parent_group): link_node = self._dom.link_to_component(comp_name, parent_group) return link_node + + def rename_component(self, comp_name, new_name): + self._dom.rename_component(comp_name, new_name) + pass + + def rename_timeline_of_component(self, timeline_name, new_name, comp_name): + self._dom.rename_timeline_of_component(timeline_name, new_name, + comp_name) + pass + + def rename_timeline(self, timeline_name, new_name): + self._dom.rename_timeline(timeline_name, new_name) + pass pass