[download]

local/bin/huddbus

   1 #!/usr/bin/env python3
   2 # https://github.com/RafaelBocquet/i3-hud-menu
   3 
   4 import gi
   5 gi.require_version('Gtk', '3.0')
   6 from gi.repository import Gtk
   7 
   8 import dbus
   9 import dbus.service
  10 from dbus.mainloop.glib import DBusGMainLoop
  11 
  12 class HudDbus(dbus.service.Object):
  13     def __init__(self):
  14         busname = dbus.service.BusName('com.canonical.AppMenu.Registrar', bus=dbus.SessionBus())
  15         dbus.service.Object.__init__(self, busname, '/com/canonical/AppMenu/Registrar')
  16         self.list = dict()
  17 
  18     @dbus.service.method('com.canonical.AppMenu.Registrar', in_signature='uo', sender_keyword='sender')
  19     def RegisterWindow(self, windowId, menuObjectPath, sender):
  20         print('RegisterWindow', windowId, sender, menuObjectPath)
  21         self.list[windowId] = (sender, menuObjectPath)
  22 
  23     @dbus.service.method('com.canonical.AppMenu.Registrar', in_signature='u', sender_keyword='sender')
  24     def UnregisterWindow(self, windowId, sender):
  25         print('UnregisterWindow', windowId, sender)
  26         if windowId in self.list:
  27             del self.list[windowId]
  28 
  29     @dbus.service.method('com.canonical.AppMenu.Registrar', in_signature='u', out_signature='so')
  30     def GetMenuForWindow(self, windowId):
  31         if windowId in self.list:
  32             sender, menuObjectPath = self.list[windowId]
  33             print('GetMenuForWindow', windowId, sender, menuObjectPath)
  34             return [dbus.String(sender), dbus.ObjectPath(menuObjectPath)]
  35 
  36     @dbus.service.method('com.canonical.AppMenu.Registrar')
  37     def Q(self):
  38         Gtk.main_quit()
  39 
  40 try:
  41     DBusGMainLoop(set_as_default=True)
  42     HudDbus()
  43     Gtk.main()
  44 except KeyboardInterrupt:
  45     Gtk.main_quit()