2020-04-21 20:34:10 +02:00
|
|
|
# pylint: disable=C0112,R0903
|
|
|
|
|
|
|
|
"""Shows a widget per user-defined shortcut and allows to define the behaviour
|
|
|
|
when clicking on it.
|
|
|
|
|
|
|
|
For more than one shortcut, the commands and labels are strings separated by
|
|
|
|
a demiliter (; semicolon by default).
|
|
|
|
|
|
|
|
For example in order to create two shortcuts labeled A and B with commands
|
|
|
|
cmdA and cmdB you could do:
|
|
|
|
|
2020-04-21 20:34:27 +02:00
|
|
|
./bumblebee-status -m shortcut -p shortcut.cmd='ls;ps' shortcut.label='A;B'
|
2020-04-21 20:34:10 +02:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* shortcut.cmds : List of commands to execute
|
|
|
|
* shortcut.labels: List of widgets' labels (text)
|
|
|
|
* shortcut.delim : Commands and labels delimiter (; semicolon by default)
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2020-04-21 20:34:27 +02:00
|
|
|
LINK = 'https://github.com/tobi-wan-kenobi/bumblebee-status/wiki'
|
|
|
|
LABEL = 'Click me'
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.input
|
|
|
|
import core.decorators
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
class Module(core.module.Module):
|
|
|
|
@core.decorators.every(minutes=60)
|
|
|
|
def __init__(self, config):
|
|
|
|
super().__init__(config, [])
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
self.__labels = self.parameter('labels', '{}'.format(LABEL))
|
|
|
|
self.__cmds = self.parameter('cmds', 'firefox {}'.format(LINK))
|
|
|
|
self.__delim = self.parameter('delim', ';')
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
self.update_widgets()
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
def update_widgets(self):
|
2020-04-21 20:34:10 +02:00
|
|
|
""" Creates a set of widget per user define shortcut."""
|
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
widgets = self.widgets()
|
|
|
|
|
|
|
|
cmds = self.__cmds.split(self.__delim)
|
|
|
|
labels = self.__labels.split(self.__delim)
|
2020-04-21 20:34:10 +02:00
|
|
|
|
|
|
|
# to be on the safe side create as many widgets as there are data (cmds or labels)
|
|
|
|
num_shortcuts = min(len(cmds), len(labels))
|
|
|
|
|
|
|
|
# report possible problem as a warning
|
|
|
|
if len(cmds) is not len(labels):
|
2020-04-21 20:34:27 +02:00
|
|
|
logging.warning('shortcut: the number of commands does not match '\
|
|
|
|
'the number of provided labels.')
|
|
|
|
logging.warning('cmds : %s, labels : %s', cmds, labels)
|
2020-04-21 20:34:10 +02:00
|
|
|
|
|
|
|
for idx in range(0, num_shortcuts):
|
|
|
|
cmd = cmds[idx]
|
|
|
|
label = labels[idx]
|
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
widget = core.widget.Widget(full_text=label)
|
|
|
|
core.input.register(widget, button=core.input.LEFT_MOUSE, cmd=cmd)
|
2020-04-21 20:34:10 +02:00
|
|
|
|
|
|
|
widgets.append(widget)
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|