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

Revision 25581, 7.2 KB checked in by jdreed, 13 years ago (diff)
Remove typo'd snark, replace with real comment.
  • 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
12from optparse import OptionParser
13
14SM_DBUS_NAME = "org.gnome.SessionManager"
15SM_DBUS_PATH = "/org/gnome/SessionManager"
16SM_DBUS_INTERFACE = "org.gnome.SessionManager"
17SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate"
18APP_ID = "debathena-branding"
19GLADE_FILE="/usr/share/debathena-branding/debathena-branding.glade"
20DEBATHENA_LOGO_FILES=["/usr/share/pixmaps/debathena.png",
21                      "/usr/share/pixmaps/debathena1.png",
22                      "/usr/share/pixmaps/debathena2.png",
23                      "/usr/share/pixmaps/debathena3.png",
24                      "/usr/share/pixmaps/debathena4.png",
25                      "/usr/share/pixmaps/debathena5.png",
26                      "/usr/share/pixmaps/debathena6.png",
27                      "/usr/share/pixmaps/debathena7.png",
28                      "/usr/share/pixmaps/debathena8.png"]
29
30class Branding:
31    animation_loop_frames = 150
32
33    def __init__(self, options):
34        self.debug = options.debug
35        self.sessionEnding = False
36        self.sessionBus = dbus.SessionBus()
37        try:
38            self.register_with_sm()
39            self.init_sm_client()
40        except:
41            print "Warning: Cannot register with session manager."
42       
43        try:
44            self.xml = gtk.glade.XML(options.gladefile)
45        except:
46            print "Could not load Glade XML: %s" % (options.gladefile)
47            sys.exit(1)
48
49       
50        self.winWelcome = self.xml.get_widget('winWelcome')
51        self.winWelcome.set_property('can_focus', False)
52        # Multiple monitor support.  Use the primary monitor.
53        defaultScreen = gtk.gdk.screen_get_default()
54        self.monitorGeometry = defaultScreen.get_monitor_geometry(defaultScreen.get_primary_monitor())
55        moveY = self.monitorGeometry.y + 200
56        logoScale = 0.60
57        if (self.monitorGeometry.height - self.monitorGeometry.y) <= 900:
58            moveY = self.monitorGeometry.y + 10
59            logoScale = 0.40
60        moveX = self.monitorGeometry.x + ((self.monitorGeometry.width - self.winWelcome.get_size()[0]) / 2)
61        self.winWelcome.move(moveX, moveY)
62        self.imgDebathena = self.xml.get_widget('imgDebathena')
63        self.imgDebathena.set_property('can_focus', False)
64        self.animate = self.setup_owl(logoScale)
65        self.winBranding = self.xml.get_widget('winBranding')
66        self.winBranding.set_property('can_focus', False)
67        self.lblBranding = self.xml.get_widget('lblBranding')
68        self.lblBranding.set_property('can_focus', False)
69        try:
70            metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip()
71        except OSError:
72            metapackage = '(error)'
73        try:
74            baseos = subprocess.Popen(["machtype", "-E"], stdout=subprocess.PIPE).communicate()[0].rstrip()
75        except OSError:
76            baseos = '(error)'
77        arch = platform.machine()
78        if arch != "x86_64":
79            arch = "<b>" + arch + "</b>"
80        self.lblBranding.set_markup(metapackage + "\n" + baseos + "\n" + arch)
81        self.winBranding.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST)
82        width, height = self.winBranding.get_size()
83        self.winBranding.move(self.monitorGeometry.x + (self.monitorGeometry.width - width), self.monitorGeometry.y + (self.monitorGeometry.height - height))
84
85    # Connect to the session manager, and register our client.
86    def register_with_sm(self):
87        proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH)
88        sm = dbus.Interface(proxy, SM_DBUS_INTERFACE)
89        autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="")
90        self.smClientId = sm.RegisterClient(APP_ID, autostart_id)
91
92    # Set up to handle signals from the session manager.
93    def init_sm_client(self):
94        proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId)
95        self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE)
96        self.smClient.connect_to_signal("QueryEndSession",
97                                         self.sm_on_QueryEndSession)
98        self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession)
99        self.smClient.connect_to_signal("CancelEndSession",
100                                         self.sm_on_CancelEndSession)
101        self.smClient.connect_to_signal("Stop", self.sm_on_Stop)
102
103    # Load the Debathena owl image and generate self.logo_pixbufs, the list of
104    # animation frames.  Returns True if successful, False otherwise.
105    def setup_owl(self, logoScale):
106        self.logo_pixbufs = []
107        num_pixbufs = 0
108        try:
109            # Eyes go closed.
110            for img in DEBATHENA_LOGO_FILES:
111                pixbuf = gtk.gdk.pixbuf_new_from_file(img)
112                self.logo_pixbufs.append(pixbuf.scale_simple(int(pixbuf.get_width() * logoScale), int(pixbuf.get_height() * logoScale), gtk.gdk.INTERP_BILINEAR))
113                num_pixbufs += 1
114
115        except:
116            # Just don't display the image if it's missing
117            return False
118
119        # Eyes come open.
120        for pixbuf in self.logo_pixbufs[::-1]:
121            self.logo_pixbufs.append(pixbuf)
122            num_pixbufs += 1
123
124        # Eyes stay open.
125        self.logo_pixbufs.extend([None] * (self.animation_loop_frames - num_pixbufs))
126        # Set it to the first image so that the window can size itself         
127        # accordingly                                                           
128        self.imgDebathena.set_from_pixbuf(self.logo_pixbufs[0])
129        self.img_idx = -1
130        return True
131
132    # Update the Debathena owl image.
133    def update_owl(self):
134        if not self.animate:
135            return False
136
137        self.img_idx = (self.img_idx + 1) % self.animation_loop_frames
138        pixbuf = self.logo_pixbufs[self.img_idx]
139        if pixbuf is not None:
140            self.imgDebathena.set_from_pixbuf(pixbuf)
141        return True
142
143    # Here on a QueryEndSession signal from the session manager.
144    def sm_on_QueryEndSession(self, flags):
145        self.sessionEnding = True
146        # Response args: is_ok, reason.
147        self.smClient.EndSessionResponse(True, "")
148
149    # Here on an EndSession signal from the session manager.
150    def sm_on_EndSession(self, flags):
151        self.sessionEnding = True
152        # Response args: is_ok, reason.
153        self.smClient.EndSessionResponse(True, "")
154
155    # Here on a CancelEndSession signal from the session manager.
156    def sm_on_CancelEndSession(self):
157        self.sessionEnding = False
158
159    # Here on a Stop signal from the session manager.
160    def sm_on_Stop(self):
161        subprocess.call(["/usr/bin/pkill", "-f", "gnome-settings-daemon"])
162        gtk.main_quit()
163
164def main(options):
165    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
166    branding = Branding(options)
167    gobject.timeout_add(50, branding.update_owl)
168    gtk.main()
169
170if __name__ == '__main__':
171    parser = OptionParser()
172    parser.set_defaults(debug=False, guitest=False)
173    parser.add_option("--test", action="store_true", dest="debug")
174    parser.add_option("--glade", action="store", type="string",
175                      default=GLADE_FILE, dest="gladefile")
176    (options, args) = parser.parse_args()
177    main(options)
Note: See TracBrowser for help on using the repository browser.