Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/svglabel.py
diff options
context:
space:
mode:
authorSimon Schampijer <simon@schampijer.de>2007-07-12 20:45:24 (GMT)
committer Simon Schampijer <simon@schampijer.de>2007-07-12 20:45:24 (GMT)
commit8a2defe196f4f1d1edd7845ca871d58a57c717e1 (patch)
tree9244672f0969a47ab7dc509bac0427c51df5dfe4 /svglabel.py
parent1c2728aad09cf28fd194f20c01138fc53e0f4b68 (diff)
Started to merge the memosono game and the meorize game into one activity.
Diffstat (limited to 'svglabel.py')
-rwxr-xr-xsvglabel.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/svglabel.py b/svglabel.py
new file mode 100755
index 0000000..64c7f44
--- /dev/null
+++ b/svglabel.py
@@ -0,0 +1,103 @@
+#! /usr/bin/env python
+#
+# Copyright (C) 2007, One Laptop Per Child
+#
+# Muriel de Souza Godoi - muriel@laptop.org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import gtk, pygtk
+import rsvg
+import cairo
+import re
+
+class SvgLabel(gtk.DrawingArea):
+
+ filename = ''
+ fill_color = ''
+ stroke_color = ''
+ background_color = ''
+
+
+ def __init__(self, filename, fill_color, stroke_color, pixbuf = False, background_color = '', request_x = 45, request_y = 45):
+ gtk.DrawingArea.__init__(self)
+ self.set_size_request(request_x, request_y)
+ self.filename = filename
+ self.background_color = background_color
+ self.fill_color = fill_color
+ self.stroke_color = stroke_color
+ self.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(background_color))
+ if pixbuf:
+ self.pixbuf = pixbuf
+ else:
+ self.pixbuf = self._read_icon_data(self.filename, self.fill_color, self.stroke_color)
+
+ self.connect('expose-event', self._expose_cb)
+
+ def _expose_cb(self, widget, event):
+ widget.window.draw_pixbuf(None,self.pixbuf, 0, 0, 0, 0)
+ return False
+
+ def _read_icon_data(self, filename, fill_color, stroke_color):
+ icon_file = open(filename, 'r')
+ data = icon_file.read()
+ icon_file.close()
+
+ if fill_color:
+ entity = '<!ENTITY fill_color "%s">' % fill_color
+ data = re.sub('<!ENTITY fill_color .*>', entity, data)
+
+ if stroke_color:
+ entity = '<!ENTITY stroke_color "%s">' % stroke_color
+ data = re.sub('<!ENTITY stroke_color .*>', entity, data)
+
+ self.data_size = len(data)
+ return rsvg.Handle(data=data).get_pixbuf()
+
+ def set_color(self, fill_color, stroke_color):
+ self.fill_color = fill_color
+ self.stroke_color = stroke_color
+ self.pixmap = self._read_icon_data(self.filename, self.fill_color, self.stroke_color)
+ self.queue_draw()
+
+ def set_fill_color(self, fill_color):
+ self.fill_color = fill_color
+ self.pixmap = self._read_icon_data(self.filename, self.fill_color, self.stroke_color)
+ self.queue_draw()
+
+ def get_fill_color(self):
+ return self.fill_color
+
+ def set_stroke_color(self, stroke_color):
+ self.stroke_color = stroke_color
+ self.pixmap = self._read_icon_data(self.filename, self.fill_color, self.stroke_color)
+ self.queue_draw()
+
+ def get_stroke_color(self):
+ return self.stroke_color
+
+ def get_pixbuf(self):
+ return self.pixbuf
+
+ def set_pixbuf(self, pixbuf):
+ self.pixbuf = pixbuf
+ self.queue_draw()
+
+ def set_background(self, background_color):
+ self.background_color = background_color
+ self.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(self.background_color))
+ self.queue_draw()
+ \ No newline at end of file