daily pastebin goal
11%
SHARE
TWEET

icewm-logout

a guest Apr 21st, 2011 442 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import pygtk
  5. pygtk.require('2.0')
  6. import gtk
  7. import os
  8.  
  9. class DoTheLogOut:
  10.  
  11.     # Cancel/exit
  12.     def delete_event(self, widget, event, data=None):
  13.         gtk.main_quit()
  14.         return False
  15.  
  16.     # Hibernate
  17.     def hibernate(self, widget):
  18.         os.system("sleep 1s && dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate")
  19.  
  20.     # Suspend
  21.     def suspend(self, widget):
  22.         os.system("sleep 1s && dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0")
  23.  
  24.     # Logout
  25.     def logout(self, widget):
  26.         os.system("killall icewm-session")
  27.  
  28.     # Reboot
  29.     def reboot(self, widget):
  30.         os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart")
  31.  
  32.     # Shutdown
  33.     def shutdown(self, widget):
  34.         os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop")
  35.  
  36.     def __init__(self):
  37.         # Create a new window
  38.         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  39.         self.window.set_title("Exit? Choose an option:")
  40.         self.window.set_resizable(False)
  41.         self.window.set_position(1)
  42.         self.window.connect("delete_event", self.delete_event)
  43.         self.window.set_border_width(15)
  44.  
  45.         # Create a box to pack widgets into
  46.         self.box1 = gtk.HBox(False, 0)
  47.         self.window.add(self.box1)
  48.  
  49.         # Create cancel button
  50.         self.button1 = gtk.Button("_Cancel")
  51.         self.button1.set_border_width(5)
  52.         self.button1.connect("clicked", self.delete_event, "Never mind :)")
  53.         self.box1.pack_start(self.button1, True, True, 0)
  54.         self.button1.show()
  55.  
  56.         # Create hibernate button
  57.         self.button2 = gtk.Button("_Hibernate")
  58.         self.button2.set_border_width(5)
  59.         self.button2.connect("clicked", self.hibernate)
  60.         self.box1.pack_start(self.button2, True, True, 0)
  61.         self.button2.show()
  62.  
  63.         # Create suspend button
  64.         self.button3 = gtk.Button("S_uspend")
  65.         self.button3.set_border_width(5)
  66.         self.button3.connect("clicked", self.suspend)
  67.         self.box1.pack_start(self.button3, True, True, 0)
  68.         self.button3.show()
  69.  
  70.         # Create logout button
  71.         self.button4 = gtk.Button("_Log out")
  72.         self.button4.set_border_width(5)
  73.         self.button4.connect("clicked", self.logout)
  74.         self.box1.pack_start(self.button4, True, True, 0)
  75.         self.button4.show()
  76.  
  77.         # Create reboot button
  78.         self.button5 = gtk.Button("_Reboot")
  79.         self.button5.set_border_width(5)
  80.         self.button5.connect("clicked", self.reboot)
  81.         self.box1.pack_start(self.button5, True, True, 0)
  82.         self.button5.show()
  83.  
  84.         # Create shutdown button
  85.         self.button6 = gtk.Button("_Shutdown")
  86.         self.button6.set_border_width(5)
  87.         self.button6.connect("clicked", self.shutdown)
  88.         self.box1.pack_start(self.button6, True, True, 0)
  89.         self.button6.show()
  90.  
  91.         self.box1.show()
  92.         self.window.show()
  93.  
  94. def main():
  95.     gtk.main()
  96.  
  97. if __name__ == "__main__":
  98.     gogogo = DoTheLogOut()
  99.     main()
RAW Paste Data
Top