[24816] | 1 | #!/usr/bin/python -Wall |
---|
| 2 | |
---|
| 3 | import dbus |
---|
| 4 | import dbus.mainloop.glib |
---|
| 5 | import gtk |
---|
[24817] | 6 | import gtk.glade |
---|
[24816] | 7 | import gobject |
---|
[24817] | 8 | import sys |
---|
[24816] | 9 | import os |
---|
| 10 | import subprocess |
---|
[24917] | 11 | import platform |
---|
[25221] | 12 | from optparse import OptionParser |
---|
[24816] | 13 | |
---|
| 14 | SM_DBUS_NAME = "org.gnome.SessionManager" |
---|
| 15 | SM_DBUS_PATH = "/org/gnome/SessionManager" |
---|
| 16 | SM_DBUS_INTERFACE = "org.gnome.SessionManager" |
---|
| 17 | SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate" |
---|
| 18 | APP_ID = "debathena-branding" |
---|
[24818] | 19 | GLADE_FILE="/usr/share/debathena-branding/debathena-branding.glade" |
---|
[25410] | 20 | DEBATHENA_LOGO_FILES=["/usr/share/pixmaps/debathena.png", |
---|
[25409] | 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"] |
---|
[24816] | 29 | |
---|
| 30 | class Branding: |
---|
[25409] | 31 | animation_loop_frames = 150 |
---|
| 32 | |
---|
[25221] | 33 | def __init__(self, options): |
---|
| 34 | self.debug = options.debug |
---|
[24816] | 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." |
---|
[24817] | 42 | |
---|
| 43 | try: |
---|
[25221] | 44 | self.xml = gtk.glade.XML(options.gladefile) |
---|
[24817] | 45 | except: |
---|
[25221] | 46 | print "Could not load Glade XML: %s" % (options.gladefile) |
---|
[24817] | 47 | sys.exit(1) |
---|
[24816] | 48 | |
---|
[24817] | 49 | |
---|
| 50 | self.winWelcome = self.xml.get_widget('winWelcome') |
---|
[24979] | 51 | self.winWelcome.set_property('can_focus', False) |
---|
[25581] | 52 | # Multiple monitor support. Use the primary monitor. |
---|
[25579] | 53 | defaultScreen = gtk.gdk.screen_get_default() |
---|
| 54 | self.monitorGeometry = defaultScreen.get_monitor_geometry(defaultScreen.get_primary_monitor()) |
---|
| 55 | moveY = self.monitorGeometry.y + 200 |
---|
[24840] | 56 | logoScale = 0.60 |
---|
[25579] | 57 | if (self.monitorGeometry.height - self.monitorGeometry.y) <= 900: |
---|
| 58 | moveY = self.monitorGeometry.y + 10 |
---|
[24840] | 59 | logoScale = 0.40 |
---|
[25579] | 60 | moveX = self.monitorGeometry.x + ((self.monitorGeometry.width - self.winWelcome.get_size()[0]) / 2) |
---|
| 61 | self.winWelcome.move(moveX, moveY) |
---|
[24817] | 62 | self.imgDebathena = self.xml.get_widget('imgDebathena') |
---|
[24979] | 63 | self.imgDebathena.set_property('can_focus', False) |
---|
[25409] | 64 | self.animate = self.setup_owl(logoScale) |
---|
[24817] | 65 | self.winBranding = self.xml.get_widget('winBranding') |
---|
[24979] | 66 | self.winBranding.set_property('can_focus', False) |
---|
[24817] | 67 | self.lblBranding = self.xml.get_widget('lblBranding') |
---|
[24979] | 68 | self.lblBranding.set_property('can_focus', False) |
---|
[24817] | 69 | try: |
---|
[24816] | 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)' |
---|
[24919] | 77 | arch = platform.machine() |
---|
| 78 | if arch != "x86_64": |
---|
| 79 | arch = "<b>" + arch + "</b>" |
---|
| 80 | self.lblBranding.set_markup(metapackage + "\n" + baseos + "\n" + arch) |
---|
[24817] | 81 | self.winBranding.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST) |
---|
| 82 | width, height = self.winBranding.get_size() |
---|
[25579] | 83 | self.winBranding.move(self.monitorGeometry.x + (self.monitorGeometry.width - width), self.monitorGeometry.y + (self.monitorGeometry.height - height)) |
---|
[24816] | 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 | |
---|
[25409] | 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 |
---|
[25410] | 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 |
---|
[25409] | 114 | |
---|
[25410] | 115 | except: |
---|
| 116 | # Just don't display the image if it's missing |
---|
| 117 | return False |
---|
| 118 | |
---|
[25409] | 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)) |
---|
[25493] | 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]) |
---|
[25409] | 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 | |
---|
[24816] | 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): |
---|
[25254] | 161 | subprocess.call(["/usr/bin/pkill", "-f", "gnome-settings-daemon"]) |
---|
[24816] | 162 | gtk.main_quit() |
---|
| 163 | |
---|
[25221] | 164 | def main(options): |
---|
[24816] | 165 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
---|
[25409] | 166 | branding = Branding(options) |
---|
| 167 | gobject.timeout_add(50, branding.update_owl) |
---|
[24816] | 168 | gtk.main() |
---|
| 169 | |
---|
| 170 | if __name__ == '__main__': |
---|
[25221] | 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) |
---|