
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