41 lines
951 B
Python
Executable File
41 lines
951 B
Python
Executable File
#!/usr/bin/env pythonw
|
|
|
|
import os
|
|
import sys
|
|
import gtk
|
|
import pango
|
|
import cairo
|
|
import pangocairo
|
|
|
|
class MyWidget(gtk.DrawingArea):
|
|
def __init__(self):
|
|
gtk.DrawingArea.__init__(self)
|
|
self.set_size_request(200, 200)
|
|
self.connect('expose-event', self.expose)
|
|
|
|
def expose(self, widget, event):
|
|
cr = widget.window.cairo_create()
|
|
layout = cr.create_layout()
|
|
layout.set_text("Hello")
|
|
desc = pango.FontDescription("Mono Bold 27")
|
|
layout.set_font_description(desc)
|
|
cr.move_to(10, 150)
|
|
cr.update_layout(layout)
|
|
cr.show_layout(layout)
|
|
|
|
def destroy(window):
|
|
gtk.main_quit()
|
|
|
|
def main():
|
|
window = gtk.Window()
|
|
window.set_title("Custom pygtk widget hello world")
|
|
widget = MyWidget()
|
|
window.add(widget)
|
|
window.connect_after('destroy', destroy)
|
|
window.show_all()
|
|
gtk.main()
|
|
return 0
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|