changeset 203:1d485bf96480

Add a sample inkscape extention to assign symbol name to an SVG element.
author wycc
date Wed, 10 Dec 2008 09:17:16 +0800
parents 75ec0124202a
children eb6ff421da7e
files inkscape/AssignSymbol.py inkscape/MB_assignSymbol.inx inkscape/README.mbext
diffstat 3 files changed, 134 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inkscape/AssignSymbol.py	Wed Dec 10 09:17:16 2008 +0800
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+import inkex
+import pygtk
+import gtk
+
+class AssignSymbol(inkex.Effect):
+	def effect(self):
+		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+		self.window.set_position(gtk.WIN_POS_MOUSE)
+		self.defaultname = 'input symbol name here'
+		self.fillcontent()
+		self.window.show_all()
+		self.window.connect("delete_event", gtk.main_quit)
+		gtk.main()
+	def onQuit(self,data):
+		gtk.main_quit()
+	def onAssign(self,data):
+		text = self.text.get_text()
+		if text != self.defaultname:
+			self.node.set("mbname",text)
+		gtk.main_quit()
+		
+	def confirm(self,msg):
+		vbox = gtk.VBox()
+		vbox.pack_start(gtk.Label(msg))
+		self.button = gtk.Button('OK')
+		vbox.pack_start(self.button)
+		self.button.connect("clicked", self.onQuit)
+		self.window.add(vbox)
+	def dumpattr(self,n):
+		s = ""
+		for a,v in n.attrib.items():
+			s = s + ("%s=%s"  % (a,v))
+		return s
+			
+	def dump(self,node,l=0):
+		print " " * l*2,"<", node.tag, self.dumpattr(node),">"
+		for n in node:
+			self.dump(n,l+1)
+		print " " * l * 2,"/>"
+
+	def fillcontent(self):
+		if len(self.selected) != 1:
+			self.confirm('Please select on group only')
+			return
+		for id,node in self.selected.iteritems():
+			#self.dump(node)
+			self.node = node
+			vbox = gtk.VBox()
+			vbox.pack_start(gtk.Label('Please input the symbol name'))
+			self.text = gtk.Entry()
+			try:
+				self.text.set_text(node.get("mbname"))
+			except:
+				self.text.set_text(self.defaultname)
+			vbox.pack_start(self.text)
+			self.button = gtk.Button('OK')
+			self.button.connect("clicked", self.onAssign)
+			vbox.pack_start(self.button)
+			self.window.add(vbox)
+			self.window.show_all()
+			
+		
+		
+
+a=AssignSymbol()
+a.affect()
+
+# vim: set ts=4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inkscape/MB_assignSymbol.inx	Wed Dec 10 09:17:16 2008 +0800
@@ -0,0 +1,15 @@
+<inkscape-extension>
+    <name>Convert to Symbol</name>
+    <id>MadButterfly.ConvertSymbol</id>
+	<dependency type="executable" location="extensions">AssignSymbol.py</dependency>
+	<dependency type="executable" location="extensions">inkex.py</dependency>
+    <effect>
+		<object-type>group</object-type>
+		<effects-menu>
+			<submenu _name="MadButterfly"/>
+		</effects-menu>
+    </effect>
+    <script>
+        <command reldir="extensions" interpreter="python">AssignSymbol.py</command>
+    </script>
+</inkscape-extension>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inkscape/README.mbext	Wed Dec 10 09:17:16 2008 +0800
@@ -0,0 +1,50 @@
+# Introduction
+
+This is inkscape extention for the MadButteerfly. It can help users to establish SVG files which is usable for the MadButterfly SVG parser and loader.
+
+# Requirement
+
+The following package must be installed in your system
+ * python 2.5 or above
+ * pygtk
+ * python lxml module
+
+
+# Installation
+
+The installation is simple. Just copy all files to the inkscape extention directory. Usually, it should be /usr/share/inkscape/extentions.
+
+# Usage
+
+## Assign an MadButterfly symbol to an element
+
+This function will give an SVG element, such as path or group, a MadButterfly symbol so that we can access them by symbol in the MadButterfly program.
+
+Steps
+   * Select a single object in the worksapce. If you want to assign multiple elements to one symbol, please group them.
+   * Select the effect/MadButterFly/Convert to symbol
+   * Input the symbol name in the text entry
+   * Press OK
+
+You can check by using the XML editor in the inkscape. A new attribute mbname will be added. The MadButterfly parser willput this object into the symbol table by using the mbname.
+
+## Convert to button(In planned)
+
+This function will convert a symbol into a button. A button is a symbol with three groups inside it. For example,
+
+<g id="g1234" mbname="btn">
+    <g id="g1235" frame="active">
+    </g>
+    <g id="g1235" frame="normal">
+    </g>
+    <g id="g1236" frame="click">
+    </g>
+</g>
+
+
+The content of all three groups will be the same. We can modify each of them seperately. By default, the active and click group will be hidden. We can use the button editor to edit it.
+
+## Button editor(In planned)
+
+This function will invoke another inkscape to edit the selected button. In the new inkscape, all three group will be visible and put in different layer. We can move them and edit them. When we close the inkscape, the MB extention will collect the new content and update the groups in the original SVG file. By this way, we can edit the button in any SVG file.
+