Mercurial > MadButterfly
changeset 1265:ca301f6abef7
Support undo for insert key frame/rm keyframe. We will refresh all layers and scenes since it is not feasible to collect these changes and update the layers and scenes. We may scan two level only in the future to improve the performance.
author | wycc |
---|---|
date | Wed, 12 Jan 2011 15:01:14 +0800 |
parents | ff410dcdea02 |
children | d4559e7f82cd |
files | pyink/MBScene.py pyink/consistency.py pyink/data_monitor.py pyink/domview.py pyink/domview_ui.py |
diffstat | 5 files changed, 76 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/pyink/MBScene.py Wed Jan 12 12:25:45 2011 +0800 +++ b/pyink/MBScene.py Wed Jan 12 15:01:14 2011 +0800 @@ -70,6 +70,7 @@ self.current = 0 self._domviewui = create_domview_ui() + self._locker = self._domviewui pass def change_active_frame(self, node): @@ -255,6 +256,14 @@ self._lockui = False return + def lock(self): + self._domviewui.lock() + pass + + def unlock(self): + self._domviewui.unlock() + pass + def doExtendScene(self,w): self._lockui = True
--- a/pyink/consistency.py Wed Jan 12 12:25:45 2011 +0800 +++ b/pyink/consistency.py Wed Jan 12 15:01:14 2011 +0800 @@ -1,6 +1,6 @@ import dom_event from data_monitor import data_monitor - +import traceback ## \brief Check consistency of a DOM-tree associated with a domview_ui. # # This is a co-worker of \ref domview_ui to check DOM-tree and make @@ -26,6 +26,7 @@ def __init__(self, domview_ui): self._domview = domview_ui + self._locker = self._domview self._doc = None self._root = None pass @@ -75,6 +76,7 @@ pass def _remove_node_recursive(self, node, child): + return for cchild in child.childList(): self._remove_node_recursive(child, cchild) pass @@ -131,5 +133,22 @@ pass def do_attr_modified(self, node, name, old_value, new_value): + if node.name() == 'ns0:scene' and name == 'ref': + try: + if new_value: + raise ValueError('The new_value is not empty') + self._domview.reset() + except: + traceback.print_exc() + pass + pass pass pass + + def lock(self): + self._domview.lock() + pass + + def unlock(self): + self._domview.unlock() + pass
--- a/pyink/data_monitor.py Wed Jan 12 12:25:45 2011 +0800 +++ b/pyink/data_monitor.py Wed Jan 12 15:01:14 2011 +0800 @@ -34,7 +34,7 @@ print ' kws: %s' % (repr(kws)) pass - if not self._domview.lock(): # can not lock + if not self._locker.lock(): # can not lock if debug_level >= 1: print ' fault to lock' pass @@ -43,7 +43,7 @@ try: func(self, *args, **kws) finally: - self._domview.unlock() + self._locker.unlock() pass pass return sentinel
--- a/pyink/domview.py Wed Jan 12 12:25:45 2011 +0800 +++ b/pyink/domview.py Wed Jan 12 15:01:14 2011 +0800 @@ -72,7 +72,7 @@ except: pass pass - pass + pass def _find_maxframe(self, scenes_node): maxframe = 0 @@ -104,8 +104,7 @@ pass else: if child_id not in self._id2node: - raise ValueError, \ - 'remove a node that is never known (%s)' % (child_id) + return del self._id2node[child_id] pass @@ -189,7 +188,7 @@ def _parse_one_scene(self, scene_node): assert scene_node.name() == 'ns0:scene' - + start = int(scene_node.getAttribute("start")) try: end = int(scene_node.getAttribute("end")) @@ -221,6 +220,7 @@ continue try: + ref = scene_node.getAttribute('ref') start, end, scene_type = self._parse_one_scene(scene_node) except: continue @@ -349,6 +349,10 @@ self._init_metadata() self._parse_all_layers() pass + + def reset(self): + self.handle_doc_root( self._doc, self._root) + pass def dumpattr(self, n): s = "" @@ -665,6 +669,12 @@ pass pass + ## \brief add the current position to the undo buffer + # + def mark_undo(self, msg): + self._doc.done("none", msg) + pass + ## \brief Remove frames # # - Scenes covered by removing range were removed.
--- a/pyink/domview_ui.py Wed Jan 12 12:25:45 2011 +0800 +++ b/pyink/domview_ui.py Wed Jan 12 15:01:14 2011 +0800 @@ -75,7 +75,6 @@ def _add_frameline(self, layer_idx): if layer_idx > len(self._framelines): raise ValueError, 'layer number should be a consequence' - vbox = self._frameline_vbox line = frameline(self._num_frames_of_line) @@ -111,6 +110,7 @@ hbox = line.parent vbox.remove(hbox) + hbox.remove(line) del self._framelines[layer_idx] for idx in range(layer_idx, len(self._framelines)): @@ -118,7 +118,23 @@ pass pass + def _remove_all_framelines(self): + num = len(self._framelines) + + for idx in range(0,num): + line = self._framelines[idx] + hbox = line.parent + self._frameline_vbox.remove(hbox) + self._framelines=[] + self._last_mouse_over_frameline = None + self._last_active_frameline = None + self._active_frame_callback = None + + pass + def _init_framelines(self): + if self._framelines!= None: + return self._framelines = [] box = gtk.ScrolledWindow() @@ -411,6 +427,13 @@ self._root = root pass + ## \brief Reload the document. + # + def reset(self): + self._fl_stack._remove_all_framelines() + self.handle_doc_root(self._doc, self._root) + pass + ## \brief Mark given frame as a key frame. # def mark_key(self, layer_idx, key_idx): @@ -645,6 +668,13 @@ max_frame = self._dom.get_max_frame() return max_frame + ## \brief add the current position to the undo buffer. + # + # The msg will be displayed in the UI to indicate the undo set. + def mark_undo(self, msg): + self._dom.mark_undo(msg) + pass + @property def doc(self): return self._doc