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
|
2021-02-12 09:31:09 +01:00
|
|
|
a delimiter (; semicolon by default).
|
2020-04-21 20:34:10 +02:00
|
|
|
|
|
|
|
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)
|
2020-05-08 20:58:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
contributed by `cacyss0807 <https://github.com/cacyss0807>`_ - many thanks!
|
2020-04-21 20:34:10 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2020-05-03 11:15:52 +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.input
|
|
|
|
import core.decorators
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-21 20:37:54 +02:00
|
|
|
class Module(core.module.Module):
|
|
|
|
@core.decorators.every(minutes=60)
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, [])
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-05-03 11:15:52 +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
|
|
|
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-05-03 11:15:52 +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-05-09 10:57:44 +02:00
|
|
|
widget = self.add_widget(full_text=label)
|
2020-04-21 20:37:54 +02:00
|
|
|
core.input.register(widget, button=core.input.LEFT_MOUSE, cmd=cmd)
|
2020-04-21 20:34:10 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-21 20:34:10 +02:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|