Features/GTK3/Porting/Record: Difference between revisions

Created page with "'''Replace:''' def getStringFromPixbuf(pixbuf): data = [""] pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data) return base64.b64encode(str(data[0])) ..."
 
Francis (talk | contribs)
No edit summary
Line 1: Line 1:
= Some changes =
'''Replace:'''
'''Replace:'''


def getStringFromPixbuf(pixbuf):
def getStringFromPixbuf(pixbuf):
    data = [""]
    data = [""]
    pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data)
    pixbuf.save_to_callback(_saveDataToBufferCb, "png", {}, data)
    return base64.b64encode(str(data[0]))
    return base64.b64encode(str(data[0]))
 
 
def _saveDataToBufferCb(buf, data):
def _saveDataToBufferCb(buf, data):
    data[0] += buf
    data[0] += buf
    return True
    return True


'''By:'''
'''With:'''


def getStringFromPixbuf(pixbuf):
def getStringFromPixbuf(pixbuf):
    """Converts a pixbuf in a string."""
    """Converts a pixbuf in a string."""
 
    # Save_to_bufferv return: (bool, string)
    data = pixbuf.save_to_bufferv('png', [], [])
      
      
    # Save_to_bufferv return: (bool, string)
    return base64.b64encode(data[1])
    data = pixbuf.save_to_bufferv('png', [], [])
   
    return base64.b64encode(data[1])


'''Replace:'''
'''Replace:'''


thumbImg.save(thumbPath, "jpeg", {"quality":"85"} )
thumbImg.save(thumbPath, "jpeg", {"quality":"85"} )


'''By:'''
'''With:'''


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)
    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(data=data).get_pixbuf()'''
    """return rsvg.Handle(data=data).get_pixbuf()"""


'''By:'''
'''With:'''


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:'''
=From Pixmap to Pixbuf=
Traceback (most recent call last):
When an application fails and you want to close from the corresponding button occurs:
File "/usr/lib/python2.7/site-packages/sugar3/activity/activity.py", line 890, in _keep_failed_dialog_response_cb
Traceback (most recent call last):
self.close(skip_save=True)
File "/usr/lib/python2.7/site-packages/sugar3/activity/activity.py", line 890, in _keep_failed_dialog_response_cb
TypeError: close() got an unexpected keyword argument 'skip_save'
self.close(skip_save=True)
And the activity is not closed, nor can restart sugar as alert reappears again and again, you need to stop.
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:'''
==This error is caused because:==
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 81: Line 84:




'''Stop using Pixmap instead use Pixbuf:'''
The solution is in using Pixbuf instead of Pixmap:


'''Replace:'''
'''Replace:'''
Line 96: Line 99:
'''By:'''
'''By:'''
     def _generate_image(self, num):
     def _generate_image(self, num):
 
         w = 55
         w = 55
         h = w
         h = w