Advertisement
learnlinuxtv

Untitled

Oct 16th, 2019
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.06 KB | None | 0 0
  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. class cb_exit:
  10.     def disable_buttons(self):
  11.         self.cancel.set_sensitive(False)
  12.         self.logout.set_sensitive(False)
  13.         self.suspend.set_sensitive(False)
  14.         self.reboot.set_sensitive(False)
  15.         self.shutdown.set_sensitive(False)
  16.  
  17.     def cancel_action(self,btn):
  18.         self.disable_buttons()
  19.         gtk.main_quit()
  20.  
  21.     def logout_action(self,btn):
  22.         self.disable_buttons()
  23.         self.status.set_label("Exiting Openbox, please standby...")
  24.         os.system("openbox --exit")
  25.  
  26.     def suspend_action(self,btn):
  27.             self.disable_buttons()
  28.             self.status.set_label("Suspending, please standby...")
  29.             os.system("light-locker-command -l")
  30.             os.system("sleep 1")
  31.             os.system("systemctl 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("systemctl reboot")
  38.  
  39.     def shutdown_action(self,btn):
  40.             self.disable_buttons()
  41.             self.status.set_label("Shutting down, please standby...")
  42.             os.system("systemctl poweroff")
  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.  
  59.             #Create HBox for buttons
  60.             self.button_box = gtk.HBox()
  61.             self.button_box.show()
  62.  
  63.             #Cancel button
  64.             self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
  65.             self.cancel.set_border_width(4)
  66.             self.cancel.connect("clicked", self.cancel_action)
  67.             self.button_box.pack_start(self.cancel)
  68.             self.cancel.show()
  69.  
  70.             #Logout button
  71.             self.logout = gtk.Button("_Log out")
  72.             self.logout.set_border_width(4)
  73.             self.logout.connect("clicked", self.logout_action)
  74.             self.button_box.pack_start(self.logout)
  75.             self.logout.show()
  76.  
  77.             #Suspend button
  78.             self.suspend = gtk.Button("_Suspend")
  79.             self.suspend.set_border_width(4)
  80.             self.suspend.connect("clicked", self.suspend_action)
  81.             self.button_box.pack_start(self.suspend)
  82.             self.suspend.show()
  83.  
  84.             #Reboot button
  85.             self.reboot = gtk.Button("_Reboot")
  86.             self.reboot.set_border_width(4)
  87.             self.reboot.connect("clicked", self.reboot_action)
  88.             self.button_box.pack_start(self.reboot)
  89.             self.reboot.show()
  90.  
  91.             #Shutdown button
  92.             self.shutdown = gtk.Button("_Power off")
  93.             self.shutdown.set_border_width(4)
  94.             self.shutdown.connect("clicked", self.shutdown_action)
  95.             self.button_box.pack_start(self.shutdown)
  96.             self.shutdown.show()
  97.  
  98.             #Create HBox for status label
  99.             self.label_box = gtk.HBox()
  100.             self.label_box.show()
  101.             self.status = gtk.Label()
  102.             self.status.show()
  103.             self.label_box.pack_start(self.status)
  104.  
  105.             #Create VBox and pack the above HBox's
  106.             self.vbox = gtk.VBox()
  107.             self.vbox.pack_start(self.button_box)
  108.             self.vbox.pack_start(self.label_box)
  109.             self.vbox.show()
  110.  
  111.             self.window.add(self.vbox)
  112.             self.window.show()
  113.  
  114.     def __init__(self):
  115.         self.create_window()
  116.  
  117.  
  118. def main():
  119.     gtk.main()
  120.  
  121. if __name__ == "__main__":
  122.     go = cb_exit()
  123.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement