Advertisement
Kimarite

cb-exit (CrunchBang Waldorf)

Jan 1st, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # https://pythonhosted.org/kitchen/unicode-frustrations.html
  4. import pygtk
  5. pygtk.require('2.0')
  6. import gtk
  7. import os
  8. import getpass
  9. import unicodedata
  10.  
  11. class cb_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 Openbox, please standby...")
  26. os.system("openbox --exit")
  27.  
  28. def suspend_action(self,btn):
  29. self.disable_buttons()
  30. self.status.set_label("Suspending, please standby...")
  31. os.system("cb-lock")
  32. os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.UPower\" /org/freedesktop/UPower org.freedesktop.UPower.Suspend")
  33. gtk.main_quit()
  34.  
  35. def reboot_action(self,btn):
  36. self.disable_buttons()
  37. self.status.set_label("Rebooting, please standby...")
  38. os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart")
  39.  
  40. def shutdown_action(self,btn):
  41. self.disable_buttons()
  42. self.status.set_label("Shutting down, please standby...")
  43. os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.ConsoleKit\" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop")
  44.  
  45. def create_window(self):
  46. self.window = gtk.Window()
  47. title = "Kijelentkezel " + getpass.getuser() + "? Válassz a lehetőségekből:"
  48. self.window.set_title(title)
  49. self.window.set_border_width(5)
  50. self.window.set_size_request(500, 80)
  51. self.window.set_resizable(False)
  52. self.window.set_keep_above(True)
  53. self.window.stick
  54. self.window.set_position(1)
  55. self.window.connect("delete_event", gtk.main_quit)
  56. windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
  57. self.window.set_icon(windowicon)
  58.  
  59.  
  60. #Create HBox for buttons
  61. self.button_box = gtk.HBox()
  62. self.button_box.show()
  63.  
  64. #Cancel button
  65. self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL)
  66. self.cancel.set_border_width(4)
  67. self.cancel.connect("clicked", self.cancel_action)
  68. self.button_box.pack_start(self.cancel)
  69. self.cancel.show()
  70.  
  71. #Logout button
  72. self.logout = gtk.Button("_Kijelentkezés")
  73. self.logout.set_border_width(4)
  74. self.logout.connect("clicked", self.logout_action)
  75. self.button_box.pack_start(self.logout)
  76. self.logout.show()
  77.  
  78. #Suspend button
  79. self.suspend = gtk.Button("_Suspend")
  80. self.suspend.set_border_width(4)
  81. self.suspend.connect("clicked", self.suspend_action)
  82. self.button_box.pack_start(self.suspend)
  83. #self.suspend.show()
  84.  
  85. #Reboot button
  86. self.reboot = gtk.Button("_Újrainditás")
  87. self.reboot.set_border_width(4)
  88. self.reboot.connect("clicked", self.reboot_action)
  89. self.button_box.pack_start(self.reboot)
  90. self.reboot.show()
  91.  
  92. #Shutdown button
  93. self.shutdown = gtk.Button("_Kikapcsolás")
  94. self.shutdown.set_border_width(4)
  95. self.shutdown.connect("clicked", self.shutdown_action)
  96. self.button_box.pack_start(self.shutdown)
  97. self.shutdown.show()
  98.  
  99. #Create HBox for status label
  100. self.label_box = gtk.HBox()
  101. self.label_box.show()
  102. self.status = gtk.Label()
  103. self.status.show()
  104. self.label_box.pack_start(self.status)
  105.  
  106. #Create VBox and pack the above HBox's
  107. self.vbox = gtk.VBox()
  108. self.vbox.pack_start(self.button_box)
  109. self.vbox.pack_start(self.label_box)
  110. self.vbox.show()
  111.  
  112. self.window.add(self.vbox)
  113. self.window.show()
  114.  
  115. def __init__(self):
  116. self.create_window()
  117.  
  118.  
  119. def main():
  120. gtk.main()
  121.  
  122. if __name__ == "__main__":
  123. go = cb_exit()
  124. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement