[24213] | 1 | #!/usr/bin/python -Wall |
---|
| 2 | |
---|
| 3 | import gtk |
---|
| 4 | import gtk.glade |
---|
| 5 | import gobject |
---|
| 6 | import time |
---|
| 7 | import os |
---|
| 8 | import sys |
---|
| 9 | import subprocess |
---|
| 10 | from optparse import OptionParser |
---|
| 11 | |
---|
| 12 | gladeFile = "/usr/share/debathena-kiosk/gdm-launch-kiosk.glade" |
---|
| 13 | launchCommand = "/usr/lib/debathena-kiosk/launch-kiosk" |
---|
| 14 | |
---|
| 15 | class Kiosk: |
---|
| 16 | def __init__(self): |
---|
| 17 | try: |
---|
| 18 | self.xml = gtk.glade.XML(gladeFile) |
---|
| 19 | except: |
---|
| 20 | print "Failed to create Glade XML object." |
---|
| 21 | sys.exit(1) |
---|
| 22 | self.kioskWindow = self.xml.get_widget('KioskWindow') |
---|
| 23 | self.kioskDialog = self.xml.get_widget('KioskDialog') |
---|
| 24 | self.xml.signal_autoconnect(self) |
---|
| 25 | # Turn off all window decorations for the login screen. |
---|
| 26 | self.kioskWindow.set_decorated(False) |
---|
| 27 | self.kioskDialog.set_decorated(False) |
---|
| 28 | # Position the window near the bottom of the screen, in the center. |
---|
| 29 | self.kioskWindow.set_gravity(gtk.gdk.GRAVITY_SOUTH) |
---|
| 30 | width, height = self.kioskWindow.get_size() |
---|
| 31 | self.kioskWindow.move((gtk.gdk.screen_width() - width) / 2, |
---|
| 32 | gtk.gdk.screen_height() - height - 80) |
---|
| 33 | self.kioskWindow.show_all() |
---|
| 34 | |
---|
| 35 | def kioskButton_on_click(self, button): |
---|
| 36 | self.kioskDialog.show() |
---|
| 37 | |
---|
| 38 | def kioskDialogResponseHandler(self, dialog, response_id): |
---|
| 39 | if response_id == 1: |
---|
| 40 | self.launch() |
---|
| 41 | self.kioskDialog.hide() |
---|
| 42 | |
---|
| 43 | def launch(self): |
---|
| 44 | pid = os.fork() |
---|
| 45 | if pid == 0: |
---|
| 46 | # Start a new session. |
---|
| 47 | os.setsid(); |
---|
| 48 | # Fork another child to launch the command. |
---|
| 49 | pid = os.fork() |
---|
| 50 | if pid == 0: |
---|
| 51 | # Here in the second child, exec the command. |
---|
| 52 | try: |
---|
| 53 | os.execlp("sudo", "sudo", "-n", launchCommand) |
---|
| 54 | except OSError, e: |
---|
| 55 | print "error: Could not run %s as root: %s" % (launchCommand, e.strerror) |
---|
| 56 | os._exit(255) |
---|
| 57 | else: |
---|
| 58 | # The first child exits immediately. |
---|
| 59 | os._exit(0) |
---|
| 60 | else: |
---|
| 61 | # Here in the parent: wait for the first child to exit. |
---|
| 62 | (pid, status) = os.waitpid(pid, 0) |
---|
| 63 | if status != 0: |
---|
| 64 | print "error launching command, status %d" % status |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | def main(): |
---|
| 68 | if not os.access(gladeFile, os.R_OK): |
---|
| 69 | print 'error: Unable to read glade file "' + gladeFile + '"' |
---|
| 70 | sys.exit(1) |
---|
| 71 | Kiosk() |
---|
| 72 | gtk.main() |
---|
| 73 | |
---|
| 74 | if __name__ == '__main__': |
---|
| 75 | main() |
---|