in a windowEdit
The clock-face tutorial is a good starting point to see how you can use cairo to draw stuff. It shows how to use various drawing commands directly on your GTK+ window. You can also have a look at the second part of the clock-face tutorial.
in a widgetEdit
The following incomplete code can be used with the clock-face code to draw the clock face in a widget, next to some buttons. Our first step is to create the object that will do the cairo drawing. The code for this class is in the clock-face tutorial. The size request is mysterious to me.
def main(): clock = EggClockFace() clock.set_size_request(110,50)
The next step is to create a bunch of widgets, but don't knit them together.
window = gtk.Window() hbox = gtk.HBox() but1 = gtk.Button("What's up?") but2 = gtk.Button("Dammit") ebox = gtk.EventBox()
Now knit them together. I think the order is not important here.
hbox.pack_start(but1) hbox.pack_start(but2) hbox.pack_start(ebox) ebox.add(clock) window.add(hbox)
To make the program do something, we connect some signals to actions. Note that that the clock can receive signals, but doesn't receive all signals. For example, we have to attach button_press_event to the event box in which the clock lives. On the other hand, the clock receives screen-changed messages. If anyone can explain what's up with that, please comment.
but1.connect("clicked", gtk.main_quit) ebox.connect_object("button_press_event", clock.togglecolor, clock) clock.connect("screen-changed", clock.screen_changed) window.connect("destroy", gtk.main_quit)
Now we are done. We continue as usual.