commit
ebd97a9495
4 changed files with 89 additions and 3 deletions
77
bumblebee/modules/system.py
Normal file
77
bumblebee/modules/system.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
# -*- 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.
|
||||
|
||||
Paramters:
|
||||
* system.confirm: show confirmation dialog before performing any action (default: true)
|
||||
"""
|
||||
|
||||
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):
|
||||
pass
|
||||
|
||||
def text(self, widget):
|
||||
return ""
|
||||
|
||||
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)
|
||||
root.destroy()
|
||||
|
||||
if do_it:
|
||||
bumblebee.util.execute(command)
|
||||
|
||||
|
||||
def popup(self, widget):
|
||||
menu = bumblebee.popup_v2.PopupMenu()
|
||||
menu.add_menuitem("shutdown", callback=functools.partial(self._on_command, "Shutdown", "Shutdown?", "shutdown -h now"))
|
||||
menu.add_menuitem("reboot", callback=functools.partial(self._on_command, "Reboot", "Reboot?", "reboot"))
|
||||
|
||||
menu.show(widget)
|
||||
|
||||
def state(self, widget):
|
||||
return []
|
|
@ -132,6 +132,9 @@
|
|||
"dunst": {
|
||||
"muted": { "prefix": "dunst(muted)"},
|
||||
"unmuted": { "prefix": "dunst" }
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
"prefix": "system"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -206,5 +206,8 @@
|
|||
},
|
||||
"vpn": {
|
||||
"prefix": ""
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
"prefix": " "
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,6 +166,9 @@
|
|||
"dunst": {
|
||||
"muted": { "prefix": "\uf39a"},
|
||||
"unmuted": { "prefix": "\uf39b" }
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
"prefix": " \uf2a9 "
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue