Mercurial > MadButterfly
changeset 1528:b7d70341ee57
Insert layer with unique name
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 31 Aug 2011 22:23:04 +0800 |
parents | d42951ebfc6f |
children | af8dd27bf450 |
files | pyink/MBScene.py pyink/domview.py pyink/domview_ui.py |
diffstat | 3 files changed, 64 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/pyink/MBScene.py Wed Aug 31 17:16:44 2011 +0800 +++ b/pyink/MBScene.py Wed Aug 31 22:23:04 2011 +0800 @@ -261,6 +261,15 @@ self._domviewui.remember_current_frame(layer_idx, frame_idx) pass + def doAddLayer(self, w): + domview = self._domviewui + layer_num = domview.get_layer_num() + domview.insert_layer(layer_num) + pass + + def doRemoveLayer(self, w): + pass + def doInsertKeyScene(self,w): layer_idx, frame_idx = self._domviewui.get_active_layer_frame() self.insertKeyScene(layer_idx, frame_idx) @@ -361,6 +370,14 @@ pass def _add_buttons(self, hbox): + btn = gtk.Button('Add a Layer') + btn.connect('clicked', self.doAddLayer) + hbox.pack_start(btn, expand=False, fill=False) + + btn = gtk.Button('Remove the Layer') + btn.connect('clicked', self.doRemoveLayer) + hbox.pack_start(btn, expand=False, fill=False) + btn = gtk.Button('Insert Key') btn.connect('clicked', self.doInsertKeyScene) hbox.pack_start(btn, expand=False, fill=False)
--- a/pyink/domview.py Wed Aug 31 17:16:44 2011 +0800 +++ b/pyink/domview.py Wed Aug 31 22:23:04 2011 +0800 @@ -26,6 +26,14 @@ self.scenes = [] self.group = node pass + + def get_name(self): + layer_name = self.group.getAttribute('inkscape:label') + return layer_name + + def set_name(self, layer_name): + self.group.setAttribute('inkscape:label', layer_name) + pass pass @@ -1577,6 +1585,9 @@ get_scene = require get_node = require new_id = require + get_current_component = require + _get_layers_group_of_component = require + _create_comp_layer_group = require def parse_all_layers(self): layers = self._layers @@ -1623,13 +1634,40 @@ def get_layer_num(self): return len(self._layers) + def _make_unique_layer_name(self, idx): + names = [layer.get_name() for layer in self._layers] + + idx = idx + 1 + name = 'Layer%d' % (idx) + while name in names: + idx = idx + 1 + name = 'Layer%d' % (idx) + pass + return name + + def get_layer_name(self, layer_idx): + layers = self._layers + layer = layers[layer_idx] + return layer.get_name() + + def set_layer_name(self, layer_idx, name): + layers = self._layers + layer = layers[layer_idx] + layer.set_name(name) + pass + ## \brief Add/insert a layer at given position. # # \param layer_idx is the position in the layer list. # - def insert_layer(self, layer_idx, layer_group): + def insert_layer(self, layer_idx): layers = self._layers + comp_name = self.get_current_component() + layers_group = self._get_layers_group_of_component(comp_name) + layer_name = self._make_unique_layer_name(layer_idx) + layer_group = self._create_comp_layer_group(layers_group, layer_name) + layer = Layer(layer_group) if layer_idx >= len(layers): layers.append(layer) @@ -1790,7 +1828,11 @@ method_map_traits = {component_manager._start_component_manager: '_start_component_manager', component_manager._get_component: - '_get_component'} + '_get_component', + component_manager._get_layers_group_of_component: + '_get_layers_group_of_component', + component_manager._create_comp_layer_group: + '_create_comp_layer_group'} # Declare variables, here, for keeping tracking _doc = None
--- a/pyink/domview_ui.py Wed Aug 31 17:16:44 2011 +0800 +++ b/pyink/domview_ui.py Wed Aug 31 22:23:04 2011 +0800 @@ -809,7 +809,10 @@ # def insert_layer(self, layer_idx): self._dom.insert_layer(layer_idx) + layer_name = self._dom.get_layer_name(layer_idx) + self._fl_stack.add_frameline(layer_idx) + self._fl_stack.set_layer_label(layer_idx, layer_name) self._fl_stack.show_framelines() pass