Description: This is a demonstration screenlet, not for use by normal users. The code is commented extensively to help developers understand how to code screenlets, and to provide them with an example of screenlet that has updating text on a simple background. Hopefully this demonstration screenlet will allow you to understand how a screenlet is coded and allow you to code desklets of your own to better Gnome.Last changelog:
*Fixed Possible Memory Leak in draw_text() definition
**Changed the draw_text() definition to accept values for font type and the width of the "drawing area"
self.draw_text(ctx, '<b>' + self.mytext + '</b>', 10, 10, 10)
where did you find this? is it on the latest bzr? what does the 10,10,10 represent?
nice job
Whise,
No, it isn't part of the bzr, I just have it defined below:
=======================================
# This is a user defined function that will tell python how to draw the text onto the background
def draw_text(self, ctx, value, x, y, size):
=======================================
The 10,10,10 represents the x coordinate, y coordinate, and the font size. Therefore, I decided to have the drawing position start 10 pixels from left of the background and 10 pixels down from the top of the background, and I decided to use size 10 font. Thanks for asking for clarification.
nevermind i just saw you def...
you wrote it your self?
i should warn you that you shouldnt make people use yor funtion because of several things
you should check out this topic
http://forum.compiz-fusion.org/showthread.php?t=3576&highlight=memory+leak
because in the way you draw your text there is a memory leak , that can become very severe so i advise you to read the topic
also you should allow people to select the width of the text area pago allows you to do that
Whise,
Great catch - I hadn't thought about this. I fixed that problem in the draw_text() def, but I didn't add the option to change the text width yet. I'll add that in when I get a chance - Thanks for the pointer.
could you also implement the font option? that would be nice, if you implement those 2 i think you should contact rix and ask him about implementing the draw_text function in the screenlets core, making the life easyier for devs
Whise,
I've changed the draw_text() definition to be as follows:
=====================================
def draw_text(self, ctx, value, x, y, width, font, size):
=====================================
The added options are 'width' and 'font', which are variables representing the width of the drawing area and the font type, respectively. Please tell me if there is anything else that you would like me to modify.
seems really good now , if you can only add the option to set a default font in case the font doesnt get specified (maybe sans), after that maybe you should contact RYX and see if he can get this funtion into the core seems really helpfull
nice job
Ratings & Comments
9 Comments
self.draw_text(ctx, '<b>' + self.mytext + '</b>', 10, 10, 10) where did you find this? is it on the latest bzr? what does the 10,10,10 represent? nice job
Whise, No, it isn't part of the bzr, I just have it defined below: ======================================= # This is a user defined function that will tell python how to draw the text onto the background def draw_text(self, ctx, value, x, y, size): ======================================= The 10,10,10 represents the x coordinate, y coordinate, and the font size. Therefore, I decided to have the drawing position start 10 pixels from left of the background and 10 pixels down from the top of the background, and I decided to use size 10 font. Thanks for asking for clarification.
nevermind i just saw you def... you wrote it your self? i should warn you that you shouldnt make people use yor funtion because of several things you should check out this topic http://forum.compiz-fusion.org/showthread.php?t=3576&highlight=memory+leak because in the way you draw your text there is a memory leak , that can become very severe so i advise you to read the topic also you should allow people to select the width of the text area pago allows you to do that
sorry for the spelling :)
Whise, Great catch - I hadn't thought about this. I fixed that problem in the draw_text() def, but I didn't add the option to change the text width yet. I'll add that in when I get a chance - Thanks for the pointer.
could you also implement the font option? that would be nice, if you implement those 2 i think you should contact rix and ask him about implementing the draw_text function in the screenlets core, making the life easyier for devs
Whise, I've changed the draw_text() definition to be as follows: ===================================== def draw_text(self, ctx, value, x, y, width, font, size): ===================================== The added options are 'width' and 'font', which are variables representing the width of the drawing area and the font type, respectively. Please tell me if there is anything else that you would like me to modify.
seems really good now , if you can only add the option to set a default font in case the font doesnt get specified (maybe sans), after that maybe you should contact RYX and see if he can get this funtion into the core seems really helpfull nice job
ohh and i forgot , also there is need for the option for text color , maybe that should be specified outside the function