Changes

Jump to navigation Jump to search
no edit summary
Line 164: Line 164:  
         return taglist
 
         return taglist
   −
=From Pixmap to Pixbuf=
+
'''Replace:'''
 +
 
 +
def getStringFromPixbuf(pixbuf):
 +
    data = [""]
 +
    pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data)
 +
    return base64.b64encode(str(data[0]))
 +
 
 +
 
 +
def _saveDataToBufferCb(buf, data):
 +
    data[0] += buf
 +
    return True
 +
 
 +
'''By:'''
 +
 
 +
def getStringFromPixbuf(pixbuf):
 +
    """Converts a pixbuf in a string."""
 +
   
 +
    # Save_to_bufferv return: (bool, string)
 +
    data = pixbuf.save_to_bufferv('png', [], [])
 +
   
 +
    return base64.b64encode(data[1])
 +
 
 +
'''Replace:'''
 +
 
 +
thumbImg.save(thumbPath, "jpeg", {"quality":"85"} )
 +
 
 +
'''By:'''
 +
 
 +
thumbImg.savev(thumbPath, "jpeg", {"quality":"85"} )
 +
 
 +
'''Replace:'''
 +
 
 +
def load_colored_svg(filename, stroke, fill):
 +
    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 stroke_color "%s">' % stroke
 +
    data = re.sub('<!ENTITY stroke_color .*>', entity, data)
 +
 
 +
    return rsvg.Handle(data=data).get_pixbuf()
 +
 
 +
'''By:'''
 +
 
 +
def load_colored_svg(filename, stroke, fill):
 +
    """Loads an svg, will change the fill and
 +
    stroke colors and returns the pixbuf."""
 +
   
 +
    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 stroke_color "%s">' % stroke
 +
    data = re.sub('<!ENTITY stroke_color .*>', entity, data)
 +
 
 +
    return Rsvg.Handle.new_from_data(data.encode('utf-8')).get_pixbuf()
 +
 
 +
 
 +
'''Not implement:'''
 +
 
 +
super(Record, self).close()
 +
 
 +
'''Due to:''' http://bugs.sugarlabs.org/ticket/4345
 +
 
 
When an application fails and you want to close from the corresponding button occurs:
 
When an application fails and you want to close from the corresponding button occurs:
Traceback (most recent call last):
+
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/sugar3/activity/activity.py", line 890, in _keep_failed_dialog_response_cb
+
File "/usr/lib/python2.7/site-packages/sugar3/activity/activity.py", line 890, in _keep_failed_dialog_response_cb
self.close(skip_save=True)
+
self.close(skip_save=True)
TypeError: close() got an unexpected keyword argument 'skip_save'
+
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.
+
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:==
+
This error is caused by the following:
 
When a class B inherits from class A, and
 
When a class B inherits from class A, and
 
in B is overwritten a function of A,
 
in B is overwritten a function of A,
Line 179: Line 246:  
even when explicitly call function A from B.
 
even when explicitly call function A from B.
   −
 
+
'''Stop using Pixmap instead use Pixbuf:'''
The solution is in using Pixbuf instead of Pixmap:
      
'''Replace:'''
 
'''Replace:'''
Line 195: Line 261:  
'''By:'''
 
'''By:'''
 
     def _generate_image(self, num):
 
     def _generate_image(self, num):
+
 
 
         w = 55
 
         w = 55
 
         h = w
 
         h = w
Line 220: Line 286:  
         ctx.set_source_rgb(0, 0, 0)
 
         ctx.set_source_rgb(0, 0, 0)
 
         ctx.fill()
 
         ctx.fill()
 +
 +
 +
'''New Gst.TagList:'''
 +
 +
'''Replace:'''
 +
 +
        taglist = self._get_tags(constants.TYPE_AUDIO)
 +
 +
        if self._audio_pixbuf:
 +
            pixbuf_b64 = utils.getStringFromPixbuf(self._audio_pixbuf)
 +
            taglist[gst.TAG_EXTENDED_COMMENT] = "coverart=" + pixbuf_b64
 +
 +
        vorbis_enc = audioline.get_by_name('audioVorbisenc')
 +
        vorbis_enc.merge_tags(taglist, gst.TAG_MERGE_REPLACE_ALL)
 +
 +
'''By:'''
 +
 +
        taglist = self._get_tags(constants.TYPE_AUDIO)
 +
       
 +
        if self._audio_pixbuf:
 +
            pixbuf_b64 = utils.getStringFromPixbuf(self._audio_pixbuf)
 +
           
 +
            taglist.add_value(
 +
                Gst.TagMergeMode.REPLACE,
 +
                Gst.TAG_EXTENDED_COMMENT,
 +
                "coverart=" + pixbuf_b64)
 +
               
 +
        vorbis_enc = audioline.get_by_name('audioVorbisenc')
 +
        vorbis_enc.merge_tags(taglist, Gst.TagMergeMode.REPLACE_ALL)
 +
 +
'''Replace:'''
 +
 +
        taglist = self._get_tags(constants.TYPE_VIDEO)
 +
        vorbis_enc = muxline.get_by_name('muxVorbisenc')
 +
        vorbis_enc.merge_tags(taglist, gst.TAG_MERGE_REPLACE_ALL)
 +
 +
'''By:'''
 +
 +
        taglist = self._get_tags(constants.TYPE_VIDEO)
 +
        vorbis_enc = muxline.get_by_name('muxVorbisenc')
 +
        vorbis_enc.merge_tags(taglist, Gst.TagMergeMode.REPLACE_ALL)
 +
 +
'''Replace:'''
 +
 +
    def _get_tags(self, type):
 +
        tl = gst.TagList()
 +
        tl[gst.TAG_ARTIST] = self.model.get_nickname()
 +
        tl[gst.TAG_COMMENT] = "olpc"
 +
        #this is unfortunately, unreliable
 +
        #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()))
 +
        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,
 +
                'name': self.model.get_nickname()}
 +
        return tl
 +
 +
'''By:'''
 +
 +
    def _get_tags(self, type):
 +
       
 +
        taglist = Gst.TagList.new_empty()
 +
       
 +
        taglist.add_value(
 +
            Gst.TagMergeMode.REPLACE,
 +
            Gst.TAG_ARTIST,
 +
            self.model.get_nickname())
 +
           
 +
        taglist.add_value(
 +
            Gst.TagMergeMode.REPLACE,
 +
            Gst.TAG_COMMENT,
 +
            "olpc")
 +
           
 +
        #this is unfortunately, unreliable
 +
        #record.Record.log.debug("self.ca.metadata['title']->" + str(self.ca.metadata['title']) )
 +
 +
        taglist.add_value(
 +
            Gst.TagMergeMode.REPLACE,
 +
            Gst.TAG_ALBUM,
 +
            "olpc") #self.ca.metadata['title']
 +
 +
        taglist.add_value(
 +
            Gst.TagMergeMode.REPLACE,
 +
            Gst.TAG_DATE,
 +
            utils.getDateString(int(time.time())))
 +
           
 +
        stringType = constants.MEDIA_INFO[type]['istr'] #self.ca.metadata['title']
 +
           
 +
        taglist.add_value(
 +
            Gst.TagMergeMode.REPLACE,
 +
            Gst.TAG_TITLE,
 +
            _('%(type)s by %(name)s') % {'type': stringType,
 +
                'name': self.model.get_nickname()})
 +
               
 +
        return taglist
6

edits

Navigation menu