[modules/shortcut] update to latest API
This commit is contained in:
parent
007b097077
commit
771eaf331e
2 changed files with 20 additions and 22 deletions
|
@ -64,6 +64,7 @@ def main():
|
||||||
core.event.trigger('stop')
|
core.event.trigger('stop')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -18,32 +18,33 @@ Parameters:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import bumblebee.engine
|
|
||||||
import bumblebee.output
|
|
||||||
import bumblebee.input
|
|
||||||
|
|
||||||
LINK = 'https://github.com/tobi-wan-kenobi/bumblebee-status/wiki'
|
LINK = 'https://github.com/tobi-wan-kenobi/bumblebee-status/wiki'
|
||||||
LABEL = 'Click me'
|
LABEL = 'Click me'
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
import core.module
|
||||||
""" Shortcut module."""
|
import core.widget
|
||||||
|
import core.input
|
||||||
|
import core.decorators
|
||||||
|
|
||||||
def __init__(self, engine, config):
|
class Module(core.module.Module):
|
||||||
widgets = []
|
@core.decorators.every(minutes=60)
|
||||||
self._engine = engine
|
def __init__(self, config):
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
super().__init__(config, [])
|
||||||
|
|
||||||
self._labels = self.parameter('labels', '{}'.format(LABEL))
|
self.__labels = self.parameter('labels', '{}'.format(LABEL))
|
||||||
self._cmds = self.parameter('cmds', 'firefox {}'.format(LINK))
|
self.__cmds = self.parameter('cmds', 'firefox {}'.format(LINK))
|
||||||
self._delim = self.parameter('delim', ';')
|
self.__delim = self.parameter('delim', ';')
|
||||||
|
|
||||||
self.update_widgets(widgets)
|
self.update_widgets()
|
||||||
|
|
||||||
def update_widgets(self, widgets):
|
def update_widgets(self):
|
||||||
""" Creates a set of widget per user define shortcut."""
|
""" Creates a set of widget per user define shortcut."""
|
||||||
|
|
||||||
cmds = self._cmds.split(self._delim)
|
widgets = self.widgets()
|
||||||
labels = self._labels.split(self._delim)
|
|
||||||
|
cmds = self.__cmds.split(self.__delim)
|
||||||
|
labels = self.__labels.split(self.__delim)
|
||||||
|
|
||||||
# to be on the safe side create as many widgets as there are data (cmds or labels)
|
# to be on the safe side create as many widgets as there are data (cmds or labels)
|
||||||
num_shortcuts = min(len(cmds), len(labels))
|
num_shortcuts = min(len(cmds), len(labels))
|
||||||
|
@ -58,13 +59,9 @@ class Module(bumblebee.engine.Module):
|
||||||
cmd = cmds[idx]
|
cmd = cmds[idx]
|
||||||
label = labels[idx]
|
label = labels[idx]
|
||||||
|
|
||||||
widget = bumblebee.output.Widget(full_text=label)
|
widget = core.widget.Widget(full_text=label)
|
||||||
self._engine.input.register_callback(widget, button=bumblebee.input.LEFT_MOUSE, cmd=cmd)
|
core.input.register(widget, button=core.input.LEFT_MOUSE, cmd=cmd)
|
||||||
|
|
||||||
widgets.append(widget)
|
widgets.append(widget)
|
||||||
|
|
||||||
def update(self, widgets):
|
|
||||||
if len(widgets) <= 0:
|
|
||||||
self.update_widgets(widgets)
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue