Friday, January 8, 2010

photobomb can has lolz

Tonight's Photobomb Feature: Text

Tonight I add the ability to add text. You can also change the set the font and color. You can change the size just by growing the size of the object with the size buttons I added initially.

I also added the ability to edit items after you've added them. That is you can change the color of most objects, and the width of your ink strokes. You can't edit the text once you've added it, but I suppose I could add the pretty easily as a feature some night.

Tonight I wrote the first piece of code that suggested extending goocanvas namespace types rather than writing the program in a more procedural style. When changing colors, for most objects, you want to change the fill_color property. But for ink, you want to change the stroke_color property. So I added some code to detect the type and set the right property as needed.

       if type(self.selected_item) == goocanvas.Path:
self.selected_item.set_property("stroke_color",self.__ink_color)
else:
self.selected_item.set_property("fill_color",self.__ink_color)


Typically, when I find myself detecting types and branching, it's not long before I start sub-classing instead. However, when I look at the goocanvas reference it seems that there are limited objects, and perhaps a procedural style will hold out.

No comments:

Post a Comment