2019-07-28 18:14:46 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
""" system module
|
|
|
|
|
|
|
|
adds the possibility to
|
|
|
|
* shutdown
|
|
|
|
* reboot
|
|
|
|
the system.
|
|
|
|
|
|
|
|
Per default a confirmation dialog is shown before the actual action is performed.
|
|
|
|
|
2019-12-14 13:25:58 +01:00
|
|
|
Parameters:
|
2019-07-28 18:14:46 +02:00
|
|
|
* system.confirm: show confirmation dialog before performing any action (default: true)
|
2019-12-14 13:25:58 +01:00
|
|
|
* system.reboot: specify a reboot command (defaults to 'reboot')
|
|
|
|
* system.shutdown: specify a shutdown command (defaults to 'shutdown -h now')
|
|
|
|
* system.logout: specify a logout command (defaults to 'i3exit logout')
|
|
|
|
* system.switch_user: specify a command for switching the user (defaults to 'i3exit switch_user')
|
|
|
|
* system.lock: specify a command for locking the screen (defaults to 'i3exit lock')
|
|
|
|
* system.suspend: specify a command for suspending (defaults to 'i3exit suspend')
|
|
|
|
* system.hibernate: specify a command for hibernating (defaults to 'i3exit hibernate')
|
2019-07-28 18:14:46 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
import bumblebee.popup_v2
|
|
|
|
import functools
|
|
|
|
|
|
|
|
try:
|
|
|
|
import Tkinter as tk
|
|
|
|
import tkMessageBox as tkmessagebox
|
|
|
|
except ImportError:
|
|
|
|
# python 3
|
|
|
|
try:
|
|
|
|
import tkinter as tk
|
|
|
|
from tkinter import messagebox as tkmessagebox
|
|
|
|
except ImportError:
|
|
|
|
logging.warning("failed to import tkinter - bumblebee popups won't work!")
|
|
|
|
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.text)
|
|
|
|
)
|
|
|
|
|
|
|
|
self._confirm = True
|
|
|
|
if self.parameter("confirm", "true") == "false":
|
|
|
|
self._confirm = False
|
|
|
|
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
|
|
cmd=self.popup)
|
|
|
|
|
|
|
|
def update(self, widgets):
|
2019-07-28 18:17:29 +02:00
|
|
|
pass
|
2019-07-28 18:14:46 +02:00
|
|
|
|
|
|
|
def text(self, widget):
|
2019-07-28 18:17:29 +02:00
|
|
|
return ""
|
2019-07-28 18:14:46 +02:00
|
|
|
|
|
|
|
def _on_command(self, header, text, command):
|
|
|
|
do_it = True
|
|
|
|
if self._confirm:
|
|
|
|
root = tk.Tk()
|
|
|
|
root.withdraw()
|
|
|
|
root.focus_set()
|
|
|
|
|
|
|
|
do_it = tkmessagebox.askyesno(header, text)
|
2019-07-28 18:19:49 +02:00
|
|
|
root.destroy()
|
2019-07-28 18:14:46 +02:00
|
|
|
|
|
|
|
if do_it:
|
2019-07-28 18:19:49 +02:00
|
|
|
bumblebee.util.execute(command)
|
2019-07-28 18:14:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def popup(self, widget):
|
|
|
|
menu = bumblebee.popup_v2.PopupMenu()
|
2019-12-14 13:25:58 +01:00
|
|
|
reboot_cmd = self.parameter("reboot", "reboot")
|
|
|
|
shutdown_cmd = self.parameter("shutdown", "shutdown -h now")
|
|
|
|
logout_cmd = self.parameter("logout", "i3exit logout")
|
|
|
|
switch_user_cmd = self.parameter("switch_user", "i3exit switch_user")
|
|
|
|
lock_cmd = self.parameter("lock", "i3exit lock")
|
|
|
|
suspend_cmd = self.parameter("suspend", "i3exit suspend")
|
|
|
|
hibernate_cmd = self.parameter("hibernate", "i3exit hibernate")
|
|
|
|
|
|
|
|
menu.add_menuitem("shutdown", callback=functools.partial(self._on_command, "Shutdown", "Shutdown?", shutdown_cmd))
|
|
|
|
menu.add_menuitem("reboot", callback=functools.partial(self._on_command, "Reboot", "Reboot?", reboot_cmd))
|
2019-08-20 13:27:12 +02:00
|
|
|
menu.add_menuitem("log out", callback=functools.partial(self._on_command, "Log out", "Log out?", "i3exit logout"))
|
|
|
|
# don't ask for these
|
2019-12-14 13:25:58 +01:00
|
|
|
menu.add_menuitem("switch user", callback=functools.partial(bumblebee.util.execute, switch_user_cmd))
|
|
|
|
menu.add_menuitem("lock", callback=functools.partial(bumblebee.util.execute, lock_cmd))
|
|
|
|
menu.add_menuitem("suspend", callback=functools.partial(bumblebee.util.execute, suspend_cmd))
|
|
|
|
menu.add_menuitem("hibernate", callback=functools.partial(bumblebee.util.execute, hibernate_cmd))
|
2019-07-28 18:14:46 +02:00
|
|
|
|
|
|
|
menu.show(widget)
|
|
|
|
|
|
|
|
def state(self, widget):
|
|
|
|
return []
|