#!/usr/bin/python -Wall import dbus import dbus.mainloop.glib import gtk import gtk.glade import gobject import sys import os import subprocess SM_DBUS_NAME = "org.gnome.SessionManager" SM_DBUS_PATH = "/org/gnome/SessionManager" SM_DBUS_INTERFACE = "org.gnome.SessionManager" SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate" APP_ID = "debathena-branding" GLADE_FILE="/usr/share/debathena-branding/debathena-branding.glade" DEBATHENA_LOGO_FILE="/usr/share/pixmaps/debathena.png" class Branding: def __init__(self): self.sessionEnding = False self.sessionBus = dbus.SessionBus() try: self.register_with_sm() self.init_sm_client() except: print "Warning: Cannot register with session manager." try: self.xml = gtk.glade.XML(GLADE_FILE) except: print "Could not load Glade XML: %s" % (GLADE_FILE) sys.exit(1) self.winWelcome = self.xml.get_widget('winWelcome') moveY = 200 logoScale = 0.60 if gtk.gdk.screen_height() < 864: # Here's a nickel, buy a real display moveY = 0 logoScale = 0.40 self.winWelcome.move((gtk.gdk.screen_width() - self.winWelcome.get_size()[0]) / 2, moveY) self.imgDebathena = self.xml.get_widget('imgDebathena') try: pixbuf = gtk.gdk.pixbuf_new_from_file(DEBATHENA_LOGO_FILE) self.imgDebathena.set_from_pixbuf(pixbuf.scale_simple(int(pixbuf.get_width() * logoScale), int(pixbuf.get_height() * logoScale), gtk.gdk.INTERP_BILINEAR)) except: # Just don't display the image if it's missing pass self.winBranding = self.xml.get_widget('winBranding') self.lblBranding = self.xml.get_widget('lblBranding') try: metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip() except OSError: metapackage = '(error)' try: baseos = subprocess.Popen(["machtype", "-E"], stdout=subprocess.PIPE).communicate()[0].rstrip() except OSError: baseos = '(error)' self.lblBranding.set_text(metapackage + "\n" + baseos) self.winBranding.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST) width, height = self.winBranding.get_size() self.winBranding.move(gtk.gdk.screen_width() - width, gtk.gdk.screen_height() - height) # Connect to the session manager, and register our client. def register_with_sm(self): proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH) sm = dbus.Interface(proxy, SM_DBUS_INTERFACE) autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="") self.smClientId = sm.RegisterClient(APP_ID, autostart_id) # Set up to handle signals from the session manager. def init_sm_client(self): proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId) self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE) self.smClient.connect_to_signal("QueryEndSession", self.sm_on_QueryEndSession) self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession) self.smClient.connect_to_signal("CancelEndSession", self.sm_on_CancelEndSession) self.smClient.connect_to_signal("Stop", self.sm_on_Stop) # Here on a QueryEndSession signal from the session manager. def sm_on_QueryEndSession(self, flags): self.sessionEnding = True # Response args: is_ok, reason. self.smClient.EndSessionResponse(True, "") # Here on an EndSession signal from the session manager. def sm_on_EndSession(self, flags): self.sessionEnding = True # Response args: is_ok, reason. self.smClient.EndSessionResponse(True, "") # Here on a CancelEndSession signal from the session manager. def sm_on_CancelEndSession(self): self.sessionEnding = False # Here on a Stop signal from the session manager. def sm_on_Stop(self): gtk.main_quit() def main(): dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) Branding() gtk.main() if __name__ == '__main__': main()