diff pyink/comp_dock.py @ 1310:85d04ba11146

Support adding new components
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 20 Jan 2011 12:44:37 +0800
parents f2b1b22f7cbc
children e6bb9d00341f
line wrap: on
line diff
--- a/pyink/comp_dock.py	Thu Jan 20 10:54:27 2011 +0800
+++ b/pyink/comp_dock.py	Thu Jan 20 12:44:37 2011 +0800
@@ -76,13 +76,94 @@
             timelines_model.append((timeline_name, True))
             pass
         pass
+
+    def _current_component(self):
+        treeview = self._components_treeview
+        path, col = treeview.get_cursor()
+
+        model = self._components_model
+        itr = model.get_iter(path)
+        name = model.get_value(itr, 0)
+        return name
+
+    def _current_timeline(self):
+        treeview = self._timelines_treeview
+        path, col = treeview.get_cursor()
+
+        model = self._timelines_model
+        itr = model.get_iter(path)
+        name = model.get_value(itr, 0)
+        return name
+
+    def _add_component(self):
+        def _make_component_name():
+            comp_name = 'New Component'
+            idx = 0
+            while comp_name in self._domview_ui.all_comp_names():
+                comp_name = 'New Component %d' % (idx)
+                idx = idx + 1
+                pass
+            return comp_name
+
+        comp_name = _make_component_name()
+        print comp_name
+        self._domview_ui.add_component(comp_name)
+        pass
+
+    def _rm_component(self):
+        if self._current_component() == 'main':
+            return
+        
+        treeview = self._components_treeview
+        path, col = treeview.get_cursor()
+        
+        model = self._components_model
+        itr = model.get_iter(path)
+        comp_name = model.get_value(itr, 0)
+        print comp_name
+
+        self._domview_ui.rm_component(comp_name)
+        pass
+    
+    def _add_timeline(self):
+        def _make_timeline_name():
+            tl_name = 'New Timeline'
+            idx = 0
+            while tl_name in self._domview_ui.all_timeline_names():
+                tl_name = 'New Timeline %d' % (idx)
+                idx = idx + 1
+                pass
+            return tl_name
+
+        if self._current_component() == 'main':
+            return
+
+        tl_name = _make_timeline_name()
+        print tl_name
+        self._domview_ui.add_timeline(tl_name)
+        pass
+
+    def _rm_timeline(self):
+        if self._current_component() == 'main':
+            return
+        
+        treeview = self._timelines_treeview
+        path, col = treeview.get_cursor()
+        
+        model = self._timelines_model
+        itr = model.get_iter(path)
+        tl_name = model.get_value(itr, col)
+        print tl_name
+
+        self._domview_ui.rm_timeline(tl_name)
+        pass
     
     def on_add_comp_clicked(self, *args):
-        print args
+        self._add_component()
         pass
 
     def on_remove_comp_clicked(self, *args):
-        print args
+        self._rm_component()
         pass
 
     def on_treeview_components_cursor_changed(self, *args):
@@ -95,11 +176,11 @@
         pass
     
     def on_add_timeline_clicked(self, *args):
-        print args
+        self._add_timeline()
         pass
 
     def on_remove_timeline_clicked(self, *args):
-        print args
+        self._rm_timeline()
         pass
 
     def on_treeview_timelines_cursor_changed(self, *args):