Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

cb-exit: Improved PEP8 compliance

By: G4Oblivion on May 7th, 2012  |  syntax: Python  |  size: 4.11 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2.  
  3. import pygtk
  4. pygtk.require('2.0')
  5. import gtk
  6. import os
  7. import getpass
  8.  
  9.  
  10. class cb_exit:
  11.     def disable_buttons(self):
  12.         self.cancel.set_sensitive(False)
  13.         self.logout.set_sensitive(False)
  14.         self.suspend.set_sensitive(False)
  15.         self.reboot.set_sensitive(False)
  16.         self.shutdown.set_sensitive(False)
  17.  
  18.     def cancel_action(self, btn):
  19.         self.disable_buttons()
  20.         gtk.main_quit()
  21.  
  22.     def logout_action(self, btn):
  23.         self.disable_buttons()
  24.         self.status.set_label("Exiting Openbox, please standby...")
  25.         os.system("openbox --exit")
  26.  
  27.     def suspend_action(self, btn):
  28.         self.disable_buttons()
  29.         self.status.set_label("Suspending, please standby...")
  30.         os.system("cb-lock")
  31.         os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.UPower\" /org/freedesktop/UPower org.freedesktop.UPower.Suspend")
  32.         gtk.main_quit()
  33.  
  34.     def reboot_action(self, btn):
  35.         self.disable_buttons()
  36.         self.status.set_label("Rebooting, please standby...")
  37.         os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart")
  38.  
  39.     def shutdown_action(self, btn):
  40.         self.disable_buttons()
  41.         self.status.set_label("Shutting down, please standby...")
  42.         os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop")
  43.  
  44.     def create_window(self):
  45.         self.window = gtk.Window()
  46.         title = "Log out " + getpass.getuser() + "? Choose an option:"
  47.         self.window.set_title(title)
  48.         self.window.set_border_width(5)
  49.         self.window.set_size_request(500, 80)
  50.         self.window.set_resizable(False)
  51.         self.window.set_keep_above(True)
  52.         self.window.stick()
  53.         self.window.set_position(1)
  54.         self.window.connect("delete_event", gtk.main_quit)
  55.         windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
  56.         self.window.set_icon(windowicon)
  57.  
  58.         #Create HBox for buttons
  59.         self.button_box = gtk.HBox()
  60.         self.button_box.show()
  61.  
  62.         #Cancel button
  63.         self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL)
  64.         self.cancel.set_border_width(4)
  65.         self.cancel.connect("clicked", self.cancel_action)
  66.         self.button_box.pack_start(self.cancel)
  67.         self.cancel.show()
  68.  
  69.         #Logout button
  70.         self.logout = gtk.Button("_Log out")
  71.         self.logout.set_border_width(4)
  72.         self.logout.connect("clicked", self.logout_action)
  73.         self.button_box.pack_start(self.logout)
  74.         self.logout.show()
  75.  
  76.         #Suspend button
  77.         self.suspend = gtk.Button("_Suspend")
  78.         self.suspend.set_border_width(4)
  79.         self.suspend.connect("clicked", self.suspend_action)
  80.         self.button_box.pack_start(self.suspend)
  81.         self.suspend.show()
  82.  
  83.         #Reboot button
  84.         self.reboot = gtk.Button("_Reboot")
  85.         self.reboot.set_border_width(4)
  86.         self.reboot.connect("clicked", self.reboot_action)
  87.         self.button_box.pack_start(self.reboot)
  88.         self.reboot.show()
  89.  
  90.         #Shutdown button
  91.         self.shutdown = gtk.Button("_Power off")
  92.         self.shutdown.set_border_width(4)
  93.         self.shutdown.connect("clicked", self.shutdown_action)
  94.         self.button_box.pack_start(self.shutdown)
  95.         self.shutdown.show()
  96.  
  97.         #Create HBox for status label
  98.         self.label_box = gtk.HBox()
  99.         self.label_box.show()
  100.         self.status = gtk.Label()
  101.         self.status.show()
  102.         self.label_box.pack_start(self.status)
  103.  
  104.         #Create VBox and pack the above HBox's
  105.         self.vbox = gtk.VBox()
  106.         self.vbox.pack_start(self.button_box)
  107.         self.vbox.pack_start(self.label_box)
  108.         self.vbox.show()
  109.  
  110.         self.window.add(self.vbox)
  111.         self.window.show()
  112.  
  113.     def __init__(self):
  114.         self.create_window()
  115.  
  116.  
  117. def main():
  118.     gtk.main()
  119.  
  120. if __name__ == "__main__":
  121.     go = cb_exit()
  122.     main()