Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJRG 2 <jrg2@ubuntu.(none)>2013-12-26 14:18:54 (GMT)
committer JRG 2 <jrg2@ubuntu.(none)>2013-12-26 14:18:54 (GMT)
commitbea48d50d55810ad5617d8f8a37ed789e3b31e01 (patch)
tree10d7c43dea0c1de3ae2c453d351d4782cb33a72d
parente69cc6e521c5fb13c148e0761f2257a619aeeb09 (diff)
Export iconexport_icons
-rw-r--r--TurtleArt/tacanvas.py7
-rw-r--r--TurtleArt/tawindow.py67
-rw-r--r--TurtleArtActivity.py20
3 files changed, 94 insertions, 0 deletions
diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py
index f37a3a4..753fd32 100644
--- a/TurtleArt/tacanvas.py
+++ b/TurtleArt/tacanvas.py
@@ -128,9 +128,14 @@ class TurtleGraphics:
else:
svg_surface = cairo.SVGSurface(
TMP_SVG_PATH, self.width, self.height)
+ self.svg_surface = svg_surface
self.cr_svg = cairo.Context(svg_surface)
self.cr_svg.set_line_cap(1) # Set the line cap to be round
+ def get_square_svg_path(self):
+ return os.path.join(get_path(self.turtle_window.activity, 'instance'),
+ 'output.svg')
+
def fill_polygon(self, poly_points):
''' Draw the polygon... '''
def _fill_polygon(cr, poly_points):
@@ -416,6 +421,8 @@ class TurtleGraphics:
def svg_close(self):
''' Close current SVG graphic '''
self.cr_svg.show_page()
+ self.svg_surface.flush()
+ self.svg_surface.finish()
def svg_reset(self):
''' Reset svg flags '''
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index 4584726..d8bdb6d 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -4642,6 +4642,73 @@ before making changes to your program'))
save_picture(self.canvas, image_file)
return ta_file, image_file
+ def save_as_icon(self, name=''):
+ from sugariconify import SugarIconify
+
+ icon = SugarIconify()
+ path = self.canvas.get_square_svg_path()
+ self.square_svg(path)
+
+ lst_path = path.split('/')
+ icon.set_use_default_colors(True)
+ output_path = '/'.join(lst_path[:-1])
+
+ icon.set_output_path(output_path)
+ icon.set_stroke_color('rgb(0%,0%,0%)')
+ icon.set_fill_color('rgb(99.215686%,99.215686%,99.215686%)')
+ icon.iconify(path)
+
+ file_name_lst = lst_path[-1].split('.')
+ file_name = '.'.join(file_name_lst[:-1]) + '.sugar.svg'
+ lst_path[-1] = file_name
+ path = '/'.join(lst_path)
+
+ if self.running_sugar:
+ from sugar.datastore import datastore
+ from sugar import profile
+
+ dsobject = datastore.create()
+ if len(name) == 0:
+ dsobject.metadata['title'] = '%s %s' % \
+ (self.activity.metadata['title'], _('icon'))
+ else:
+ dsobject.metadata['title'] = name
+ dsobject.metadata['icon-color'] = profile.get_color().to_string()
+ dsobject.metadata['mime_type'] = 'image/svg+xml'
+ dsobject.set_file_path(path)
+ datastore.write(dsobject)
+ dsobject.destroy()
+ self.saved_pictures.append((dsobject.object_id, True))
+ os.remove(path)
+
+ def write_svg_operation(self):
+ self.canvas.svg_close()
+ self.canvas.svg_reset()
+
+ def square_svg(self, path):
+ from xml.dom import minidom
+ fil = open(path, 'r')
+ svg_text = fil.read()
+ fil.close()
+ svg_xml = minidom.parseString(svg_text)
+ svg_element = svg_xml.getElementsByTagName('svg')[0]
+ width = int(svg_element.getAttribute('width')[:-2])
+ height = int(svg_element.getAttribute('height')[:-2])
+ size = 0
+
+ if height > width:
+ size = width
+ else:
+ size = height
+ svg_element.setAttribute('width', str(size) + 'pt')
+ svg_element.setAttribute('height', str(size) + 'pt')
+ view_box = str(int(size/2)) + ' 0 ' + str(size) + ' ' + str(size)
+ svg_element.setAttribute('viewBox', view_box)
+ svg_text = svg_xml.toxml()
+ fil = open(path, 'w+')
+ fil.write(svg_text)
+ fil.close()
+
def save_as_image(self, name='', svg=False):
''' Grab the current canvas and save it. '''
if svg:
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index f6b94ca..0cc907c 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -335,6 +335,20 @@ class TurtleArtActivity(activity.Activity):
self.tw.load_python_code_from_file(fname=None, add_new_block=True)
gobject.timeout_add(250, self.load_python.set_icon, 'pippy-openoff')
+ def do_save_as_icon_cb(self, button):
+ _logger.debug('saving icon to journal')
+ if hasattr(self, 'get_window'):
+ if hasattr(self.get_window(), 'get_cursor'):
+ self._old_cursor = self.get_window().get_cursor()
+ self.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
+ gobject.timeout_add(250, self.__save_as_icon)
+
+ def __save_as_icon(self):
+ self.tw.write_svg_operation()
+ self.tw.save_as_icon()
+ if hasattr(self, 'get_window'):
+ self.get_window().set_cursor(self._old_cursor)
+
def do_save_as_image_cb(self, button):
''' Save the canvas to the Journal. '''
self.save_as_image.set_icon('image-saveon')
@@ -1086,6 +1100,9 @@ class TurtleArtActivity(activity.Activity):
self.keep_button2, self.keep_label2 = self._add_button_and_label(
'filesaveoff', _('Save snapshot'), self.do_keep_cb,
None, button_box)
+ self.save_as_icon = self._add_button_and_label(
+ 'image-saveoff', _('Save as sugar icon'), self.do_save_as_icon_cb,
+ None, button_box)
load_button = self._add_button(
'load', _('Load'), self._save_load_palette_cb,
@@ -1133,6 +1150,9 @@ class TurtleArtActivity(activity.Activity):
toolbar)
self.keep_button = self._add_button(
'filesaveoff', _('Save snapshot'), self.do_keep_cb, toolbar)
+ self.save_as_icon = self._add_button(
+ 'image-saveoff', _('Save as sugar icon'), self.do_save_as_icon_cb,
+ toolbar)
self.load_ta_project = self._add_button(
'load-from-journal', _('Add project'),
self.do_load_ta_project_cb, toolbar)