Ticket #2910: 0001-Added-feature-Export-moon-phase-image-to-journal.patch

File 0001-Added-feature-Export-moon-phase-image-to-journal.patch, 8.9 KB (added by cheekujodhpur, 11 years ago)

This is a patch which adds the requested feature to the activity...Tested on Fedora 17 SOAS

  • new file icons/image-saveoff.svg

    From 50220527302c8330af598bffdd43278efd4cab40 Mon Sep 17 00:00:00 2001
    From: Cheeku <Owner@SEBASTIAN.(none)>
    Date: Fri, 7 Dec 2012 20:47:44 +0530
    Subject: [PATCH] Added feature:Export moon phase image to journal
    
    ---
     icons/image-saveoff.svg |  116 +++++++++++++++++++++++++++++++++++++++++++++++
     moon.py                 |   33 +++++++++++++
     2 files changed, 149 insertions(+), 0 deletions(-)
     create mode 100644 icons/image-saveoff.svg
    
    diff --git a/icons/image-saveoff.svg b/icons/image-saveoff.svg
    new file mode 100644
    index 0000000..365f578
    - +  
     1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
     2<!-- Created with Inkscape (http://www.inkscape.org/) -->
     3
     4<svg
     5   xmlns:dc="http://purl.org/dc/elements/1.1/"
     6   xmlns:cc="http://creativecommons.org/ns#"
     7   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     8   xmlns:svg="http://www.w3.org/2000/svg"
     9   xmlns="http://www.w3.org/2000/svg"
     10   version="1.1"
     11   width="55"
     12   height="55"
     13   viewBox="0 0 55 55"
     14   id="svg2"
     15   xml:space="preserve"><metadata
     16     id="metadata25"><rdf:RDF><cc:Work
     17         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
     18           rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
     19     id="defs33">
     20       
     21       
     22       
     23
     24 
     25 
     26
     27 
     28   
     29   
     30   
     31   
     32
     33       
     34
     35               
     36               
     37               
     38               
     39               
     40               
     41               
     42               
     43               
     44        </defs><g
     45     transform="matrix(0.55205508,0,0,0.55205508,77.118464,18.235971)"
     46     id="g4382"><g
     47       transform="translate(-80.093659,12.220029)"
     48       id="g4308"
     49       style="fill:none;stroke:#ffffff;stroke-opacity:1">
     50                        <g
     51   id="g4310"
     52   style="fill:none;stroke:#ffffff;stroke-opacity:1">
     53                                <path
     54   d="m 6.736,49.002 h 24.52 c 2.225,0 3.439,-1.447 3.439,-3.441 v -27.28 c 0,-1.73 -1.732,-3.441 -3.439,-3.441 h -4.389"
     55   id="path4312"
     56   style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" />
     57                        </g>
     58                </g><g
     59       transform="translate(-80.093659,12.220029)"
     60       id="g4314"
     61       style="fill:none;stroke:#ffffff;stroke-opacity:1">
     62                        <g
     63   id="g4316"
     64   style="fill:none;stroke:#ffffff;stroke-opacity:1">
     65                                <path
     66   d="m 26.867,38.592 c 0,1.836 -1.345,3.201 -3.441,4.047 L 6.736,49.002 V 14.84 l 16.69,-8.599 c 2.228,-0.394 3.441,0.84 3.441,2.834 v 29.517 z"
     67   id="path4318"
     68   style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" />
     69                        </g>
     70                </g><path
     71       d="m -70.669659,54.827029 c 0,0 -1.351,-0.543 -2.702,-0.543 -1.351,0 -2.703,0.543 -2.703,0.543"
     72       id="path4320"
     73       style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
     74       d="m -70.669659,44.226029 c 0,0 -1.239,-0.543 -2.815,-0.543 -1.577,0 -2.59,0.543 -2.59,0.543"
     75       id="path4322"
     76       style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><path
     77       d="m -70.669659,33.898029 c 0,0 -1.125,-0.544 -2.927,-0.544 -1.802,0 -2.478,0.544 -2.478,0.544"
     78       id="path4324"
     79       style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /><line
     80       style="fill:none;stroke:#ffffff;stroke-width:2.25;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
     81       x1="-66.884659"
     82       x2="-66.884659"
     83       y1="58.753029"
     84       y2="23.725029"
     85       id="line4326" /></g><g
     86     transform="matrix(1.1623273,0,0,1.1623273,-14.422024,-12.63995)"
     87     id="g3882"
     88     style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;display:inline"><g
     89       id="g3884"
     90       style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"><polygon
     91         points="43.041,21.577 35.281,13.812 15.204,13.812 15.204,35.189 43.041,35.189 "
     92         id="polygon3886"
     93         style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><polyline
     94         id="polyline3888"
     95         points="35.281,13.812 35.281,21.577 43.041,21.577    "
     96         style="fill:none;stroke:#ffffff;stroke-width:2.15085721;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g><path
     97     d="m 19.426691,12.275117 c -4.727185,0 -8.666312,4.714399 -8.666312,4.714399 0,0 3.939127,4.737646 8.666312,4.735322 4.729509,-0.0046 8.668637,-4.739971 8.668637,-4.739971 0,0 -3.939128,-4.713237 -8.668637,-4.70975 z m 0,8.039818 c -1.830666,0 -3.314958,-1.484292 -3.314958,-3.31612 0,-1.827179 1.484292,-3.314958 3.314958,-3.314958 1.828341,0 3.312632,1.487779 3.312632,3.314958 0,1.831828 -1.484291,3.31612 -3.312632,3.31612 z"
     98     id="path3890"
     99     style="fill:#ffffff;fill-opacity:1;stroke:none;display:inline" /><circle
     100     cx="29.207001"
     101     cy="25.863001"
     102     r="1.294"
     103     transform="matrix(1.1623273,0,0,1.1623273,-14.520241,-13.061294)"
     104     id="circle3892"
     105     style="fill:#ffffff;fill-opacity:1;stroke:none;display:inline" /><g
     106     transform="matrix(1,0,0,-1,-24.850339,47.707501)"
     107     id="g4770"><g
     108       transform="translate(34.0803,-1006.42)"
     109       id="g4772"><polyline
     110         transform="matrix(-0.469241,0.469241,-0.469241,-0.469241,66.2906,1019.03)"
     111         style="fill:none;stroke:#ffffff;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round"
     112         points="51.562,15.306 41.17,16.188 42.053,5.794"
     113         id="polyline4774" /><path
     114         d="m 39.363241,1033.1291 -0.05636,9.9115 -8.750608,0.067"
     115         id="path4776"
     116         style="fill:none;stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g></svg>
     117 No newline at end of file
  • moon.py

    diff --git a/moon.py b/moon.py
    index 4ab5840..ab59e5b 100755
    a b network connection is needed. 
    3232import gtk
    3333import gobject
    3434from sugar.activity import activity
     35from sugar import profile
     36from sugar.datastore import datastore
    3537from sugar.graphics.toggletoolbutton import ToggleToolButton
     38from sugar.graphics.toolbutton import ToolButton
    3639from gettext import gettext as _
    3740import math
    3841import time
    class MoonActivity(activity.Activity): 
    100103            self.toggle_hemisphere_handler_id = self.toggle_hemisphere_button.connect('clicked', self.toggle_hemisphere_clicked)
    101104            toolbar_box.toolbar.insert(self.toggle_hemisphere_button, -1)
    102105            self.toggle_hemisphere_button.show()
     106            self.save_image_button = ToolButton('image-saveoff')
     107            self.save_image_button.set_tooltip(_("Save As Image"))
     108            self.save_image_button.connect('clicked',self.save_image)
     109            toolbar_box.toolbar.insert(self.save_image_button, -1)
     110            self.save_image_button.show()
    103111            separator = gtk.SeparatorToolItem()
    104112            separator.props.draw = False
    105113            separator.set_expand(True)
    class MoonActivity(activity.Activity): 
    126134            self.toggle_hemisphere_handler_id = self.toggle_hemisphere_button.connect('clicked', self.toggle_hemisphere_clicked)
    127135            view_tool_bar.insert(self.toggle_hemisphere_button, -1)
    128136            self.toggle_hemisphere_button.show()
     137            self.save_image_button = ToolButton('image-saveoff')
     138            self.save_image_button.set_tooltip(_("Save As Image"))
     139            self.save_image_button.connect('clicked',self.save_image)
     140            toolbar_box.toolbar.insert(self.save_image_button, -1)
     141            self.save_image_button.show()
    129142            view_tool_bar.show()
    130143            toolbox.add_toolbar(_('View'), view_tool_bar)
    131144            self.set_toolbox(toolbox)
    class MoonActivity(activity.Activity): 
    273286        gobject.source_remove(self.update_moon_image_timeout)
    274287        self.update_moon_image_view()
    275288
     289    def save_image(self, button=None):
     290        """ Save current phase as image"""
     291        width, height = self.get_size()
     292        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
     293                                int(width / 1.70), height - 55)
     294        screenshot = pixbuf.get_from_drawable(
     295            self.window, self.get_colormap(), width - int(width / 1.70),
     296            55, 0, 0, int(width / 1.70), height - 55)
     297        image_path = os.path.join(activity.get_activity_root(),
     298                                  'instance', 'moon.png')
     299        screenshot.save(image_path,'png')
     300        entry = datastore.create()
     301        entry.metadata['title'] = "%s %s" % \
     302            (self.metadata['title'], _("Image"))
     303        entry.metadata['icon-color'] = profile.get_color().to_string()
     304        entry.metadata['mime_type'] = 'image/png'
     305        entry.set_file_path(image_path)
     306        datastore.write(entry)
     307        entry.destroy()
     308
    276309    def update_text_information_view(self):
    277310        """Generate Moon data and update text based information view.
    278311        """