Skip to content

Commit

Permalink
Allow adjusting the font size of tk popups
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdgeOfRage committed Sep 6, 2023
1 parent d03e630 commit 0a3c6fe
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 20 deletions.
9 changes: 9 additions & 0 deletions bumblebee_status/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ def modules(self):
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
Expand Down
12 changes: 4 additions & 8 deletions bumblebee_status/modules/contrib/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,15 @@ def update(self):

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."""
Expand Down
8 changes: 4 additions & 4 deletions bumblebee_status/modules/contrib/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* 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')
Expand Down Expand Up @@ -77,7 +77,7 @@ def popup(self, widget):
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")
Expand Down
2 changes: 1 addition & 1 deletion bumblebee_status/modules/contrib/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __on_vpnconnect(self, name):
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)
Expand Down
2 changes: 1 addition & 1 deletion bumblebee_status/modules/core/pulseaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def select_default_device_popup(self, widget):
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")
Expand Down
2 changes: 1 addition & 1 deletion bumblebee_status/modules/core/pulsectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def update(self):
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,
Expand Down
4 changes: 2 additions & 2 deletions bumblebee_status/modules/core/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -73,7 +73,7 @@ def __init__(self, config, theme):
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)
Expand Down
9 changes: 6 additions & 3 deletions bumblebee_status/util/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging

import tkinter as tk
import tkinter.font as tkFont

import functools

Expand All @@ -12,9 +13,10 @@ class menu(object):
: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)
:param font_size: Font size to use for the menu (defaults to system settings)
"""

def __init__(self, parent=None, leave=True):
def __init__(self, config, parent=None, leave=True):
self.running = True

self.parent = parent
Expand All @@ -23,6 +25,7 @@ def __init__(self, parent=None, leave=True):
self._root.withdraw()
self._menu = tk.Menu(self._root, tearoff=0)
self._menu.bind("<FocusOut>", self.__on_focus_out)
self._font_size = tkFont.Font(size=config.popup_font_size())

if leave:
self._menu.bind("<Leave>", self.__on_focus_out)
Expand Down Expand Up @@ -68,7 +71,7 @@ def release(self, event=None):
"""

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
Expand All @@ -78,7 +81,7 @@ def add_cascade(self, menuitem, submenu):

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"""
Expand Down

0 comments on commit 0a3c6fe

Please sign in to comment.