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

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