[modules/system] Update to latest API

This commit is contained in:
tobi-wan-kenobi 2020-04-25 16:26:57 +02:00
parent e104579fe1
commit aabf269742

View file

@ -22,46 +22,39 @@ Parameters:
""" """
import logging import logging
import bumblebee.input
import bumblebee.output
import bumblebee.engine
import bumblebee.popup_v2
import functools import functools
try: try:
import Tkinter as tk
import tkMessageBox as tkmessagebox
except ImportError:
# python 3
try:
import tkinter as tk import tkinter as tk
from tkinter import messagebox as tkmessagebox from tkinter import messagebox as tkmessagebox
except ImportError: except ImportError:
logging.warning('failed to import tkinter - bumblebee popups won't work!') logging.warning('failed to import tkinter - bumblebee popups won\'t work!')
import core.module
import core.widget
import core.input
import core.decorators
class Module(bumblebee.engine.Module): import util.cli
def __init__(self, engine, config): import util.popup
super(Module, self).__init__(engine, config, import util.format
bumblebee.output.Widget(full_text=self.text)
)
self._confirm = True class Module(core.module.Module):
if self.parameter('confirm', 'true') == 'false': @core.decorators.every(minutes=60)
self._confirm = False def __init__(self, config):
super().__init__(config, core.widget.Widget(self.text))
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, self.__confirm = util.format.asbool(self.parameter('confirm', True))
core.input.register(self, button=core.input.LEFT_MOUSE,
cmd=self.popup) cmd=self.popup)
def update(self, widgets):
pass
def text(self, widget): def text(self, widget):
return '' return ''
def _on_command(self, header, text, command): def __on_command(self, header, text, command):
do_it = True do_it = True
if self._confirm: if self.__confirm:
root = tk.Tk() root = tk.Tk()
root.withdraw() root.withdraw()
root.focus_set() root.focus_set()
@ -70,11 +63,11 @@ class Module(bumblebee.engine.Module):
root.destroy() root.destroy()
if do_it: if do_it:
bumblebee.util.execute(command) util.cli.execute(command)
def popup(self, widget): def popup(self, widget):
menu = bumblebee.popup_v2.PopupMenu() menu = util.popup.menu()
reboot_cmd = self.parameter('reboot', 'reboot') reboot_cmd = self.parameter('reboot', 'reboot')
shutdown_cmd = self.parameter('shutdown', 'shutdown -h now') shutdown_cmd = self.parameter('shutdown', 'shutdown -h now')
logout_cmd = self.parameter('logout', 'i3exit logout') logout_cmd = self.parameter('logout', 'i3exit logout')
@ -83,16 +76,15 @@ class Module(bumblebee.engine.Module):
suspend_cmd = self.parameter('suspend', 'i3exit suspend') suspend_cmd = self.parameter('suspend', 'i3exit suspend')
hibernate_cmd = self.parameter('hibernate', 'i3exit hibernate') hibernate_cmd = self.parameter('hibernate', 'i3exit hibernate')
menu.add_menuitem('shutdown', callback=functools.partial(self._on_command, 'Shutdown', 'Shutdown?', shutdown_cmd)) 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)) menu.add_menuitem('reboot', callback=functools.partial(self.__on_command, 'Reboot', 'Reboot?', reboot_cmd))
menu.add_menuitem('log out', callback=functools.partial(self._on_command, 'Log out', 'Log out?', 'i3exit logout')) menu.add_menuitem('log out', callback=functools.partial(self.__on_command, 'Log out', 'Log out?', 'i3exit logout'))
# don't ask for these # don't ask for these
menu.add_menuitem('switch user', callback=functools.partial(bumblebee.util.execute, switch_user_cmd)) menu.add_menuitem('switch user', callback=functools.partial(util.cli.execute, switch_user_cmd))
menu.add_menuitem('lock', callback=functools.partial(bumblebee.util.execute, lock_cmd)) menu.add_menuitem('lock', callback=functools.partial(util.cli.execute, lock_cmd))
menu.add_menuitem('suspend', callback=functools.partial(bumblebee.util.execute, suspend_cmd)) menu.add_menuitem('suspend', callback=functools.partial(util.cli.execute, suspend_cmd))
menu.add_menuitem('hibernate', callback=functools.partial(bumblebee.util.execute, hibernate_cmd)) menu.add_menuitem('hibernate', callback=functools.partial(util.cli.execute, hibernate_cmd))
menu.show(widget) menu.show(widget, 0, 0)
def state(self, widget): # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
return []