Allow adjusting the font size of tk popups
This commit is contained in:
parent
d03e6307f5
commit
37b5646d65
8 changed files with 28 additions and 20 deletions
|
@ -276,6 +276,15 @@ class Config(util.store.Store):
|
||||||
def interval(self, default=1):
|
def interval(self, default=1):
|
||||||
return util.format.seconds(self.get("interval", default))
|
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
|
"""Returns whether debug mode is enabled
|
||||||
|
|
||||||
:return: True if debug is enabled, False otherwise
|
:return: True if debug is enabled, False otherwise
|
||||||
|
|
|
@ -75,19 +75,15 @@ class Module(core.module.Module):
|
||||||
|
|
||||||
def popup(self, widget):
|
def popup(self, widget):
|
||||||
"""Show a popup menu."""
|
"""Show a popup menu."""
|
||||||
menu = util.popup.PopupMenu()
|
menu = util.popup.menu(self.__config)
|
||||||
if self._status == "On":
|
if self._status == "On":
|
||||||
menu.add_menuitem("Disable Bluetooth")
|
menu.add_menuitem("Disable Bluetooth", callback=self._toggle)
|
||||||
elif self._status == "Off":
|
elif self._status == "Off":
|
||||||
menu.add_menuitem("Enable Bluetooth")
|
menu.add_menuitem("Enable Bluetooth", callback=self._toggle)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
# show menu and get return code
|
menu.show(widget)
|
||||||
ret = menu.show(widget)
|
|
||||||
if ret == 0:
|
|
||||||
# first (and only) item selected.
|
|
||||||
self._toggle()
|
|
||||||
|
|
||||||
def _toggle(self, widget=None):
|
def _toggle(self, widget=None):
|
||||||
"""Toggle bluetooth state."""
|
"""Toggle bluetooth state."""
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Module(core.module.Module):
|
||||||
util.cli.execute(popupcmd)
|
util.cli.execute(popupcmd)
|
||||||
return
|
return
|
||||||
|
|
||||||
menu = util.popup.menu()
|
menu = util.popup.menu(self.__config)
|
||||||
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")
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Module(core.module.Module):
|
||||||
self.__connected_vpn_profile = None
|
self.__connected_vpn_profile = None
|
||||||
|
|
||||||
def popup(self, widget):
|
def popup(self, widget):
|
||||||
menu = util.popup.menu()
|
menu = util.popup.menu(self.__config)
|
||||||
|
|
||||||
if self.__connected_vpn_profile is not None:
|
if self.__connected_vpn_profile is not None:
|
||||||
menu.add_menuitem("Disconnect", callback=self.__on_vpndisconnect)
|
menu.add_menuitem("Disconnect", callback=self.__on_vpndisconnect)
|
||||||
|
|
|
@ -236,7 +236,7 @@ class Module(core.module.Module):
|
||||||
channel = "sinks" if self._channel == "sink" else "sources"
|
channel = "sinks" if self._channel == "sink" else "sources"
|
||||||
result = util.cli.execute("pactl list {} short".format(channel))
|
result = util.cli.execute("pactl list {} short".format(channel))
|
||||||
|
|
||||||
menu = util.popup.menu()
|
menu = util.popup.menu(self.__config)
|
||||||
lines = result.splitlines()
|
lines = result.splitlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
info = line.split("\t")
|
info = line.split("\t")
|
||||||
|
|
|
@ -171,7 +171,7 @@ class Module(core.module.Module):
|
||||||
def select_default_device_popup(self, widget):
|
def select_default_device_popup(self, widget):
|
||||||
with pulsectl.Pulse(self.id) as pulse:
|
with pulsectl.Pulse(self.id) as pulse:
|
||||||
devs = pulse.sink_list() if self.__type == "sink" else pulse.source_list()
|
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:
|
for dev in devs:
|
||||||
menu.add_menuitem(
|
menu.add_menuitem(
|
||||||
dev.description,
|
dev.description,
|
||||||
|
|
|
@ -52,7 +52,7 @@ def build_menu(parent, current_directory, callback):
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
submenu = util.popup.menu(parent, leave=False)
|
submenu = util.popup.menu(self.__config, parent, leave=False)
|
||||||
build_menu(
|
build_menu(
|
||||||
submenu, os.path.join(current_directory, entry.name), callback
|
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)
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.popup)
|
||||||
|
|
||||||
def popup(self, widget):
|
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)
|
build_menu(menu, self.__path, self.__callback)
|
||||||
menu.show(widget, offset_x=self.__offx, offset_y=self.__offy)
|
menu.show(widget, offset_x=self.__offx, offset_y=self.__offy)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
import tkinter.font as tkFont
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
|
@ -10,11 +11,12 @@ import functools
|
||||||
class menu(object):
|
class menu(object):
|
||||||
"""Draws a hierarchical popup menu
|
"""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 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 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.running = True
|
||||||
|
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
@ -23,6 +25,7 @@ class menu(object):
|
||||||
self._root.withdraw()
|
self._root.withdraw()
|
||||||
self._menu = tk.Menu(self._root, tearoff=0)
|
self._menu = tk.Menu(self._root, tearoff=0)
|
||||||
self._menu.bind("<FocusOut>", self.__on_focus_out)
|
self._menu.bind("<FocusOut>", self.__on_focus_out)
|
||||||
|
self._font_size = tkFont.Font(size=config.popup_font_size())
|
||||||
|
|
||||||
if leave:
|
if leave:
|
||||||
self._menu.bind("<Leave>", self.__on_focus_out)
|
self._menu.bind("<Leave>", self.__on_focus_out)
|
||||||
|
@ -68,7 +71,7 @@ class menu(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def add_cascade(self, menuitem, submenu):
|
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
|
"""Adds an item to the current menu
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@ class menu(object):
|
||||||
|
|
||||||
def add_menuitem(self, menuitem, callback):
|
def add_menuitem(self, menuitem, callback):
|
||||||
self._menu.add_command(
|
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"""
|
"""Adds a separator to the menu in the current location"""
|
||||||
|
|
Loading…
Reference in a new issue