Guest User

Untitled

a guest
Jun 19th, 2020
38
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. # Popover dialog on mouse position
  3. import gi
  4. import cairo
  5. gi.require_version('Gtk', '3.0')
  6. gi.require_version('Gdk', '3.0')
  7. from gi.repository import Gtk, Gdk
  8.  
  9. class Popover(Gtk.Window):
  10. def __init__(self):
  11. Gtk.Window.__init__(self, Gtk.WindowType.TOPLEVEL)
  12. self.set_title("Popover")
  13. self.set_default_size(190, 75)
  14. self.connect("destroy", Gtk.main_quit)
  15.  
  16. self.screen = self.get_screen()
  17. self.visual = self.screen.get_rgba_visual()
  18. if self.visual != None and self.screen.is_composited():
  19. print ("Composited")
  20. self.set_visual(self.visual)
  21. self.set_app_paintable(True)
  22. self.connect("draw", self.area_draw)
  23.  
  24. box = Gtk.Box()
  25. box.set_spacing(5)
  26. box.set_orientation(Gtk.Orientation.VERTICAL)
  27. self.add(box)
  28.  
  29. self.popover = Gtk.Popover()
  30. self.popover.set_position(Gtk.PositionType.TOP)
  31. self.popover.set_relative_to(box)
  32.  
  33. box = Gtk.Box()
  34. box.set_spacing(5)
  35. box.set_orientation(Gtk.Orientation.VERTICAL)
  36.  
  37. self.popover.add(box)
  38.  
  39. button = Gtk.Button("Close")
  40. button.connect("button-press-event", Gtk.main_quit)
  41.  
  42. label = Gtk.Label("Click this to close")
  43. box.add(button)
  44.  
  45. checkbutton = Gtk.CheckButton("A CheckButton widget")
  46. box.add(checkbutton)
  47. self.popover.show_all()
  48.  
  49. def area_draw(self, widget, cr):
  50. cr.set_source_rgba(0, 0, 0, 0)
  51. cr.set_operator(cairo.OPERATOR_SOURCE)
  52. cr.paint()
  53. cr.set_operator(cairo.OPERATOR_OVER)
  54.  
  55. w2 = Popover()
  56. w2.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
  57. w2.connect("button-press-event", Gtk.main_quit)
  58.  
  59. w2.connect("destroy", Gtk.main_quit)
  60. w2.connect("focus-out-event", Gtk.main_quit)
  61. w2.set_position(Gtk.WindowPosition.MOUSE)
  62. w2.set_decorated(False)
  63. w2.set_skip_taskbar_hint(True)
  64.  
  65. w2.show()
  66.  
  67. Gtk.main()
RAW Paste Data