Created
March 23, 2010 07:06
-
-
Save Mistat/340909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To change this template, choose Tools | Templates | |
# and open the template in the editor. | |
import gtk, gobject, cairo | |
# Create a GTK+ widget on which we will draw using Cairo | |
class Screen(gtk.DrawingArea): | |
# Draw in response to an expose-event | |
__gsignals__ = { "expose-event": "override" } | |
# Handle the expose-event by drawing | |
def do_expose_event(self, event): | |
# Create the cairo context | |
cr = self.window.cairo_create() | |
# Restrict Cairo to the exposed area; avoid extra work | |
cr.rectangle(event.area.x, event.area.y, | |
event.area.width, event.area.height) | |
cr.clip() | |
(width, height) = self.window.get_size(); | |
# draw background | |
cr.set_source_rgb(1, 1, 1) | |
cr.rectangle(0, 0, width, height) | |
cr.fill() | |
# draw texts | |
cr.set_source_rgb(0, 0, 0) | |
cr.move_to(20,50) | |
cr.select_font_face("msgothic", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL); | |
cr.show_text("test is FONT_SLANT_NORMAL") | |
cr.move_to(20,70) | |
cr.select_font_face("msgothic", cairo.FONT_SLANT_ITALIC, cairo.FONT_WEIGHT_NORMAL); | |
cr.show_text("text is FONT_SLANT_ITALIC") | |
cr.move_to(20,90) | |
cr.select_font_face("msgothic", cairo.FONT_SLANT_OBLIQUE, cairo.FONT_WEIGHT_BOLD); | |
cr.show_text("test is FONT_SLANT_OBLIQUE") | |
y = 0 | |
cr.set_line_width(0.5) | |
while y < height: | |
cr.move_to(1,y) | |
cr.line_to(width,y) | |
cr.stroke() | |
cr.move_to(1,y) | |
cr.show_text(str(y)) | |
y+=10 | |
# GTK mumbo-jumbo to show the widget in a window and quit when it's closed | |
def run(Widget): | |
window = gtk.Window() | |
window.connect("delete-event", gtk.main_quit) | |
widget = Widget() | |
widget.show() | |
window.add(widget) | |
window.present() | |
gtk.main() | |
if __name__ == "__main__": | |
run(Screen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment