changeset 1224:5d731460b32c

Remove search_by_id() from frameline. - frameline is only responsible for drawing a row of frames. - layers and scenes are managed by MBScene_dom. So, function of search_by_id() must move to MBScene_dom class. - onCellClick() and _change_active_frame() are responsible for handling GUI event. - It should not be used with workaround to implement some function. - Solutions - MBScene_dom.find_layer_n_scene_of_nod() is used to replace search_by_id(). - MBScene_framelines.active_frame() is used to replace the workaround.
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 06 Jan 2011 11:11:27 +0800
parents ec964cf4c993
children bdc2ed94ea37
files pyink/MBScene.py pyink/frameline.py
diffstat 2 files changed, 48 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Thu Jan 06 09:39:47 2011 +0800
+++ b/pyink/MBScene.py	Thu Jan 06 11:11:27 2011 +0800
@@ -525,6 +525,16 @@
 	    layers[idx].idx = idx
 	    pass
 	pass
+
+    def find_layer_n_scene_of_node(self, node_id):
+	for layer_idx, layer in enumerate(self._layers):
+	    for scene_node in layer.scenes:
+		scene_group_id = scene_node.getAttribute('ref')
+		if scene_group_id == node_id:
+		    return layer_idx, scene_node
+		pass
+	    pass
+	pass
     pass
 
 ## \brief Maintain frameline list for MBScene.
@@ -542,18 +552,6 @@
 	self._last_active_frameline = None
 	pass
 
-    def search_frameline_by_id(self, id):
-	"""
-	Search the frameline whose layer is id
-	"""
-
-	for f in self._framelines:
-	    idx = f.search_by_id(id)
-	    if idx != -1:
-	        return (f,idx)
-	    pass
-	return (None,-1)
-    
     def _change_hover_frameline(self, widget, event):
         """
 	Hide all hover frames. This is a hack. We should use the lost focus
@@ -566,16 +564,22 @@
 	self._last_mouse_over_frameline = widget
 	pass
 
+    def _active_frameline(self, frameline):
+	last = self._last_active_frameline
+	
+	if last and last != frameline:
+	    last.deactive()
+	    pass
+	
+	self._last_active_frameline = frameline
+	pass
+
     ## \brief Called for changing of active frame.
     #
     # This handle deactive previous frameline that owns an active frame when a
     # frame in another frameline is activated.
     def _change_active_frame(self, widget, frame, button):
-	if self._last_active_frameline and \
-		self._last_active_frameline != widget:
-	    self._last_active_frameline.deactive()
-	    pass
-	self._last_active_frameline = widget
+	self._active_frameline(widget)
 	pass
 
     ## \brief Add a frameline into the frameline box for the given layer.
@@ -604,6 +608,7 @@
 	
 	line.label = label
 	line.layer_idx = layer_idx
+	# TODO: The following line of code should be moved to MBScene.
 	line.connect(line.FRAME_BUT_PRESS, self.onCellClick)
 	line.connect('motion-notify-event', self._change_hover_frameline)
 	line.connect(frameline.FRAME_BUT_PRESS, self._change_active_frame)
@@ -655,6 +660,12 @@
     def _show_framelines(self):
 	self._frameline_vbox.show_all()
 	pass
+
+    def active_frame(self, layer_idx, frame_idx):
+	frameline = self._framelines[layer_idx]
+	self._active_frameline(frameline)
+	frameline.active_frame(frame_idx)
+	pass
     pass
 
 ## \brief MBScene connect GUI and DOM-tree
@@ -709,28 +720,36 @@
 	self.change_active_frame(self.last_select.repr.parent())
 	pass
 
-    def change_active_frame(self, obj):
+    def change_active_frame(self, node):
 	"""
-	    Change the active frame to the current selected object. This will
-	    tell users where the current object is.
+	    Change the active frame to the current selected node. This will
+	    tell users where the current node is.
 	"""
 
-	while obj:
-	    id = obj.getAttribute('id')
+	while node:
 	    try:
-		# Search for the frameline which use @obj as one of its scene
+		node_id = node.getAttribute('id')
+	    except:
+		node = node.parent()
+		continue
+	    
+	    try:
+		# Search for the frameline which use @node as one of its scene
 		# group.
-		(frameline, frame) = self.search_frameline_by_id(id)
-		if frameline == None:
-		    print "Error: internal structure error %s not found" % id
+		try:
+		    layer_idx, scene_node = \
+			self.find_layer_n_scene_of_node(node_id)
+		except:
+		    pass
 		else:
-		    self._change_active_frame(frameline, 0, 0)
-		    self.onCellClick(frameline, frame, 0)
+		    start, end, tween_type_name = \
+			self._parse_one_scene(scene_node)
+		    self.active_frame(layer_idx, start)
 		    return
 	    except:
 		traceback.print_exc()
 		pass
-	    obj = obj.parent()
+	    node = node.parent()
 	    pass
 	pass
 
--- a/pyink/frameline.py	Thu Jan 06 09:39:47 2011 +0800
+++ b/pyink/frameline.py	Thu Jan 06 11:11:27 2011 +0800
@@ -866,18 +866,6 @@
 	key = self._keys[pos]
 	return key.ref
 
-    def search_by_id(self,ID):
-	for k in self._keys:
-	    try:
-		if k.ref == None: continue
-	        if k.ref.getAttribute("ref") == ID:
-		    return k.idx
-	    except:
-		traceback.print_exc()
-		pass
-	    pass
-	return -1
-    
     def set_frame_data(self, idx, value):
 	pos = self._find_keyframe(idx)
 	key = self._keys[pos]