Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import gtk
- import rsvg
- up_arrow = ((0,0),(0.2,0.2),(0.1,0.2),(0.1,0.4),(-0.1,0.4),(-0.1,0.2),(-0.2,0.2))
- def make_shape(size, x, y, shape):
- points = []
- for p in shape:
- points += (int(size * (p[0] + x)), int(size * (p[1] + y))),
- return points
- class MyWidget(gtk.DrawingArea):
- def __init__(self):
- gtk.DrawingArea.__init__(self)
- self.gc = None # initialized in realize-event handler
- self.id = "" # set to # + svg group id: value
- self.width = 0 # updated in size-allocate handler
- self.height = 0 # idem
- self.connect('size-allocate', self.on_size_allocate)
- self.connect('expose-event', self.on_expose_event)
- self.connect('realize', self.on_realize)
- self.connect('button_press_event', self.button_press)
- def on_realize(self, widget):
- self.gc = widget.window.new_gc()
- self.gc.set_line_attributes(3, gtk.gdk.LINE_ON_OFF_DASH,
- gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
- def on_size_allocate(self, widget, allocation):
- self.width = allocation.width
- self.height = allocation.height
- def on_expose_event(self, widget, event):
- cr = widget.window.cairo_create()
- x,y,w,h = widget.allocation
- print x,y,w,h
- cr.scale(w/100.0, w/100.0)
- svg=rsvg.Handle(file="probe.svg")
- svg.render_cairo(cr=cr, id=self.id)
- return True
- def button_press(self, widget, event):
- print event
- win = gtk.Window(gtk.WINDOW_TOPLEVEL)
- win.set_border_width(0)
- win.set_default_size(300,150)
- box = gtk.HBox(True,0)
- w1 = MyWidget()
- w1.id = "#ID"
- w1.add_events(gtk.gdk.BUTTON_PRESS_MASK)
- w2 = MyWidget()
- w2.id = "#OD"
- w3 = MyWidget()
- w3.id = "#YOut"
- w4 = MyWidget()
- w4.id = "#YIn"
- w1.add_events(gtk.gdk.BUTTON_PRESS_MASK)
- box.pack_start(w1, True, True, 1)
- box.add(w2)
- box.add(w3)
- box.pack_end(w4, True, True, 1)
- box.show
- win.add(box)
- win.show_all()
- win.connect("destroy", lambda w: gtk.main_quit())
- gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement