Mercurial > MadButterfly
changeset 1316:9ab8d50dcf7e
Refactory code of refreshing UI
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 22 Jan 2011 19:28:36 +0800 |
parents | fcff6978f9bf |
children | e2ad9eb7f7a4 |
files | pyink/comp_dock.py pyink/domview.py pyink/domview_ui.py |
diffstat | 3 files changed, 63 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/pyink/comp_dock.py Sat Jan 22 14:23:42 2011 +0800 +++ b/pyink/comp_dock.py Sat Jan 22 19:28:36 2011 +0800 @@ -56,13 +56,16 @@ self._dock_top.show() pass - ## \brief Refresh content of component list and timeline list. + ## \brief Update the list of components. # - def refresh(self): + # The cursor is still keeping on the name of current component. + # + def refresh_components(self): components_model = self._components_model components_model.clear() - for comp_name in self._domview_ui.all_comp_names(): + all_comp_names = self._domview_ui.all_comp_names() + for comp_name in all_comp_names: if comp_name == 'main': editable = False else: @@ -72,16 +75,34 @@ components_model.append((comp_name, editable)) pass - self._components_treeview.set_cursor((0,)) + cur_comp_name = self._domview_ui.get_current_component() + cur_comp_idx = all_comp_names.index(cur_comp_name) + self._components_treeview.set_cursor((cur_comp_idx,)) + pass + ## \brief Update the list of timelines. + # + # The cursor is still keeping on the name of current component. + # + def refresh_timelines(self): timelines_model = self._timelines_model timelines_model.clear() - for timeline_name in self._domview_ui.all_timeline_names(): + all_timeline_names = self._domview_ui.all_timeline_names() + for timeline_name in all_timeline_names: timelines_model.append((timeline_name, True)) pass - self._timelines_treeview.set_cursor((0,)) + cur_tl_name = self._domview_ui.get_current_timeline() + cur_tl_idx = all_timeline_names.index(cur_tl_name) + self._timelines_treeview.set_cursor((cur_tl_idx,)) + pass + + ## \brief Refresh content of component list and timeline list. + # + def refresh(self): + self.refresh_components() + self.refresh_timelines() pass def dom_add_component(self, name):
--- a/pyink/domview.py Sat Jan 22 14:23:42 2011 +0800 +++ b/pyink/domview.py Sat Jan 22 19:28:36 2011 +0800 @@ -169,7 +169,6 @@ self._comp_names.add('main') self._main_comp = comp - self._cur_comp = comp pass def _parse_components(self): @@ -232,6 +231,11 @@ self._component_manager_init_metadata() self._set_main_component() self._parse_components() + + self._cur_comp = self._main_comp + tl = self._main_comp.get_timeline('default') + self._cur_timeline = tl + self._scenes_node = tl.scenes_node pass def _create_component_group(self): @@ -352,6 +356,9 @@ gid = comp_node.getAttribute('ref') comp_group = self.get_node(gid) return comp_group + + def get_current_component(self): + return self._cur_comp.name() def switch_timeline(self, timeline_name): tl = self._cur_comp.get_timeline(timeline_name) @@ -377,6 +384,9 @@ def has_timeline(self, name): r = self._cur_comp.has_timeline(name) return r + + def get_current_timeline(self): + return self._cur_timeline.name() pass
--- a/pyink/domview_ui.py Sat Jan 22 14:23:42 2011 +0800 +++ b/pyink/domview_ui.py Sat Jan 22 19:28:36 2011 +0800 @@ -388,6 +388,10 @@ self._comp_dock = comp_dock(self) pass + + def _ui_comp_refresh(self): + self._comp_dock.refresh() + pass ## \brief Setup desktop that the document will be serviced. # @@ -410,9 +414,8 @@ def switch_component(self, name): self._dom.switch_component(name) - self.reset() # FIXME: it would parse layers again - # while switch_compoent already parses - # it. + self._framelines_refresh() # from domview_ui + self._comp_dock.refresh_timelines() pass def all_comp_names(self): @@ -423,6 +426,9 @@ r = self._dom.has_component(name) return r + def get_current_component(self): + return self._dom.get_current_component() + def add_timeline(self, name): self._dom.add_timeline(name) self._comp_dock.dom_add_timeline(name) @@ -434,7 +440,8 @@ pass def switch_timeline(self, name): - self._dom.siwtch_timeline(name) + self._dom.switch_timeline(name) + self._framelines_refresh() # from domview_ui pass def all_timeline_names(self): @@ -444,6 +451,9 @@ def has_timeline(self, name): r = self._dom.has_timeline(name) return r + + def get_current_timeline(self): + return self._dom.get_current_timeline() pass @@ -506,19 +516,26 @@ self._fl_stack.init_framelines() self._add_frameline_for_every_layer() self._fl_stack.show_framelines() - self._comp_dock.refresh() # from domview_ui_comp + self._ui_comp_refresh() # from domview_ui_comp self._doc = doc self._root = root pass + ## \brief Update framelines according domview. + # + def _framelines_refresh(self): + self._fl_stack.remove_all_framelines() + self._add_frameline_for_every_layer() + self._fl_stack.show_framelines() + pass + ## \brief Parse the document from the scratch and update UI. # def reset(self): - self._fl_stack.remove_all_framelines() self._dom.reset() - self._add_frameline_for_every_layer() - self._fl_stack.show_framelines() + self._framelines_refresh() + self._ui_comp_refresh() # from domview_ui_comp pass ## \brief Mark given frame as a key frame.