Advertisement
Guest User

Untitled

a guest
Mar 20th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.09 KB | None | 0 0
  1. #! /usr/bin/python
  2.  
  3. import gtk
  4. import rsvg
  5.  
  6. 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))
  7.  
  8. def make_shape(size, x, y, shape):
  9.     points = []
  10.     for p in shape:
  11.         points += (int(size * (p[0] + x)), int(size * (p[1] + y))),
  12.     return points
  13.    
  14. class MyWidget(gtk.DrawingArea):
  15.     def __init__(self):
  16.         gtk.DrawingArea.__init__(self)
  17.         self.gc = None  # initialized in realize-event handler
  18.         self.id = ""    # set to # + svg group id: value
  19.         self.width  = 0 # updated in size-allocate handler
  20.         self.height = 0 # idem
  21.         self.connect('size-allocate', self.on_size_allocate)
  22.         self.connect('expose-event',  self.on_expose_event)
  23.         self.connect('realize',       self.on_realize)
  24.         self.connect('button_press_event', self.button_press)
  25.  
  26.     def on_realize(self, widget):
  27.         self.gc = widget.window.new_gc()
  28.         self.gc.set_line_attributes(3, gtk.gdk.LINE_ON_OFF_DASH,
  29.                                     gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
  30.  
  31.     def on_size_allocate(self, widget, allocation):
  32.         self.width = allocation.width
  33.         self.height = allocation.height
  34.  
  35.     def on_expose_event(self, widget, event):
  36.         cr =  widget.window.cairo_create()
  37.         x,y,w,h = widget.allocation
  38.         print x,y,w,h
  39.         cr.scale(w/100.0, w/100.0)
  40.         svg=rsvg.Handle(file="probe.svg")
  41.         svg.render_cairo(cr=cr, id=self.id)
  42.         return True
  43.                              
  44.     def button_press(self, widget, event):
  45.         print event
  46.  
  47. win = gtk.Window(gtk.WINDOW_TOPLEVEL)
  48. win.set_border_width(0)
  49. win.set_default_size(300,150)
  50. box = gtk.HBox(True,0)
  51. w1 = MyWidget()
  52. w1.id = "#ID"
  53. w1.add_events(gtk.gdk.BUTTON_PRESS_MASK)
  54. w2 = MyWidget()
  55. w2.id = "#OD"
  56. w3 = MyWidget()
  57. w3.id = "#YOut"
  58. w4 = MyWidget()
  59. w4.id = "#YIn"
  60. w1.add_events(gtk.gdk.BUTTON_PRESS_MASK)
  61. box.pack_start(w1, True, True, 1)
  62. box.add(w2)
  63. box.add(w3)
  64. box.pack_end(w4, True, True, 1)
  65. box.show
  66. win.add(box)
  67. win.show_all()
  68. win.connect("destroy", lambda w: gtk.main_quit())
  69. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement