Changes

no edit summary
Line 1: Line 1: −
= Some changes =
+
'''Replace:'''
 +
 
 +
def getStringFromPixbuf(pixbuf):
 +
    data = [""]
 +
    pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data)
 +
    return base64.b64encode(str(data[0]))
   −
'''Replace:'''
     −
def getStringFromPixbuf(pixbuf):
+
def _saveDataToBufferCb(buf, data):
    data = [""]
+
    data[0] += buf
    pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data)
+
    return True
    return base64.b64encode(str(data[0]))
  −
  −
  −
def _saveDataToBufferCb(buf, data):
  −
    data[0] += buf
  −
    return True
     −
'''With:'''
+
'''By:'''
   −
def getStringFromPixbuf(pixbuf):
+
def getStringFromPixbuf(pixbuf):
    """Converts a pixbuf in a string."""
+
    """Converts a pixbuf in a string."""
 
+
   
    # Save_to_bufferv return: (bool, string)
+
    # Save_to_bufferv return: (bool, string)
    data = pixbuf.save_to_bufferv('png', [], [])
+
    data = pixbuf.save_to_bufferv('png', [], [])
 
      
 
      
    return base64.b64encode(data[1])
+
    return base64.b64encode(data[1])
    
'''Replace:'''
 
'''Replace:'''
   −
thumbImg.save(thumbPath, "jpeg", {"quality":"85"} )
+
thumbImg.save(thumbPath, "jpeg", {"quality":"85"} )  
   −
'''With:'''
+
'''By:'''
   −
thumbImg.savev(thumbPath, "jpeg", {"quality":"85"} )
+
thumbImg.savev(thumbPath, "jpeg", {"quality":"85"} )
    
'''Replace:'''
 
'''Replace:'''
   −
def load_colored_svg(filename, stroke, fill):
+
def load_colored_svg(filename, stroke, fill):
    path = os.path.join(constants.GFX_PATH, filename)
+
 
    data = open(path, 'r').read()
+
    path = os.path.join(constants.GFX_PATH, filename)
+
    data = open(path, 'r').read()
    entity = '<!ENTITY fill_color "%s">' % fill
+
 
    data = re.sub('<!ENTITY fill_color .*>', entity, data)
+
    entity = '<!ENTITY fill_color "%s">' % fill
+
    data = re.sub('<!ENTITY fill_color .*>', entity, data)
    entity = '<!ENTITY stroke_color "%s">' % stroke
+
 
    data = re.sub('<!ENTITY stroke_color .*>', entity, data)
+
    entity = '<!ENTITY stroke_color "%s">' % stroke
+
    data = re.sub('<!ENTITY stroke_color .*>', entity, data)
    """return rsvg.Handle(data=data).get_pixbuf()"""
+
 
 +
    return rsvg.Handle(data=data).get_pixbuf()
   −
'''With:'''
+
'''By:'''
   −
def load_colored_svg(filename, stroke, fill):
+
def load_colored_svg(filename, stroke, fill):
    """Loads an svg, will change the fill and
+
    """Loads an svg, will change the fill and
    stroke colors and returns the pixbuf."""
+
    stroke colors and returns the pixbuf."""
 
      
 
      
    path = os.path.join(constants.GFX_PATH, filename)
+
    path = os.path.join(constants.GFX_PATH, filename)
    data = open(path, 'r').read()
+
    data = open(path, 'r').read()
+
 
    entity = '<!ENTITY fill_color "%s">' % fill
+
    entity = '<!ENTITY fill_color "%s">' % fill
    data = re.sub('<!ENTITY fill_color .*>', entity, data)
+
    data = re.sub('<!ENTITY fill_color .*>', entity, data)
+
 
    entity = '<!ENTITY stroke_color "%s">' % stroke
+
    entity = '<!ENTITY stroke_color "%s">' % stroke
    data = re.sub('<!ENTITY stroke_color .*>', entity, data)
+
    data = re.sub('<!ENTITY stroke_color .*>', entity, data)
+
 
    """return Rsvg.Handle.new_from_data(data.encode('utf-8')).get_pixbuf()"""
+
    return Rsvg.Handle.new_from_data(data.encode('utf-8')).get_pixbuf()
    
'''Not implement:'''
 
'''Not implement:'''
   −
super(Record, self).close()
+
super(Record, self).close()
 +
 
 +
'''Due to:''' [http://bugs.sugarlabs.org/ticket/4345]
   −
Due to: [http://bugs.sugarlabs.org/ticket/4345 SL#4345]
+
When an application fails and you want to close from the corresponding button occurs:
   −
New Gst.TagList:
+
Traceback (most recent call last):
 +
File "/usr/lib/python2.7/site-packages/sugar3/activity/activity.py", line 890, in _keep_failed_dialog_response_cb
 +
self.close(skip_save=True)
 +
TypeError: close() got an unexpected keyword argument 'skip_save'
 +
And the activity is not closed, nor can restart sugar as alert reappears again and again, you need to stop.
 +
 
 +
This error is caused by the following:
 +
When a class B inherits from class A, and
 +
in B is overwritten a function of A,
 +
A function is no longer running,
 +
but instead runs the function of the class B,
 +
even when explicitly call function A from B.
 +
 
 +
'''Stop using Pixmap instead use Pixbuf:'''
    
'''Replace:'''
 
'''Replace:'''
 +
 +
    def _generate_image(self, num):
 +
        w = 55
 +
        h = w
 +
        pixmap = gdk.Pixmap(self.get_window(), w, h, -1)
 +
        ctx = pixmap.cairo_create()
 +
        ctx.rectangle(0, 0, w, h)
 +
        ctx.set_source_rgb(0, 0, 0)
 +
        ctx.fill()
 +
 +
'''By:'''
 +
    def _generate_image(self, num):
 +
 +
        w = 55
 +
        h = w
 +
       
 +
        x, y = self.get_property('window').get_position()
 +
        rect = self.get_allocation()
 +
        width, height = rect.width, rect.height
 +
     
 +
        thumb_surface = Gdk.Window.create_similar_surface(
 +
            self.get_property('window'),
 +
            cairo.CONTENT_COLOR,
 +
            width, height)
 +
     
 +
        ctx = cairo.Context(thumb_surface)
 +
       
 +
        Gdk.cairo_set_source_window(
 +
            cairo_context,
 +
            self.get_property('window'),
 +
            x, y)
 +
           
 +
        ctx.paint()
 +
       
 +
        ctx.rectangle(x, y, w, h)
 +
        ctx.set_source_rgb(0, 0, 0)
 +
        ctx.fill()
 +
 +
'''New Gst.TagList:
 +
 +
Replace:'''
    
         taglist = self._get_tags(constants.TYPE_AUDIO)
 
         taglist = self._get_tags(constants.TYPE_AUDIO)
Line 81: Line 136:  
         vorbis_enc.merge_tags(taglist, gst.TAG_MERGE_REPLACE_ALL)
 
         vorbis_enc.merge_tags(taglist, gst.TAG_MERGE_REPLACE_ALL)
   −
'''With:'''
+
'''By:'''
    
         taglist = self._get_tags(constants.TYPE_AUDIO)
 
         taglist = self._get_tags(constants.TYPE_AUDIO)
Line 102: Line 157:  
         vorbis_enc.merge_tags(taglist, gst.TAG_MERGE_REPLACE_ALL)
 
         vorbis_enc.merge_tags(taglist, gst.TAG_MERGE_REPLACE_ALL)
   −
'''With:'''
+
'''By:'''
    
         taglist = self._get_tags(constants.TYPE_VIDEO)
 
         taglist = self._get_tags(constants.TYPE_VIDEO)
Line 111: Line 166:     
     def _get_tags(self, type):
 
     def _get_tags(self, type):
 +
 
         tl = gst.TagList()
 
         tl = gst.TagList()
 
         tl[gst.TAG_ARTIST] = self.model.get_nickname()
 
         tl[gst.TAG_ARTIST] = self.model.get_nickname()
 
         tl[gst.TAG_COMMENT] = "olpc"
 
         tl[gst.TAG_COMMENT] = "olpc"
        #this is unfortunately, unreliable
+
         tl[gst.TAG_ALBUM] = "olpc"
        #record.Record.log.debug("self.ca.metadata['title']->" + str(self.ca.metadata['title']) )
  −
         tl[gst.TAG_ALBUM] = "olpc" #self.ca.metadata['title']
   
         tl[gst.TAG_DATE] = utils.getDateString(int(time.time()))
 
         tl[gst.TAG_DATE] = utils.getDateString(int(time.time()))
 
         stringType = constants.MEDIA_INFO[type]['istr']
 
         stringType = constants.MEDIA_INFO[type]['istr']
 
          
 
          
        # Translators: photo by photographer, e.g. "Photo by Mary"
   
         tl[gst.TAG_TITLE] = _('%(type)s by %(name)s') % {'type': stringType,
 
         tl[gst.TAG_TITLE] = _('%(type)s by %(name)s') % {'type': stringType,
 
                 'name': self.model.get_nickname()}
 
                 'name': self.model.get_nickname()}
 
         return tl
 
         return tl
   −
'''With:'''
+
'''By:'''
    
     def _get_tags(self, type):
 
     def _get_tags(self, type):
Line 140: Line 193:  
             Gst.TAG_COMMENT,
 
             Gst.TAG_COMMENT,
 
             "olpc")
 
             "olpc")
           
  −
        #this is unfortunately, unreliable
  −
        #record.Record.log.debug("self.ca.metadata['title']->" + str(self.ca.metadata['title']) )
      
         taglist.add_value(
 
         taglist.add_value(
Line 154: Line 204:  
             utils.getDateString(int(time.time())))
 
             utils.getDateString(int(time.time())))
 
              
 
              
         stringType = constants.MEDIA_INFO[type]['istr'] #self.ca.metadata['title']
