Mercurial > MadButterfly
changeset 1336:0b5ee9c90af7
Update components and timelines list for async changes on DOM
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 01 Feb 2011 23:20:26 +0800 |
parents | 194c7a831083 |
children | 05ced4a389bf |
files | pyink/comp_dock.py pyink/consistency.py pyink/domview.py pyink/domview_ui.py pyink/unlink_clone.py |
diffstat | 5 files changed, 73 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/pyink/comp_dock.py Mon Jan 31 23:21:20 2011 +0800 +++ b/pyink/comp_dock.py Tue Feb 01 23:20:26 2011 +0800 @@ -164,6 +164,11 @@ def start_handle_ui_events(self): self._builder.connect_signals(self) pass + + def install_dock(self, desktop): + doc = desktop.doc() + doc.connectCommit(self.on_commit) + pass def _current_component(self): treeview = self._components_treeview @@ -400,6 +405,10 @@ self._desktop.doc().done("None", "Switch to another timeline") pass + + def on_commit(self): + print 'commit' + pass pass ## \brief Component dock @@ -412,4 +421,9 @@ self.start_handle_ui_events() pass + + def install_dock(self, desktop): + comp_dock_base.install_dock(self, desktop) + comp_dock_ui.install_dock(self, desktop) + pass pass
--- a/pyink/consistency.py Mon Jan 31 23:21:20 2011 +0800 +++ b/pyink/consistency.py Tue Feb 01 23:20:26 2011 +0800 @@ -80,13 +80,12 @@ pass def _remove_node_recursive(self, node, child): - return for cchild in child.childList(): self._remove_node_recursive(child, cchild) pass child_name = child.name() - if child_name not in ('ns0:scene', 'svg:g'): + if child_name not in ('ns0:scenes', 'ns0:scene', 'svg:g'): return #
--- a/pyink/domview.py Mon Jan 31 23:21:20 2011 +0800 +++ b/pyink/domview.py Tue Feb 01 23:20:26 2011 +0800 @@ -90,6 +90,9 @@ return names def parse_timelines(self): + print 'parse timelines fro component ' + self.name() + self.timelines[:] = [] + if self.node: assert self.node.name() == 'ns0:component' pass @@ -99,6 +102,7 @@ if child.name() == 'ns0:scenes': tl = Timeline(child) self.timelines.append(tl) + print ' ' + tl.name() pass pass pass @@ -173,6 +177,48 @@ pass +## \brief A mix-in for class component_manager for UI updating. +# +# This class collects all methods for supporting UI updating. +# +class component_manager_ui_update(object): + ## \brief Update the list of components. + # + def reparse_components(self): + saved_cur_comp = self._cur_comp + self._components[:] = [self._main_comp] + self._comp_names.clear() + self._parse_components() + + for comp in self._components: + if comp.name() == saved_cur_comp.name(): + self._cur_comp = comp + break + pass + else: + self._cur_comp = self._main_comp + pass + pass + + ## \brief Update the list of timelines of current component. + # + def reparse_timelines(self): + comp = self._cur_comp + saved_cur_timeline = self._cur_timeline + comp.parse_timelines() + + for timeline in comp.timelines: + if timeline.name() == saved_cur_timeline.name(): + self._cur_timeline = timeline + break + pass + else: + self._cur_timeline = comp.timelines[0] + pass + pass + pass + + ## \brief A mix-in for class domview for management of components. # # This class is responsible for manage components and timelines. It @@ -189,7 +235,7 @@ # special case with slightly different in structure. It should be # removed and normalized to normal components. # -class component_manager(object): +class component_manager(component_manager_ui_update): def __init__(self): self._components_node = None self._components = [] @@ -703,7 +749,9 @@ if old_value: del self._id2node[old_value] pass - self._id2node[new_value] = node + if new_value: + self._id2node[new_value] = node + pass pass elif name == 'ref' and node.name() == 'ns0:scene': parent_node = node.parent() @@ -759,9 +807,11 @@ try: node_id = node.getAttribute('id') except: - return - - self._id2node[node_id] = node + pass + else: + self._id2node[node_id] = node + pass + for n in node.childList(): self._collect_node_ids_recursive(n) pass
--- a/pyink/domview_ui.py Mon Jan 31 23:21:20 2011 +0800 +++ b/pyink/domview_ui.py Tue Feb 01 23:20:26 2011 +0800 @@ -484,11 +484,13 @@ pass def refresh_components(self): + self._dom.reparse_components() dock = self._comp_dock dock.refresh_components() pass def refresh_timelines(self): + self._dom.reparse_timelines() dock = self._comp_dock dock.refresh_timelines() pass
--- a/pyink/unlink_clone.py Mon Jan 31 23:21:20 2011 +0800 +++ b/pyink/unlink_clone.py Tue Feb 01 23:20:26 2011 +0800 @@ -108,7 +108,7 @@ pass def do_attr_modified(self, node, name, old_value, new_value): - if name == 'id' and node.name() != 'svg:use': + if name == 'id' and node.name() != 'svg:use' and new_value: # # The ID of a node may not be assigned when it being # inserted, and be assigned later. So, we checking