comparison pyink/domview.py @ 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 9e7e5f79acc6
comparison
equal deleted inserted replaced
1527:d42951ebfc6f 1528:b7d70341ee57
24 class Layer: 24 class Layer:
25 def __init__(self, node): 25 def __init__(self, node):
26 self.scenes = [] 26 self.scenes = []
27 self.group = node 27 self.group = node
28 pass 28 pass
29
30 def get_name(self):
31 layer_name = self.group.getAttribute('inkscape:label')
32 return layer_name
33
34 def set_name(self, layer_name):
35 self.group.setAttribute('inkscape:label', layer_name)
36 pass
29 pass 37 pass
30 38
31 39
32 class Timeline(object): 40 class Timeline(object):
33 def __init__(self, scenes_node): 41 def __init__(self, scenes_node):
1575 _layers = require 1583 _layers = require
1576 _layers_parent = require 1584 _layers_parent = require
1577 get_scene = require 1585 get_scene = require
1578 get_node = require 1586 get_node = require
1579 new_id = require 1587 new_id = require
1588 get_current_component = require
1589 _get_layers_group_of_component = require
1590 _create_comp_layer_group = require
1580 1591
1581 def parse_all_layers(self): 1592 def parse_all_layers(self):
1582 layers = self._layers 1593 layers = self._layers
1583 layers_parent = self._layers_parent 1594 layers_parent = self._layers_parent
1584 1595
1621 pass 1632 pass
1622 1633
1623 def get_layer_num(self): 1634 def get_layer_num(self):
1624 return len(self._layers) 1635 return len(self._layers)
1625 1636
1637 def _make_unique_layer_name(self, idx):
1638 names = [layer.get_name() for layer in self._layers]
1639
1640 idx = idx + 1
1641 name = 'Layer%d' % (idx)
1642 while name in names:
1643 idx = idx + 1
1644 name = 'Layer%d' % (idx)
1645 pass
1646 return name
1647
1648 def get_layer_name(self, layer_idx):
1649 layers = self._layers
1650 layer = layers[layer_idx]
1651 return layer.get_name()
1652
1653 def set_layer_name(self, layer_idx, name):
1654 layers = self._layers
1655 layer = layers[layer_idx]
1656 layer.set_name(name)
1657 pass
1658
1626 ## \brief Add/insert a layer at given position. 1659 ## \brief Add/insert a layer at given position.
1627 # 1660 #
1628 # \param layer_idx is the position in the layer list. 1661 # \param layer_idx is the position in the layer list.
1629 # 1662 #
1630 def insert_layer(self, layer_idx, layer_group): 1663 def insert_layer(self, layer_idx):
1631 layers = self._layers 1664 layers = self._layers
1632 1665
1666 comp_name = self.get_current_component()
1667 layers_group = self._get_layers_group_of_component(comp_name)
1668 layer_name = self._make_unique_layer_name(layer_idx)
1669 layer_group = self._create_comp_layer_group(layers_group, layer_name)
1670
1633 layer = Layer(layer_group) 1671 layer = Layer(layer_group)
1634 if layer_idx >= len(layers): 1672 if layer_idx >= len(layers):
1635 layers.append(layer) 1673 layers.append(layer)
1636 else: 1674 else:
1637 layers.insert(layer_idx, layer) 1675 layers.insert(layer_idx, layer)
1788 use_traits = (component_manager, layers_parser, FSM_manager) 1826 use_traits = (component_manager, layers_parser, FSM_manager)
1789 1827
1790 method_map_traits = {component_manager._start_component_manager: 1828 method_map_traits = {component_manager._start_component_manager:
1791 '_start_component_manager', 1829 '_start_component_manager',
1792 component_manager._get_component: 1830 component_manager._get_component:
1793 '_get_component'} 1831 '_get_component',
1832 component_manager._get_layers_group_of_component:
1833 '_get_layers_group_of_component',
1834 component_manager._create_comp_layer_group:
1835 '_create_comp_layer_group'}
1794 1836
1795 # Declare variables, here, for keeping tracking 1837 # Declare variables, here, for keeping tracking
1796 _doc = None 1838 _doc = None
1797 _root = None 1839 _root = None
1798 # Required by component_manager and FSM_manager 1840 # Required by component_manager and FSM_manager