Ci-dessous, les différences entre deux révisions de la page.
— |
vp-exit_ou_cb_-exit [2016/08/24 18:58] (Version actuelle) |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ===== Extinction menu pour viperr ou crunchbang++ ===== | ||
+ | Script cb-exit modifié pour qu'il prenne en charge systemd et les icone gtk. | ||
+ | Le script prend également en compte le français et l'anglais. | ||
+ | |||
+ | <code python>#!/usr/bin/env python | ||
+ | # -*- coding: cp1252 -*- | ||
+ | import pygtk | ||
+ | pygtk.require('2.0') | ||
+ | import gtk | ||
+ | import os | ||
+ | import getpass | ||
+ | import locale | ||
+ | |||
+ | LOCALE = locale.setlocale(locale.LC_ALL, "")[0:2] # 'fr' or 'en' | ||
+ | if LOCALE == 'fr': | ||
+ | LANG = 0 | ||
+ | else: | ||
+ | LANG = 1 | ||
+ | |||
+ | # Interface Language | ||
+ | class language: | ||
+ | #[label] | ||
+ | LOGOUT_ACTION_LABEL=["Déconnection d'Openbox, patientez...","Exiting Openbox, please standby..."] | ||
+ | SUSPEND_ACTION_LABEL=["Mise en veille, patientez...","Suspending, please standby..."] | ||
+ | REBOOT_ACTION_LABEL=["Redémarrage, patientez...","Rebooting, please standby..."] | ||
+ | SHUTDOWN_ACTION_LABEL=["Extinction, patientez...","Shutting down, please standby..."] | ||
+ | |||
+ | #[window] | ||
+ | TITLE=["Déconnecter %s? Choisissez une option:","Log out %s? Choose an option:"] | ||
+ | |||
+ | #[button] | ||
+ | LOGOUT_BUTTON=["_Déconnecter","_Logout"] | ||
+ | SUSPEND_BUTTON=["_Veille","_Suspend"] | ||
+ | REBOOT_BUTTON=["_Redémarrer","_Reboot"] | ||
+ | SHUTDOWN_BUTTON=["_Quitter","_Poweroff"] | ||
+ | |||
+ | class vp_exit: | ||
+ | def disable_buttons(self): | ||
+ | self.cancel.set_sensitive(False) | ||
+ | self.logout.set_sensitive(False) | ||
+ | self.suspend.set_sensitive(False) | ||
+ | self.reboot.set_sensitive(False) | ||
+ | self.shutdown.set_sensitive(False) | ||
+ | |||
+ | def cancel_action(self,btn): | ||
+ | self.disable_buttons() | ||
+ | gtk.main_quit() | ||
+ | |||
+ | def logout_action(self,btn): | ||
+ | self.disable_buttons() | ||
+ | self.status.set_label(language.LOGOUT_ACTION_LABEL[LANG]) | ||
+ | os.system("openbox --exit") | ||
+ | |||
+ | def suspend_action(self,btn): | ||
+ | self.disable_buttons() | ||
+ | self.status.set_label(language.SUSPEND_ACTION_LABEL[LANG]) | ||
+ | os.system("xscreensaver-command -lock") | ||
+ | os.system("systemctl suspend") | ||
+ | gtk.main_quit() | ||
+ | |||
+ | def reboot_action(self,btn): | ||
+ | self.disable_buttons() | ||
+ | self.status.set_label(language.REBOOT_ACTION_LABEL[LANG]) | ||
+ | os.system("systemctl reboot") | ||
+ | |||
+ | def shutdown_action(self,btn): | ||
+ | self.disable_buttons() | ||
+ | self.status.set_label(language.SHUTDOWN_ACTION_LABEL[LANG]) | ||
+ | os.system("systemctl poweroff") | ||
+ | |||
+ | def create_window(self): | ||
+ | iconsize = gtk.icon_size_register("24x24", 24, 24) | ||
+ | self.window = gtk.Window() | ||
+ | title = language.TITLE[LANG] % (getpass.getuser()) | ||
+ | self.window.set_title(title) | ||
+ | self.window.set_border_width(5) | ||
+ | self.window.set_size_request(580, 80) | ||
+ | self.window.set_resizable(False) | ||
+ | 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() | ||
+ | |||
+ | #Cancel button | ||
+ | self.cancel = gtk.Button(stock = gtk.STOCK_CANCEL) | ||
+ | self.cancel.set_border_width(4) | ||
+ | self.cancel.connect("clicked", self.cancel_action) | ||
+ | self.button_box.pack_start(self.cancel) | ||
+ | self.cancel.show() | ||
+ | |||
+ | #Logout button | ||
+ | self.logout = gtk.Button(language.LOGOUT_BUTTON[LANG]) | ||
+ | ico = gtk.Image() | ||
+ | ico.set_from_icon_name("gnome-logout", iconsize) | ||
+ | self.logout.set_image(ico) | ||
+ | self.logout.set_border_width(4) | ||
+ | self.logout.connect("clicked", self.logout_action) | ||
+ | self.button_box.pack_start(self.logout) | ||
+ | self.logout.show() | ||
+ | |||
+ | #Suspend button | ||
+ | self.suspend = gtk.Button(language.SUSPEND_BUTTON[LANG]) | ||
+ | ico = gtk.Image() | ||
+ | ico.set_from_icon_name("gnome-session-hibernate", iconsize) | ||
+ | self.suspend.set_image(ico) | ||
+ | self.suspend.set_border_width(4) | ||
+ | self.suspend.connect("clicked", self.suspend_action) | ||
+ | self.button_box.pack_start(self.suspend) | ||
+ | self.suspend.show() | ||
+ | |||
+ | #Reboot button | ||
+ | self.reboot = gtk.Button(language.REBOOT_BUTTON[LANG]) | ||
+ | ico = gtk.Image() | ||
+ | ico.set_from_icon_name("gnome-session-reboot", iconsize) | ||
+ | self.reboot.set_image(ico) | ||
+ | self.reboot.set_border_width(4) | ||
+ | self.reboot.connect("clicked", self.reboot_action) | ||
+ | self.button_box.pack_start(self.reboot) | ||
+ | self.reboot.show() | ||
+ | |||
+ | #Shutdown button | ||
+ | self.shutdown = gtk.Button(language.SHUTDOWN_BUTTON[LANG]) | ||
+ | ico = gtk.Image() | ||
+ | ico.set_from_icon_name("gnome-shutdown", iconsize) | ||
+ | self.shutdown.set_image(ico) | ||
+ | self.shutdown.set_border_width(4) | ||
+ | self.shutdown.connect("clicked", self.shutdown_action) | ||
+ | self.button_box.pack_start(self.shutdown) | ||
+ | self.shutdown.show() | ||
+ | |||
+ | #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.vbox = gtk.VBox() | ||
+ | self.vbox.pack_start(self.button_box) | ||
+ | self.vbox.pack_start(self.label_box) | ||
+ | self.vbox.show() | ||
+ | |||
+ | self.window.add(self.vbox) | ||
+ | self.window.show() | ||
+ | |||
+ | def __init__(self): | ||
+ | self.create_window() | ||
+ | |||
+ | def main(): | ||
+ | gtk.main() | ||
+ | |||
+ | if __name__ == "__main__": | ||
+ | go = vp_exit() | ||
+ | main()</code> |