working using expose-event

This commit is contained in:
Josh Holtrop 2012-05-15 23:14:58 -04:00
parent f50d058304
commit 7fa582baa0

View File

@ -4,21 +4,24 @@ import os
import sys
import gtk
import pango
import cairo
import pangocairo
FONT = "Sans Bold 27"
class MyWidget(gtk.DrawingArea):
def __init__(self):
gtk.DrawingArea.__init__(self)
self.set_size_request(200, 200)
self.connect('expose-event', self.expose)
def do_draw_cb(self, widget, cr):
layout = pangocairo.create_layout(cr)
layout.set_text("Text", -1)
desc = pango.font_description_from_string(FONT)
layout.set_font_description(desc)
pangocairo.show_layout(cr, layout)
def expose(self, widget, event):
cr = widget.window.cairo_create()
cr.select_font_face("Courier",
cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
cr.set_font_size(20)
cr.set_source_rgb(1.0, 0.3, 0.0)
cr.move_to(0, 15)
cr.text_path("Hello")
cr.stroke()
def destroy(window):
gtk.main_quit()
@ -28,7 +31,6 @@ def main():
window.set_title("Custom pygtk widget hello world")
widget = MyWidget()
window.add(widget)
widget.connect('draw', widget.do_draw_cb)
window.connect_after('destroy', destroy)
window.show_all()
gtk.main()