1 | #!/usr/bin/python -Wall |
---|
2 | |
---|
3 | import dbus |
---|
4 | import dbus.mainloop.glib |
---|
5 | import gtk |
---|
6 | import gobject |
---|
7 | #import time |
---|
8 | import os |
---|
9 | #import sys |
---|
10 | import subprocess |
---|
11 | #from optparse import OptionParser |
---|
12 | |
---|
13 | SM_DBUS_NAME = "org.gnome.SessionManager" |
---|
14 | SM_DBUS_PATH = "/org/gnome/SessionManager" |
---|
15 | SM_DBUS_INTERFACE = "org.gnome.SessionManager" |
---|
16 | SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate" |
---|
17 | APP_ID = "debathena-branding" |
---|
18 | |
---|
19 | class Branding: |
---|
20 | def __init__(self): |
---|
21 | self.sessionEnding = False |
---|
22 | self.sessionBus = dbus.SessionBus() |
---|
23 | try: |
---|
24 | self.register_with_sm() |
---|
25 | self.init_sm_client() |
---|
26 | except: |
---|
27 | print "Warning: Cannot register with session manager." |
---|
28 | |
---|
29 | self.brandingWindow = gtk.Window(gtk.WINDOW_TOPLEVEL) |
---|
30 | self.brandingLabel = gtk.Label() |
---|
31 | self.brandingLabel.set_justify(gtk.JUSTIFY_CENTER) |
---|
32 | self.brandingLabel.set_padding(2,2) |
---|
33 | self.brandingWindow.add(self.brandingLabel) |
---|
34 | # Turn off all window decorations for the login screen. |
---|
35 | self.brandingWindow.set_decorated(False) |
---|
36 | try: |
---|
37 | metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip() |
---|
38 | except OSError: |
---|
39 | metapackage = '(error)' |
---|
40 | try: |
---|
41 | baseos = subprocess.Popen(["machtype", "-E"], stdout=subprocess.PIPE).communicate()[0].rstrip() |
---|
42 | except OSError: |
---|
43 | baseos = '(error)' |
---|
44 | self.brandingLabel.set_text(metapackage + "\n" + baseos) |
---|
45 | self.brandingWindow.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST) |
---|
46 | self.brandingWindow.set_size_request(self.brandingLabel.get_property('width-chars'),-1) |
---|
47 | width, height = self.brandingWindow.get_size() |
---|
48 | self.brandingWindow.move(gtk.gdk.screen_width(), |
---|
49 | gtk.gdk.screen_height()) |
---|
50 | self.brandingWindow.show_all() |
---|
51 | |
---|
52 | # Connect to the session manager, and register our client. |
---|
53 | def register_with_sm(self): |
---|
54 | proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH) |
---|
55 | sm = dbus.Interface(proxy, SM_DBUS_INTERFACE) |
---|
56 | autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="") |
---|
57 | self.smClientId = sm.RegisterClient(APP_ID, autostart_id) |
---|
58 | |
---|
59 | # Set up to handle signals from the session manager. |
---|
60 | def init_sm_client(self): |
---|
61 | proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId) |
---|
62 | self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE) |
---|
63 | self.smClient.connect_to_signal("QueryEndSession", |
---|
64 | self.sm_on_QueryEndSession) |
---|
65 | self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession) |
---|
66 | self.smClient.connect_to_signal("CancelEndSession", |
---|
67 | self.sm_on_CancelEndSession) |
---|
68 | self.smClient.connect_to_signal("Stop", self.sm_on_Stop) |
---|
69 | |
---|
70 | # Here on a QueryEndSession signal from the session manager. |
---|
71 | def sm_on_QueryEndSession(self, flags): |
---|
72 | self.sessionEnding = True |
---|
73 | # Response args: is_ok, reason. |
---|
74 | self.smClient.EndSessionResponse(True, "") |
---|
75 | |
---|
76 | # Here on an EndSession signal from the session manager. |
---|
77 | def sm_on_EndSession(self, flags): |
---|
78 | self.sessionEnding = True |
---|
79 | # Response args: is_ok, reason. |
---|
80 | self.smClient.EndSessionResponse(True, "") |
---|
81 | |
---|
82 | # Here on a CancelEndSession signal from the session manager. |
---|
83 | def sm_on_CancelEndSession(self): |
---|
84 | self.sessionEnding = False |
---|
85 | |
---|
86 | # Here on a Stop signal from the session manager. |
---|
87 | def sm_on_Stop(self): |
---|
88 | gtk.main_quit() |
---|
89 | |
---|
90 | def main(): |
---|
91 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
---|
92 | Branding() |
---|
93 | gtk.main() |
---|
94 | |
---|
95 | if __name__ == '__main__': |
---|
96 | main() |
---|