source: trunk/debathena/config/gdm-config/debian/debathena-branding @ 24841

Revision 24841, 4.2 KB checked in by jdreed, 14 years ago (diff)
Deal with environments that don't honor position hints
  • Property svn:executable set to *
RevLine 
[24816]1#!/usr/bin/python -Wall
2
3import dbus
4import dbus.mainloop.glib
5import gtk
[24817]6import gtk.glade
[24816]7import gobject
[24817]8import sys
[24816]9import os
10import subprocess
11
12SM_DBUS_NAME = "org.gnome.SessionManager"
13SM_DBUS_PATH = "/org/gnome/SessionManager"
14SM_DBUS_INTERFACE = "org.gnome.SessionManager"
15SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate"
16APP_ID = "debathena-branding"
[24818]17GLADE_FILE="/usr/share/debathena-branding/debathena-branding.glade"
[24817]18DEBATHENA_LOGO_FILE="/usr/share/pixmaps/debathena.png"
[24816]19
20class Branding:
21    def __init__(self):
22        self.sessionEnding = False
23        self.sessionBus = dbus.SessionBus()
24        try:
25            self.register_with_sm()
26            self.init_sm_client()
27        except:
28            print "Warning: Cannot register with session manager."
[24817]29       
30        try:
31            self.xml = gtk.glade.XML(GLADE_FILE)
32        except:
33            print "Could not load Glade XML: %s" % (GLADE_FILE)
34            sys.exit(1)
[24816]35
[24817]36       
37        self.winWelcome = self.xml.get_widget('winWelcome')
[24840]38        moveY = 200
39        logoScale = 0.60
40        if gtk.gdk.screen_height() < 864:
41            # Here's a nickel, buy a real display
42            moveY = 0
43            logoScale = 0.40
[24841]44        self.winWelcome.move((gtk.gdk.screen_width() - self.winWelcome.get_size()[0]) / 2, moveY)
[24817]45        self.imgDebathena = self.xml.get_widget('imgDebathena')
[24816]46        try:
[24817]47            pixbuf = gtk.gdk.pixbuf_new_from_file(DEBATHENA_LOGO_FILE)
[24840]48            self.imgDebathena.set_from_pixbuf(pixbuf.scale_simple(int(pixbuf.get_width() * logoScale), int(pixbuf.get_height() * logoScale), gtk.gdk.INTERP_BILINEAR))
[24817]49        except:
50            # Just don't display the image if it's missing
51            pass
52        self.winBranding = self.xml.get_widget('winBranding')
53        self.lblBranding = self.xml.get_widget('lblBranding')
54        try:
[24816]55            metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip()
56        except OSError:
57            metapackage = '(error)'
58        try:
59            baseos = subprocess.Popen(["machtype", "-E"], stdout=subprocess.PIPE).communicate()[0].rstrip()
60        except OSError:
61            baseos = '(error)'
[24817]62        self.lblBranding.set_text(metapackage + "\n" + baseos)
63        self.winBranding.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST)
64        width, height = self.winBranding.get_size()
65        self.winBranding.move(gtk.gdk.screen_width() - width, gtk.gdk.screen_height() - height)
[24816]66
67    # Connect to the session manager, and register our client.
68    def register_with_sm(self):
69        proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH)
70        sm = dbus.Interface(proxy, SM_DBUS_INTERFACE)
71        autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="")
72        self.smClientId = sm.RegisterClient(APP_ID, autostart_id)
73
74    # Set up to handle signals from the session manager.
75    def init_sm_client(self):
76        proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId)
77        self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE)
78        self.smClient.connect_to_signal("QueryEndSession",
79                                         self.sm_on_QueryEndSession)
80        self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession)
81        self.smClient.connect_to_signal("CancelEndSession",
82                                         self.sm_on_CancelEndSession)
83        self.smClient.connect_to_signal("Stop", self.sm_on_Stop)
84
85    # Here on a QueryEndSession signal from the session manager.
86    def sm_on_QueryEndSession(self, flags):
87        self.sessionEnding = True
88        # Response args: is_ok, reason.
89        self.smClient.EndSessionResponse(True, "")
90
91    # Here on an EndSession signal from the session manager.
92    def sm_on_EndSession(self, flags):
93        self.sessionEnding = True
94        # Response args: is_ok, reason.
95        self.smClient.EndSessionResponse(True, "")
96
97    # Here on a CancelEndSession signal from the session manager.
98    def sm_on_CancelEndSession(self):
99        self.sessionEnding = False
100
101    # Here on a Stop signal from the session manager.
102    def sm_on_Stop(self):
103        gtk.main_quit()
104
105def main():
106    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
107    Branding()
108    gtk.main()
109
110if __name__ == '__main__':
111    main()
Note: See TracBrowser for help on using the repository browser.