Commits

Ivan Vučica  committed eca77db Draft

Began work on a minimal Python example which uses Xlib and DBus directly.

  • Participants
  • Parent commits 17b1541

Comments (0)

Files changed (1)

File dbus-menu-direct.py

+#!/usr/bin/env python
+import dbus
+import Xlib
+import sys
+
+# X code derived from:
+# http://python-xlib.svn.sourceforge.net/viewvc/python-xlib/trunk/examples/draw.py
+from Xlib import X, display, Xutil
+display = Xlib.display.Display()
+screen = display.screen()
+window = screen.root.create_window(
+	50, 50, 300, 200, 2,
+	screen.root_depth,
+	Xlib.X.InputOutput,
+	Xlib.X.CopyFromParent,
+
+	background_pixel = screen.white_pixel,
+	event_mask = (Xlib.X.ExposureMask | Xlib.X.ButtonPressMask),
+	colormap = X.CopyFromParent
+)
+WM_PROTOCOLS = display.intern_atom('WM_PROTOCOLS')
+WM_DELETE_WINDOW = display.intern_atom('WM_DELETE_WINDOW')
+window.set_wm_name('DBus Menu Test')
+window.set_wm_protocols([WM_DELETE_WINDOW])
+window.map()
+while True:
+	e = display.next_event()
+	if e.type == Xlib.X.DestroyNotify:
+		sys.exit(0)
+	elif e.type == Xlib.X.Expose:
+		bus = dbus.SessionBus()
+		bus_name = 'com.canonical.AppMenu.Registrar'
+		object_path = '/com/canonical/AppMenu/Registrar'
+		interface = 'com.canonical.AppMenu.Registrar'
+
+		menu_object_path = '/net/vucica/MyMenu'
+		proxy = bus.get_object(bus_name,
+		                       object_path)
+		registerWindow = proxy.get_dbus_method('RegisterWindow',dbus_interface=interface)
+		xid = dbus.UInt32(window.id)
+		registerWindow(xid, dbus.ObjectPath(menu_object_path))
+
+
+		#getMenus = proxy.get_dbus_method('GetMenus',dbus_interface=interface)
+		#print dir(getMenus)
+		#print getMenus()
+		pass
+	elif e.type == X.ClientMessage:
+		if e.client_type == WM_PROTOCOLS:
+			fmt, data = e.data
+			if fmt == 32 and data[0] == WM_DELETE_WINDOW:
+				sys.exit(0)
+