diff pyink/pyink.py @ 1323:ffbbd3aa218d

Make a component from a group. User can translate a group into a component from context menu.
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 30 Jan 2011 19:15:17 +0800
parents 6586cd10c92f
children 0a2034f490e5
line wrap: on
line diff
--- a/pyink/pyink.py	Sun Jan 23 09:24:01 2011 +0800
+++ b/pyink/pyink.py	Sun Jan 30 19:15:17 2011 +0800
@@ -13,24 +13,50 @@
 import pygtk
 import gtk
 from MBScene import *
-global ink_inited
-ink_inited=0
-def start_desktop(inkscape,ptr):
-    global ink_inited
-    if ink_inited == 1:
-    	desktop = pybInkscape.GPointer_2_PYSPDesktop(ptr)
-	top = desktop.getToplevel()
-    	#dock = desktop.getDock()
-    	#item = dock.new_item("scene", "scene", "feBlend-icon", dock.ITEM_ST_DOCKED_STATE)
-    	scene = MBScene(desktop,top)
-    	scene.show()
+
+all_desktop_mbscenes = {}
+
+def _init_mbscene(inkscape, ptr):
+    global all_desktop_mbscenes
+    
+    desktop = pybInkscape.GPointer_2_PYSPDesktop(ptr)
+
+    top = desktop.getToplevel()
+    mbscene = MBScene(desktop,top)
+    mbscene.show()
+
+    all_desktop_mbscenes[desktop] = mbscene
+
+    print hash(desktop)
+    pass
+
+
+## \brief Handler for events of activating a desktop.
+#
+def act_desktop(inkscape, ptr):
+    # Get Python wrapper of SPDesktop passed by ptr.
+    desktop = pybInkscape.GPointer_2_PYSPDesktop(ptr)
+    
+    top = desktop.getToplevel()
+    if not top:                 # has not top window.
         return
-        
 
-    ink_inited = 1
+    if desktop in all_desktop_mbscenes:
+        return                  # already initialized
+    
+    _init_mbscene(inkscape, ptr)
+    pass
 
 
 def pyink_start():
-    print 'pyink_start()'
-    pybInkscape.inkscape.connect('activate_desktop', start_desktop)
+    pybInkscape.inkscape.connect('activate_desktop', act_desktop)
     pass
+
+
+def pyink_context_menu(view, item, menu_factory):
+    print hash(view)
+    if view in all_desktop_mbscenes:
+        mbscene = all_desktop_mbscenes[view]
+        mbscene.context_menu(item, menu_factory)
+        pass
+    pass