Customize tray action icons
This commit is contained in:
parent
ee071894d0
commit
bfe4720383
|
@ -178,9 +178,13 @@ class BreakScreen(object):
|
|||
separator.show()
|
||||
|
||||
for tray_action in tray_actions:
|
||||
toolbar_button = Gtk.ToolButton.new_from_stock(tray_action.icon)
|
||||
toolbar_button = None
|
||||
if isinstance(tray_action.icon, str):
|
||||
toolbar_button = Gtk.ToolButton.new_from_stock(tray_action.icon)
|
||||
else:
|
||||
toolbar_button = Gtk.ToolButton.new(tray_action.icon, tray_action.name)
|
||||
toolbar_button.connect("clicked", lambda button, action: self.__tray_action(button, action), tray_action)
|
||||
toolbar_button.set_tooltip_text(_(tray_action.tooltip))
|
||||
toolbar_button.set_tooltip_text(_(tray_action.name))
|
||||
toolbar.add(toolbar_button)
|
||||
toolbar_button.show()
|
||||
|
||||
|
|
|
@ -292,8 +292,10 @@ class PluginManager(object):
|
|||
# Load the plugin module
|
||||
module = importlib.import_module((plugin['id'] + '.plugin'))
|
||||
logging.info("Successfully loaded %s", str(module))
|
||||
plugin_obj = {'id': plugin['id'], 'module': module, 'config': plugin.get(
|
||||
'settings', {}), 'enabled': plugin_enabled, 'break_override_allowed': plugin_config.get('break_override_allowed', False)}
|
||||
plugin_obj = {'id': plugin['id'], 'module': module, 'config': dict(plugin.get(
|
||||
'settings', {})), 'enabled': plugin_enabled, 'break_override_allowed': plugin_config.get('break_override_allowed', False)}
|
||||
# Inject the plugin directory into the config
|
||||
plugin_obj['config']['path'] = os.path.join(plugin_dir, plugin['id'])
|
||||
self.__plugins[plugin['id']] = plugin_obj
|
||||
if self.__has_method(module, 'enable'):
|
||||
module.enable()
|
||||
|
|
|
@ -37,6 +37,7 @@ import gi
|
|||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
gi.require_version('Gdk', '3.0')
|
||||
|
||||
|
@ -57,6 +58,7 @@ USER_PLUGINS_DIR = os.path.join(CONFIG_DIRECTORY, 'plugins')
|
|||
LOCALE_PATH = os.path.join(BIN_DIRECTORY, 'config/locale')
|
||||
DESKTOP_ENVIRONMENT = None
|
||||
|
||||
|
||||
def get_resource_path(resource_name):
|
||||
"""
|
||||
Return the user-defined resource if a system resource is overridden by the user.
|
||||
|
@ -496,3 +498,15 @@ def create_gtk_builder(glade_file):
|
|||
if title is not None:
|
||||
obj.set_title(_(title))
|
||||
return builder
|
||||
|
||||
|
||||
def load_and_scale_image(path, width, height):
|
||||
if not os.path.isfile(path):
|
||||
return None
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename=path,
|
||||
width=width,
|
||||
height=height,
|
||||
preserve_aspect_ratio=True)
|
||||
image = Gtk.Image.new_from_pixbuf(pixbuf)
|
||||
return image
|
||||
|
|
|
@ -299,10 +299,19 @@ class Config(object):
|
|||
|
||||
class TrayAction(object):
|
||||
"""
|
||||
Data object wrapping tooltip, icon and action.
|
||||
Data object wrapping name, icon and action.
|
||||
"""
|
||||
|
||||
def __init__(self, tooltip, icon, action):
|
||||
self.tooltip = tooltip
|
||||
def __init__(self, name, icon, action):
|
||||
self.name = name
|
||||
self.icon = icon
|
||||
self.action = action
|
||||
|
||||
@classmethod
|
||||
def build(cls, name, icon_path, icon_id, action):
|
||||
image = Utility.load_and_scale_image(icon_path, 12, 12)
|
||||
if image is None:
|
||||
return TrayAction(name, icon_id, action)
|
||||
else:
|
||||
image.show()
|
||||
return TrayAction(name, image, action)
|
||||
|
|
|
@ -29,6 +29,8 @@ from safeeyes.model import TrayAction
|
|||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
tray_icon_path = None
|
||||
|
||||
|
||||
def __active_players():
|
||||
"""
|
||||
|
@ -60,7 +62,8 @@ def init(ctx, safeeyes_config, plugin_config):
|
|||
"""
|
||||
Initialize the screensaver plugin.
|
||||
"""
|
||||
pass
|
||||
global tray_icon_path
|
||||
tray_icon_path = os.path.join(plugin_config['path'], "resource/pause.png")
|
||||
|
||||
|
||||
def get_tray_action(break_obj):
|
||||
|
@ -69,4 +72,7 @@ def get_tray_action(break_obj):
|
|||
"""
|
||||
players = __active_players()
|
||||
if players:
|
||||
return TrayAction("Pause media", Gtk.STOCK_MEDIA_PAUSE, lambda: __pause_players(players))
|
||||
return TrayAction.build("Pause media",
|
||||
tray_icon_path,
|
||||
Gtk.STOCK_MEDIA_PAUSE,
|
||||
lambda: __pause_players(players))
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 190 B |
|
@ -34,6 +34,7 @@ lock_screen = False
|
|||
lock_screen_command = None
|
||||
min_seconds = 0
|
||||
seconds_passed = 0
|
||||
tray_icon_path = None
|
||||
|
||||
|
||||
def __lock_screen_command():
|
||||
|
@ -81,9 +82,11 @@ def init(ctx, safeeyes_config, plugin_config):
|
|||
global context
|
||||
global lock_screen_command
|
||||
global min_seconds
|
||||
global tray_icon_path
|
||||
logging.debug('Initialize Screensaver plugin')
|
||||
context = ctx
|
||||
min_seconds = plugin_config['min_seconds']
|
||||
tray_icon_path = os.path.join(plugin_config['path'], "resource/lock.png")
|
||||
if plugin_config['command']:
|
||||
lock_screen_command = plugin_config['command'].split()
|
||||
else:
|
||||
|
@ -118,4 +121,7 @@ def on_stop_break():
|
|||
|
||||
|
||||
def get_tray_action(break_obj):
|
||||
return TrayAction("Lock screen", Gtk.STOCK_DIALOG_AUTHENTICATION, lambda: Utility.execute_command(lock_screen_command))
|
||||
return TrayAction.build("Lock screen",
|
||||
tray_icon_path,
|
||||
Gtk.STOCK_DIALOG_AUTHENTICATION,
|
||||
lambda: Utility.execute_command(lock_screen_command))
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 398 B |
Loading…
Reference in New Issue