SHARE
TWEET

Untitled

a guest Oct 10th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python2
  2.  
  3. import pygtk
  4. pygtk.require('2.0')
  5. import gtk, gobject, cairo
  6.  
  7. import math
  8.  
  9. def deg2rad(x):
  10.     return x * math.pi / 180
  11.  
  12. class Screen(gtk.DrawingArea):
  13.     # Draw in response to an expose-event
  14.     __gsignals__ = { "expose-event": "override" }
  15.  
  16.     def do_expose_event(self, event):
  17.         # Create the cairo context
  18.         cr = self.window.cairo_create()
  19.  
  20.         # Restrict Cairo to the exposed area; avoid extra work
  21.         cr.rectangle(event.area.x, event.area.y,
  22.                 event.area.width, event.area.height)
  23.         cr.clip()
  24.  
  25.         self.draw(cr, *self.window.get_size())
  26.  
  27.     def draw(self, cr, width, height):
  28.         cr.save()
  29.         cr.translate(width / 2, height / 2)
  30.  
  31.         radius = 40
  32.         ear_angle1 = 0
  33.         ear_angle2 = 75
  34.         ear_offset = radius
  35.         ear_height = 60
  36.  
  37.         cr.arc(0, 0, radius, deg2rad(-ear_angle1), deg2rad(180 + ear_angle1))
  38.         cr.line_to(-ear_offset, -ear_height)
  39.         cr.arc(0, 0, radius, deg2rad(180 + ear_angle2), deg2rad(-ear_angle2))
  40.         cr.line_to(ear_offset, -ear_height)
  41.         cr.close_path()
  42.  
  43.         cr.set_source_rgb(1.0, 1, 0)
  44.         cr.fill_preserve()
  45.         cr.set_source_rgb(1.0, 0.75, 0)
  46.         cr.set_line_width(5)
  47.         cr.stroke()
  48.  
  49.         cr.restore()
  50.  
  51.  
  52. def run(size=(200, 200)):
  53.     gtk.threads_init()
  54.     gtk.threads_enter()
  55.    
  56.     window = gtk.Window()
  57.  
  58.     widget = Screen()
  59.     widget.show()
  60.  
  61.     window.connect("delete-event", gtk.main_quit)
  62.     window.add(widget)
  63.     #window.set_decorated(False)
  64.     #window.set_skip_taskbar_hint(True)
  65.     #window.set_skip_pager_hint(True)
  66.     #window.set_keep_above(True)
  67.     #window.stick()
  68.     window.set_default_size(*size)
  69.  
  70.     window.present()
  71.     try:
  72.         gtk.main()
  73.     finally:
  74.         gtk.threads_leave()
  75.  
  76. if __name__ == "__main__":
  77.     run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top