changeset 1099:5ba2cab1d505

Add name editor to edit the inkscape:label withgout using the object property editor. This is more Flash-like operation.
author wycc
date Sun, 05 Dec 2010 08:16:54 +0800
parents cb4a2ffdf9e8
children 9d52dda8d49f
files pyink/MBScene.py
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Sat Dec 04 16:58:25 2010 +0800
+++ b/pyink/MBScene.py	Sun Dec 05 08:16:54 2010 +0800
@@ -92,8 +92,32 @@
 	self.scenemap = None
 	self.top = None
 	self.last_update = None
+	self.startPolling()
+	self.last_select = None
 	pass
 
+    def startPolling(self):
+	objs =  self.desktop.selection.list()
+	if len(objs) != 1: 
+	    glib.timeout_add(500,self.startPolling)
+	    try:
+		self.nameEditor.set_text('')
+	    except:
+		traceback.print_exc()
+		pass
+	    return
+	o = objs[0]
+	if o == self.last_select: 
+            glib.timeout_add(500,self.startPolling)
+	    return
+	self.last_select = o
+	try:
+	    self.nameEditor.set_text(o.repr.attribute("inkscape:label"))
+	except:
+	    self.nameEditor.set_text('')
+	    pass
+        glib.timeout_add(500,self.startPolling)
+
     def confirm(self,msg):
 	vbox = gtk.VBox()
 	vbox.pack_start(gtk.Label(msg))
@@ -611,6 +635,15 @@
 	self.extendScene()
 	#self.grid.show_all()
 	pass
+    def changeObjectLabel(self,w):
+	o = self.desktop.selection.list()[0]
+	o.repr.setAttribute("inkscape:label", self.nameEditor.get_text(), True)
+    def addNameEditor(self,hbox):
+	self.nameEditor = gtk.Entry(max=40)
+	hbox.pack_start(self.nameEditor,expand=False,fill=False)
+	self.editDone = gtk.Button('Set')
+	hbox.pack_start(self.editDone,expand=False,fill=False)
+	self.editDone.connect('clicked', self.changeObjectLabel)
     
     def addButtons(self,hbox):
 	#btn = gtk.Button('Edit')
@@ -628,6 +661,7 @@
 	btn=gtk.Button('Duplicate Key')
 	btn.connect('clicked', self.doDuplicateKeyScene)
 	hbox.pack_start(btn,expand=False,fill=False)
+	self.addNameEditor(hbox)
 	pass
     
     def onQuit(self, event):