1 | #!/usr/bin/python -Wall |
---|
2 | |
---|
3 | import dbus |
---|
4 | import dbus.mainloop.glib |
---|
5 | import gtk |
---|
6 | import gtk.glade |
---|
7 | import gobject |
---|
8 | import sys |
---|
9 | import os |
---|
10 | import subprocess |
---|
11 | |
---|
12 | SM_DBUS_NAME = "org.gnome.SessionManager" |
---|
13 | SM_DBUS_PATH = "/org/gnome/SessionManager" |
---|
14 | SM_DBUS_INTERFACE = "org.gnome.SessionManager" |
---|
15 | SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate" |
---|
16 | APP_ID = "debathena-branding" |
---|
17 | GLADE_FILE="/usr/share/debathena-branding/debathena-branding.glade" |
---|
18 | DEBATHENA_LOGO_FILE="/usr/share/pixmaps/debathena.png" |
---|
19 | |
---|
20 | class 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() < 864: |
---|
41 | # Here's a nickel, buy a real display |
---|
42 | moveY = 0 |
---|
43 | logoScale = 0.40 |
---|
44 | self.winWelcome.move(self.winWelcome.get_position()[0], moveY) |
---|
45 | self.imgDebathena = self.xml.get_widget('imgDebathena') |
---|
46 | try: |
---|
47 | pixbuf = gtk.gdk.pixbuf_new_from_file(DEBATHENA_LOGO_FILE) |
---|
48 | self.imgDebathena.set_from_pixbuf(pixbuf.scale_simple(int(pixbuf.get_width() * logoScale), int(pixbuf.get_height() * logoScale), gtk.gdk.INTERP_BILINEAR)) |
---|
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: |
---|
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)' |
---|
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) |
---|
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 | |
---|
105 | def main(): |
---|
106 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
---|
107 | Branding() |
---|
108 | gtk.main() |
---|
109 | |
---|
110 | if __name__ == '__main__': |
---|
111 | main() |
---|