# HG changeset patch # User Thinker K.F. Li # Date 1294738746 -28800 # Node ID df474448364e08b3ae67cbf0c1eeb78b444a009d # Parent 2609b219703d5d8563c1e42663d1b916cdf6afe1 Add find_layer_from_group() for domview_ui diff -r 2609b219703d -r df474448364e pyink/domview.py --- a/pyink/domview.py Tue Jan 11 17:24:56 2011 +0800 +++ b/pyink/domview.py Tue Jan 11 17:39:06 2011 +0800 @@ -524,6 +524,10 @@ def get_layer_num(self): return len(self._layers) + ## \brief Find layer index and scene info for a given scene node. + # + # \return (-1, None) for error. + # def find_layer_n_scene_of_node(self, node_id): for layer_idx, layer in enumerate(self._layers): for scene_node in layer.scenes: @@ -569,6 +573,17 @@ return dup_group + ## \brief Return associated layer index of given layer group. + # + # \return -1 for error. + # + def find_layer_of_group(self, group_id): + for layer_idx, layer in enumerate(self._layers): + if layer.group.getAttribute('id') == group_id: + return layer_idx + pass + return -1 + def insert_frames(self, layer_idx, frame_idx, num): layer = self._layers[layer_idx] for scene_node in layer.scenes: diff -r 2609b219703d -r df474448364e pyink/domview_ui.py --- a/pyink/domview_ui.py Tue Jan 11 17:24:56 2011 +0800 +++ b/pyink/domview_ui.py Tue Jan 11 17:39:06 2011 +0800 @@ -542,6 +542,9 @@ def find_key_from_group(self, scene_group_id): layer_idx, scene_node = \ self._dom.find_layer_n_scene_of_node(scene_group_id) + if layer_idx == -1: + raise ValueError, \ + 'can not find the key for group %s' % (scene_group_id) start, end, tween_name = self._dom._parse_one_scene(scene_node) tween_type = self._tween_type_names.index(tween_name) return layer_idx, (start, end, tween_type) @@ -589,6 +592,15 @@ def register_active_frame_callback(self, cb): self._fl_stack.register_active_frame_callback(cb) pass + + ## \brief Find the layer index associated with a given layer group. + # + def find_layer_from_group(self, group_id): + layer_idx = self._domview.find_layer_from_group(group_id) + if layer_idx == -1: + raise ValueError, \ + 'can not find the layer for group %s' % (group_id) + return layer_idx ## \brief Get duplicate group of a layer. #