Guest User

i3-exit

a guest
Apr 9th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # based on cb-exit used in CrunchBang Linux <http://crunchbanglinux.org/>
  4.  
  5. import pygtk
  6. pygtk.require('2.0')
  7. import gtk
  8. import os
  9. import getpass
  10.  
  11. class i3_exit:
  12.     def disable_buttons(self):
  13.         self.cancel.set_sensitive(False)
  14.         self.logout.set_sensitive(False)
  15.         self.suspend.set_sensitive(False)
  16.         self.reboot.set_sensitive(False)
  17.         self.shutdown.set_sensitive(False)
  18.  
  19.     def cancel_action(self,btn):
  20.         self.disable_buttons()
  21.         gtk.main_quit()
  22.  
  23.     def logout_action(self,btn):
  24.         self.disable_buttons()
  25.         self.status.set_label("Exiting i3, please standby...")
  26.         os.system("i3-msg exit")
  27.  
  28.     def lock_action(self, btn):
  29.         self.disable_buttons()
  30.         self.status.set_label("Locking, please standby...")
  31.         os.system("i3lock")
  32.         gtk.main_quit()
  33.  
  34.     def suspend_action(self,btn):
  35.         self.disable_buttons()
  36.         self.status.set_label("Suspending, please standby...")
  37.         os.system("i3lock")
  38.         os.system("dbus-send --system --print-reply \
  39.                --dest=\"org.freedesktop.UPower\"   \
  40.                /org/freedesktop/UPower             \
  41.                org.freedesktop.UPower.Suspend")
  42.         gtk.main_quit()
  43.  
  44.     def reboot_action(self,btn):
  45.         self.disable_buttons()
  46.         self.status.set_label("Rebooting, please standby...")
  47.         os.system("dbus-send --system --print-reply   \
  48.                --dest=\"org.freedesktop.ConsoleKit\" \
  49.                /org/freedesktop/ConsoleKit/Manager   \
  50.                org.freedesktop.ConsoleKit.Manager.Restart")
  51.  
  52.     def shutdown_action(self,btn):
  53.         self.disable_buttons()
  54.         self.status.set_label("Shutting down, please standby...")
  55.         os.system("dbus-send --system --print-reply   \
  56.                --dest=\"org.freedesktop.ConsoleKit\" \
  57.                /org/freedesktop/ConsoleKit/Manager   \
  58.                org.freedesktop.ConsoleKit.Manager.Stop")
  59.  
  60.     def create_window(self):
  61.         self.window = gtk.Window()
  62.         title = "Log out " + getpass.getuser() + "? Choose an option:"
  63.         self.window.set_title(title)
  64.         self.window.set_border_width(5)
  65.         self.window.set_size_request(500, 80)
  66.         self.window.set_resizable(False)
  67.         self.window.set_keep_above(True)
  68.         self.window.stick
  69.         self.window.set_position(1)
  70.         self.window.connect("delete_event", gtk.main_quit)
  71.         windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
  72.         self.window.set_icon(windowicon)
  73.  
  74.  
  75.         #Create HBox for buttons
  76.         self.button_box = gtk.HBox()
  77.         self.button_box.show()
  78.  
  79.         #Cancel button
  80.         self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
  81.         self.cancel.set_border_width(4)
  82.         self.cancel.connect("clicked", self.cancel_action)
  83.         self.button_box.pack_start(self.cancel)
  84.         self.cancel.show()
  85.  
  86.         self.lock = gtk.Button("Lock screen")
  87.         self.lock.set_border_width(4)
  88.         self.lock.connect("clicked", self.lock_action)
  89.         self.button_box.pack_start(self.lock)
  90.         self.lock.show()
  91.  
  92.         #Logout button
  93.         self.logout = gtk.Button("_Log out")
  94.         self.logout.set_border_width(4)
  95.         self.logout.connect("clicked", self.logout_action)
  96.         self.button_box.pack_start(self.logout)
  97.         self.logout.show()
  98.  
  99.         #Suspend button
  100.         self.suspend = gtk.Button("_Suspend")
  101.         self.suspend.set_border_width(4)
  102.         self.suspend.connect("clicked", self.suspend_action)
  103.         self.button_box.pack_start(self.suspend)
  104.         self.suspend.show()
  105.  
  106.         #Reboot button
  107.         self.reboot = gtk.Button("_Reboot")
  108.         self.reboot.set_border_width(4)
  109.         self.reboot.connect("clicked", self.reboot_action)
  110.         self.button_box.pack_start(self.reboot)
  111.         self.reboot.show()
  112.  
  113.         #Shutdown button
  114.         self.shutdown = gtk.Button("_Power off")
  115.         self.shutdown.set_border_width(4)
  116.         self.shutdown.connect("clicked", self.shutdown_action)
  117.         self.button_box.pack_start(self.shutdown)
  118.         self.shutdown.show()
  119.  
  120.         #Create HBox for status label
  121.         self.label_box = gtk.HBox()
  122.         self.label_box.show()
  123.         self.status = gtk.Label()
  124.         self.status.show()
  125.         self.label_box.pack_start(self.status)
  126.  
  127.         #Create VBox and pack the above HBox's
  128.         self.vbox = gtk.VBox()
  129.         self.vbox.pack_start(self.button_box)
  130.         self.vbox.pack_start(self.label_box)
  131.         self.vbox.show()
  132.  
  133.         self.window.add(self.vbox)
  134.         self.window.show()
  135.  
  136.     def __init__(self):
  137.         self.create_window()
  138.  
  139.  
  140. def main():
  141.     gtk.main()
  142.  
  143. if __name__ == "__main__":
  144.     go = i3_exit()
  145.     main()
Advertisement
Add Comment
Please, Sign In to add comment