changeset 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
files pyink/comp_dock.py pyink/domview.py
diffstat 2 files changed, 92 insertions(+), 8 deletions(-) [+]
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):
--- a/pyink/domview.py	Thu Jan 20 10:54:27 2011 +0800
+++ b/pyink/domview.py	Thu Jan 20 12:44:37 2011 +0800
@@ -44,10 +44,13 @@
                 break
             pass
         else:                   # no any ns0:scenes
-            scenes_node = doc.createElementById('ns0:scenes')
+            doc = self._comp_mgr._doc
+            scenes_node = doc.createElement('ns0:scenes')
             scenes_node.setAttribute('name', 'default')
+            
             node_id = self._comp_mgr.new_id()
             scenes_node.setAttribute('id', node_id)
+            
             comp_node.appendChild(scenes_node)
             pass
         pass
@@ -70,7 +73,7 @@
             pass
         
         comp_node = self.node
-        for child in comp_node.childList:
+        for child in comp_node.childList():
             if child.name() == 'ns0:scenes':
                 tl = Timeline(child)
                 self.timelines.append(tl)
@@ -100,7 +103,7 @@
         doc = self._comp_mgr._doc
         comp_node = self.node
         
-        scenes_node = doc.createElementById('ns0:scenes')
+        scenes_node = doc.createElement('ns0:scenes')
         scenes_node.setAttribute('name', name)
         node_id = self._comp_mgr.new_id()
         scenes_node.setAttribute('id', node_id)
@@ -218,7 +221,7 @@
             raise ValueError, \
                 'try add a component with existed name %s' % (comp_name)
 
-        comp_node = self._doc.createElementById('ns0:component')
+        comp_node = self._doc.createElement('ns0:component')
         comp_id = self.new_id()
         comp_node.setAttribute('id', comp_id)
         comp_node.setAttribute('name', comp_name)