+
         stringType = constants.MEDIA_INFO[type]['istr']
 
              
 
              
 
         taglist.add_value(
 
         taglist.add_value(
Line 164: Line 214:  
         return taglist
 
         return taglist
   −
=From Pixmap to Pixbuf=
  −
When an application fails and you want to close from the corresponding button occurs:
  −
Traceback (most recent call last):
  −
File "/usr/lib/python2.7/site-packages/sugar3/activity/activity.py", line 890, in _keep_failed_dialog_response_cb
  −
self.close(skip_save=True)
  −
TypeError: close() got an unexpected keyword argument 'skip_save'
  −
And the activity is not closed, nor can restart sugar as alert reappears again and again, you need to stop.
     −
==This error is caused because:==
+
GObject.get_data() and set_data() are deprecated. Use normal Python attributes instead
When a class B inherits from class A, and
+
button.set_data('handler-ids', (clicked_handler, remove_handler, clipboard_handler))
in B is overwritten a function of A,
+
 
A function is no longer running,
+
 
but instead runs the function of the class B,
+
'''No joint implementation:'''
even when explicitly call function A from B.
+
 
 +
self.connect('size_allocate', self._size_allocate_cb)
 +
def _size_allocate_cb(self, widget, requisition):
 +
. . .
 +
 
 +
and
    +
def do_size_allocate(self, allocation):
 +
. . .
   −
The solution is in using Pixbuf instead of Pixmap:
      
'''Replace:'''
 
'''Replace:'''
   −
    def _generate_image(self, num):
+
taglist.add_value(  
        w = 55
+
      Gst.TagMergeMode.REPLACE,  
        h = w
+
      Gst.TAG_DATE,
        pixmap = gdk.Pixmap(self.get_window(), w, h, -1)
+
      utils.getDateString(int(time.time())))
        ctx = pixmap.cairo_create()
+
 
        ctx.rectangle(0, 0, w, h)
+
def getDateString( when ):
        ctx.set_source_rgb(0, 0, 0)
+
   
        ctx.fill()
+
    return strftime( "%c", time.localtime(when) )
    
'''By:'''
 
'''By:'''
    def _generate_image(self, num):
+
 
 +
datetime = GLib.DateTime.new_now_local()
 +
date = GLib.Date()
 +
date.set_day(datetime.get_day_of_month())
 +
date.set_month(datetime.get_month())
 +
date.set_year(datetime.get_year())
 
   
 
   
        w = 55
+
taglist.add_value(
        h = w
+
      Gst.TagMergeMode.REPLACE,
       
+
      Gst.TAG_DATE,
        x, y = self.get_property('window').get_position()
+
      date)
        rect = self.get_allocation()
  −
        width, height = rect.width, rect.height
  −
     
  −
        thumb_surface = Gdk.Window.create_similar_surface(
  −
            self.get_property('window'),
  −
            cairo.CONTENT_COLOR,
  −
            width, height)
  −
     
  −
        ctx = cairo.Context(thumb_surface)
  −
       
  −
        Gdk.cairo_set_source_window(
  −
            cairo_context,
  −
            self.get_property('window'),
  −
            x, y)
  −
           
  −
        ctx.paint()
  −
       
  −
        ctx.rectangle(x, y, w, h)
  −
        ctx.set_source_rgb(0, 0, 0)
  −
        ctx.fill()
 
6

edits