Skip to content

Instantly share code, notes, and snippets.

@dece
Created May 21, 2017 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dece/c39e52ec5e1afc292dd8da2a80686fe2 to your computer and use it in GitHub Desktop.
Save dece/c39e52ec5e1afc292dd8da2a80686fe2 to your computer and use it in GitHub Desktop.
ObExit - Adaptation of the original cb-exit script found in the Crunchbang distribution to work with SystemD
#!/usr/bin/env python
""" Adaptation of the original cb-exit script found in the Crunchbang
distribution to work with SystemD.
I replaced "cb" with "ob" to match the Openbox tool names (obconf, obmenu)
because that script fits well with the Openbox WM.
"""
import os
import gtk
import pygtk
pygtk.require('2.0')
class Button(gtk.Button):
def __init__(self, parent, label, action):
super(Button, self).__init__(label)
self.set_border_width(4)
self.connect("clicked", action)
parent.pack_start(self)
self.show()
class ExitWindow(object):
def __init__(self):
self.window = gtk.Window()
self.window.set_title("Exit?")
self.window.set_border_width(5)
self.window.set_size_request(600, 80)
self.window.set_resizable(True)
self.window.set_keep_above(True)
self.window.stick
self.window.set_position(1)
self.window.connect("delete_event", gtk.main_quit)
windowicon = self.window.render_icon(gtk.STOCK_QUIT, gtk.ICON_SIZE_MENU)
self.window.set_icon(windowicon)
# Create HBox for buttons
self.button_box = gtk.HBox()
self.button_box.show()
self.logout = Button(self.button_box, "_Log out", self.logout_action)
self.suspend = Button(self.button_box, "_Suspend", self.suspend_action)
self.hibernate = Button(self.button_box, "_Hibernate", self.hibernate_action)
self.reboot = Button(self.button_box, "_Reboot", self.reboot_action)
self.shutdown = Button(self.button_box, "_Power off", self.shutdown_action)
self.cancel = Button(self.button_box, "_Cancel", self.cancel_action)
# Create HBox for status label
self.label_box = gtk.HBox()
self.label_box.show()
self.status = gtk.Label()
self.status.show()
self.label_box.pack_start(self.status)
# Create VBox and pack the above HBox's
self.main_layout = gtk.VBox()
self.main_layout.pack_start(self.button_box)
self.main_layout.pack_start(self.label_box)
self.main_layout.show()
self.window.add(self.main_layout)
self.window.show()
def disable_buttons(self):
self.logout.set_sensitive(False)
self.suspend.set_sensitive(False)
self.hibernate.set_sensitive(False)
self.reboot.set_sensitive(False)
self.shutdown.set_sensitive(False)
self.cancel.set_sensitive(False)
def logout_action(self, button):
self.disable_buttons()
self.status.set_label("Exiting Openbox, please standby...")
os.system("openbox --exit")
def suspend_action(self, button):
self.disable_buttons()
self.status.set_label("Suspending, please standby...")
os.system("cb-lock")
os.system("systemctl suspend")
gtk.main_quit()
def hibernate_action(self, button):
self.disable_buttons()
self.status.set_label("Hibernating, please standby...")
os.system("cb-lock")
os.system("systemctl hibernate")
gtk.main_quit()
def reboot_action(self, button):
self.disable_buttons()
self.status.set_label("Rebooting, please standby...")
os.system("systemctl reboot")
def shutdown_action(self, button):
self.disable_buttons()
self.status.set_label("Shutting down, please standby...")
os.system("systemctl poweroff")
def cancel_action(self, button):
self.disable_buttons()
gtk.main_quit()
def main():
exit_window = ExitWindow()
gtk.main()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment