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

Revision 24916, 4.2 KB checked in by jdreed, 14 years ago (diff)
Update for Vostro and remove sarcasm
  • Property svn:executable set to *
Line 
1#!/usr/bin/python -Wall
2
3import dbus
4import dbus.mainloop.glib
5import gtk
6import gtk.glade
7import gobject
8import sys
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"
17GLADE_FILE="/usr/share/debathena-branding/debathena-branding.glade"
18DEBATHENA_LOGO_FILE="/usr/share/pixmaps/debathena.png"
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."
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)
35
36       
37        self.winWelcome = self.xml.get_widget('winWelcome')
38        moveY = 200
39        logoScale = 0.60
40        if gtk.gdk.screen_height() <= 900:
41            moveY = 0
42            logoScale = 0.40
43        self.winWelcome.move((gtk.gdk.screen_width() - self.winWelcome.get_size()[0]) / 2, moveY)
44        self.imgDebathena = self.xml.get_widget('imgDebathena')
45        try:
46            pixbuf = gtk.gdk.pixbuf_new_from_file(DEBATHENA_LOGO_FILE)
47            self.imgDebathena.set_from_pixbuf(pixbuf.scale_simple(int(pixbuf.get_width() * logoScale), int(pixbuf.get_height() * logoScale), gtk.gdk.INTERP_BILINEAR))
48        except:
49            # Just don't display the image if it's missing
50            pass
51        self.winBranding = self.xml.get_widget('winBranding')
52        self.lblBranding = self.xml.get_widget('lblBranding')
53        try:
54            metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip()
55        except OSError:
56            metapackage = '(error)'
57        try:
58            baseos = subprocess.Popen(["machtype", "-E"], stdout=subprocess.PIPE).communicate()[0].rstrip()
59        except OSError:
60            baseos = '(error)'
61        self.lblBranding.set_text(metapackage + "\n" + baseos)
62        self.winBranding.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST)
63        width, height = self.winBranding.get_size()
64        self.winBranding.move(gtk.gdk.screen_width() - width, gtk.gdk.screen_height() - height)
65
66    # Connect to the session manager, and register our client.
67    def register_with_sm(self):
68        proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH)
69        sm = dbus.Interface(proxy, SM_DBUS_INTERFACE)
70        autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="")
71        self.smClientId = sm.RegisterClient(APP_ID, autostart_id)
72
73    # Set up to handle signals from the session manager.
74    def init_sm_client(self):
75        proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId)
76        self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE)
77        self.smClient.connect_to_signal("QueryEndSession",
78                                         self.sm_on_QueryEndSession)
79        self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession)
80        self.smClient.connect_to_signal("CancelEndSession",
81                                         self.sm_on_CancelEndSession)
82        self.smClient.connect_to_signal("Stop", self.sm_on_Stop)
83
84    # Here on a QueryEndSession signal from the session manager.
85    def sm_on_QueryEndSession(self, flags):
86        self.sessionEnding = True
87        # Response args: is_ok, reason.
88        self.smClient.EndSessionResponse(True, "")
89
90    # Here on an EndSession signal from the session manager.
91    def sm_on_EndSession(self, flags):
92        self.sessionEnding = True
93        # Response args: is_ok, reason.
94        self.smClient.EndSessionResponse(True, "")
95
96    # Here on a CancelEndSession signal from the session manager.
97    def sm_on_CancelEndSession(self):
98        self.sessionEnding = False
99
100    # Here on a Stop signal from the session manager.
101    def sm_on_Stop(self):
102        gtk.main_quit()
103
104def main():
105    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
106    Branding()
107    gtk.main()
108
109if __name__ == '__main__':
110    main()
Note: See TracBrowser for help on using the repository browser.