diff --git a/bumblebee_status/core/config.py b/bumblebee_status/core/config.py index f191673..1d4ebaa 100644 --- a/bumblebee_status/core/config.py +++ b/bumblebee_status/core/config.py @@ -276,6 +276,15 @@ class Config(util.store.Store): def interval(self, default=1): return util.format.seconds(self.get("interval", default)) + """Returns the global popup menu font size + + :return: popup menu font size + :rtype: int + """ + + def popup_font_size(self, default=12): + return util.format.asint(self.get("popup_font_size", default)) + """Returns whether debug mode is enabled :return: True if debug is enabled, False otherwise diff --git a/bumblebee_status/modules/contrib/bluetooth.py b/bumblebee_status/modules/contrib/bluetooth.py index 481ae88..56f5b8b 100644 --- a/bumblebee_status/modules/contrib/bluetooth.py +++ b/bumblebee_status/modules/contrib/bluetooth.py @@ -75,19 +75,15 @@ class Module(core.module.Module): def popup(self, widget): """Show a popup menu.""" - menu = util.popup.PopupMenu() + menu = util.popup.menu(self.__config) if self._status == "On": - menu.add_menuitem("Disable Bluetooth") + menu.add_menuitem("Disable Bluetooth", callback=self._toggle) elif self._status == "Off": - menu.add_menuitem("Enable Bluetooth") + menu.add_menuitem("Enable Bluetooth", callback=self._toggle) else: return - # show menu and get return code - ret = menu.show(widget) - if ret == 0: - # first (and only) item selected. - self._toggle() + menu.show(widget) def _toggle(self, widget=None): """Toggle bluetooth state.""" diff --git a/bumblebee_status/modules/contrib/system.py b/bumblebee_status/modules/contrib/system.py index 79e8846..8b136a1 100644 --- a/bumblebee_status/modules/contrib/system.py +++ b/bumblebee_status/modules/contrib/system.py @@ -8,11 +8,11 @@ adds the possibility to * reboot the system. - + Per default a confirmation dialog is shown before the actual action is performed. - + Parameters: - * system.confirm: show confirmation dialog before performing any action (default: true) + * system.confirm: show confirmation dialog before performing any action (default: true) * 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') @@ -77,7 +77,7 @@ class Module(core.module.Module): util.cli.execute(popupcmd) return - menu = util.popup.menu() + menu = util.popup.menu(self.__config) reboot_cmd = self.parameter("reboot", "reboot") shutdown_cmd = self.parameter("shutdown", "shutdown -h now") logout_cmd = self.parameter("logout", "i3exit logout") diff --git a/bumblebee_status/modules/contrib/vpn.py b/bumblebee_status/modules/contrib/vpn.py index d9c8793..ae8e748 100644 --- a/bumblebee_status/modules/contrib/vpn.py +++ b/bumblebee_status/modules/contrib/vpn.py @@ -93,7 +93,7 @@ class Module(core.module.Module): self.__connected_vpn_profile = None def popup(self, widget): - menu = util.popup.menu() + menu = util.popup.menu(self.__config) if self.__connected_vpn_profile is not None: menu.add_menuitem("Disconnect", callback=self.__on_vpndisconnect) diff --git a/bumblebee_status/modules/core/pulseaudio.py b/bumblebee_status/modules/core/pulseaudio.py index 431de10..5f74248 100644 --- a/bumblebee_status/modules/core/pulseaudio.py +++ b/bumblebee_status/modules/core/pulseaudio.py @@ -236,7 +236,7 @@ class Module(core.module.Module): channel = "sinks" if self._channel == "sink" else "sources" result = util.cli.execute("pactl list {} short".format(channel)) - menu = util.popup.menu() + menu = util.popup.menu(self.__config) lines = result.splitlines() for line in lines: info = line.split("\t") diff --git a/bumblebee_status/modules/core/pulsectl.py b/bumblebee_status/modules/core/pulsectl.py index 901202a..4342913 100644 --- a/bumblebee_status/modules/core/pulsectl.py +++ b/bumblebee_status/modules/core/pulsectl.py @@ -171,7 +171,7 @@ class Module(core.module.Module): def select_default_device_popup(self, widget): with pulsectl.Pulse(self.id) as pulse: devs = pulse.sink_list() if self.__type == "sink" else pulse.source_list() - menu = util.popup.menu() + menu = util.popup.menu(self.__config) for dev in devs: menu.add_menuitem( dev.description, diff --git a/bumblebee_status/modules/core/vault.py b/bumblebee_status/modules/core/vault.py index 7f3fb75..ba316bc 100644 --- a/bumblebee_status/modules/core/vault.py +++ b/bumblebee_status/modules/core/vault.py @@ -52,7 +52,7 @@ def build_menu(parent, current_directory, callback): ) else: - submenu = util.popup.menu(parent, leave=False) + submenu = util.popup.menu(self.__config, parent, leave=False) build_menu( submenu, os.path.join(current_directory, entry.name), callback ) @@ -73,7 +73,7 @@ class Module(core.module.Module): core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.popup) def popup(self, widget): - menu = util.popup.menu(leave=False) + menu = util.popup.menu(self.__config, leave=False) build_menu(menu, self.__path, self.__callback) menu.show(widget, offset_x=self.__offx, offset_y=self.__offy) diff --git a/bumblebee_status/util/popup.py b/bumblebee_status/util/popup.py index 784a037..cd083f7 100644 --- a/bumblebee_status/util/popup.py +++ b/bumblebee_status/util/popup.py @@ -3,6 +3,7 @@ import logging import tkinter as tk +import tkinter.font as tkFont import functools @@ -10,11 +11,12 @@ import functools class menu(object): """Draws a hierarchical popup menu + :param config: Global config singleton, passed on from modules :param parent: If given, this menu is a leave of the "parent" menu :param leave: If set to True, close this menu when mouse leaves the area (defaults to True) """ - def __init__(self, parent=None, leave=True): + def __init__(self, config, parent=None, leave=True): self.running = True self.parent = parent @@ -23,6 +25,7 @@ class menu(object): self._root.withdraw() self._menu = tk.Menu(self._root, tearoff=0) self._menu.bind("", self.__on_focus_out) + self._font_size = tkFont.Font(size=config.popup_font_size()) if leave: self._menu.bind("", self.__on_focus_out) @@ -68,7 +71,7 @@ class menu(object): """ def add_cascade(self, menuitem, submenu): - self._menu.add_cascade(label=menuitem, menu=submenu.menu()) + self._menu.add_cascade(label=menuitem, menu=submenu.menu(), font=self._font_size) """Adds an item to the current menu @@ -78,7 +81,7 @@ class menu(object): def add_menuitem(self, menuitem, callback): self._menu.add_command( - label=menuitem, command=functools.partial(self.__on_click, callback) + label=menuitem, command=functools.partial(self.__on_click, callback), font=self._font_size, ) """Adds a separator to the menu in the current location"""