This was written by Lawrence. Posted on Saturday, December 3, 2005, at 1:59 am. Filed under Everything. Tagged python. Bookmark the permalink. Follow comments here with the RSS feed. Both comments and trackbacks are currently closed.
http://www.pygtk.org Rafael Villar Burke
Nice article!. This article is now included (as a link to your blog) in the articles section in the pygtk.org website. We’d like to have a copy of it too in our site just in case your blog changes its address or it gets unavaliable. Would you mind it?.
Thanks for your work and letting others enjoy it.
Rafael
http://www.rittau.org/ Sebastian Rittau
Great to see that you converted this tutorial to Python. Many thanks! Here are some questions/suggestions, though:
def init(self):
gtk.DrawingArea.init(self)
I would recommend to use the super operator:
def init(self):
super(EggClockFace, self).init()
rect = self.get_allocation()
x = rect.x + rect.width / 2
y = rect.y + rect.height / 2
It’s probably better to make sure (for now) that floating point numbers are used for the division:
rect = self.get_allocation()
x = rect.x + rect.width / 2.0
y = rect.y + rect.height / 2.0
Or if you want to force an integer division:
rect = self.get_allocation()
x = rect.x + rect.width // 2
y = rect.y + rect.height // 2
Well, self.draw is actually an inherited method from gtk.Widget. I would recommend to rename that method to draw_face or something similar.
Also, why do you store the context in a member?
http://oluyede.org/blog Lawrence
Thanks for the reply Sebastian!
1 – there’s no compelling reason to use super() instead of the old method in a single inheritance situation (anyway I corrected)
2 – ok for the floating point division
3 – draw() is an explicit override
4 – self.context is just a matter of style, I wrote the conversion quickly and this should be also a mistake
http://riffraff.blogsome.com riffraff
I know you were trying to redo this in ruby..
I got it working with this:
require ‘cairo’
require ‘gtk2′
class EggClockFace
by installing first rcairo-1.0.0 and then ruby-gnome2-0.14.1 from source on ubuntu breezy (and after installing a boatload of xyz-dev packages with apt). The code could be more rubyified, anyway, but my box is dead ATM.
Pingback: PDI^2 :: Ruby-GNOME2, i binding dimenticati :: January :: 2006