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

Revision 25410, 6.6 KB checked in by bbaren, 13 years ago (diff)
In gdm-config: * Put original Debathena logo at its original filename. * Make debathena-branding handle missing images gracefully.
  • 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        moveY = 200
53        logoScale = 0.60
54        if gtk.gdk.screen_height() <= 900:
55            moveY = 10
56            logoScale = 0.40
57        self.winWelcome.move((gtk.gdk.screen_width() - self.winWelcome.get_size()[0]) / 2, moveY)
58        self.imgDebathena = self.xml.get_widget('imgDebathena')
59        self.imgDebathena.set_property('can_focus', False)
60        self.animate = self.setup_owl(logoScale)
61        self.winBranding = self.xml.get_widget('winBranding')
62        self.winBranding.set_property('can_focus', False)
63        self.lblBranding = self.xml.get_widget('lblBranding')
64        self.lblBranding.set_property('can_focus', False)
65        try:
66            metapackage = subprocess.Popen(["machtype", "-L"], stdout=subprocess.PIPE).communicate()[0].rstrip()
67        except OSError:
68            metapackage = '(error)'
69        try:
70            baseos = subprocess.Popen(["machtype", "-E"], stdout=subprocess.PIPE).communicate()[0].rstrip()
71        except OSError:
72            baseos = '(error)'
73        arch = platform.machine()
74        if arch != "x86_64":
75            arch = "<b>" + arch + "</b>"
76        self.lblBranding.set_markup(metapackage + "\n" + baseos + "\n" + arch)
77        self.winBranding.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST)
78        width, height = self.winBranding.get_size()
79        self.winBranding.move(gtk.gdk.screen_width() - width, gtk.gdk.screen_height() - height)
80
81    # Connect to the session manager, and register our client.
82    def register_with_sm(self):
83        proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH)
84        sm = dbus.Interface(proxy, SM_DBUS_INTERFACE)
85        autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="")
86        self.smClientId = sm.RegisterClient(APP_ID, autostart_id)
87
88    # Set up to handle signals from the session manager.
89    def init_sm_client(self):
90        proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId)
91        self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE)
92        self.smClient.connect_to_signal("QueryEndSession",
93                                         self.sm_on_QueryEndSession)
94        self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession)
95        self.smClient.connect_to_signal("CancelEndSession",
96                                         self.sm_on_CancelEndSession)
97        self.smClient.connect_to_signal("Stop", self.sm_on_Stop)
98
99    # Load the Debathena owl image and generate self.logo_pixbufs, the list of
100    # animation frames.  Returns True if successful, False otherwise.
101    def setup_owl(self, logoScale):
102        self.logo_pixbufs = []
103        num_pixbufs = 0
104        try:
105            # Eyes go closed.
106            for img in DEBATHENA_LOGO_FILES:
107                pixbuf = gtk.gdk.pixbuf_new_from_file(img)
108                self.logo_pixbufs.append(pixbuf.scale_simple(int(pixbuf.get_width() * logoScale), int(pixbuf.get_height() * logoScale), gtk.gdk.INTERP_BILINEAR))
109                num_pixbufs += 1
110
111        except:
112            # Just don't display the image if it's missing
113            return False
114
115        # Eyes come open.
116        for pixbuf in self.logo_pixbufs[::-1]:
117            self.logo_pixbufs.append(pixbuf)
118            num_pixbufs += 1
119
120        # Eyes stay open.
121        self.logo_pixbufs.extend([None] * (self.animation_loop_frames - num_pixbufs))
122
123        self.img_idx = -1
124        return True
125
126    # Update the Debathena owl image.
127    def update_owl(self):
128        if not self.animate:
129            return False
130
131        self.img_idx = (self.img_idx + 1) % self.animation_loop_frames
132        pixbuf = self.logo_pixbufs[self.img_idx]
133        if pixbuf is not None:
134            self.imgDebathena.set_from_pixbuf(pixbuf)
135        return True
136
137    # Here on a QueryEndSession signal from the session manager.
138    def sm_on_QueryEndSession(self, flags):
139        self.sessionEnding = True
140        # Response args: is_ok, reason.
141        self.smClient.EndSessionResponse(True, "")
142
143    # Here on an EndSession signal from the session manager.
144    def sm_on_EndSession(self, flags):
145        self.sessionEnding = True
146        # Response args: is_ok, reason.
147        self.smClient.EndSessionResponse(True, "")
148
149    # Here on a CancelEndSession signal from the session manager.
150    def sm_on_CancelEndSession(self):
151        self.sessionEnding = False
152
153    # Here on a Stop signal from the session manager.
154    def sm_on_Stop(self):
155        subprocess.call(["/usr/bin/pkill", "-f", "gnome-settings-daemon"])
156        gtk.main_quit()
157
158def main(options):
159    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
160    branding = Branding(options)
161    gobject.timeout_add(50, branding.update_owl)
162    gtk.main()
163
164if __name__ == '__main__':
165    parser = OptionParser()
166    parser.set_defaults(debug=False, guitest=False)
167    parser.add_option("--test", action="store_true", dest="debug")
168    parser.add_option("--glade", action="store", type="string",
169                      default=GLADE_FILE, dest="gladefile")
170    (options, args) = parser.parse_args()
171    main(options)
Note: See TracBrowser for help on using the repository browser.