[core] Add option to draw widgets right-to-left

fixes #295
This commit is contained in:
Tobias Witek 2018-09-22 14:40:32 +02:00
parent 8863ce1c5b
commit e80ae8b91e
3 changed files with 12 additions and 3 deletions

View file

@ -39,7 +39,7 @@ def main():
) )
theme = bumblebee.theme.Theme(config.theme(), config.iconset()) theme = bumblebee.theme.Theme(config.theme(), config.iconset())
output = bumblebee.output.I3BarOutput(theme=theme) output = bumblebee.output.I3BarOutput(theme=theme, config=config)
inp = bumblebee.input.I3BarInput() inp = bumblebee.input.I3BarInput()
engine = None engine = None

View file

@ -57,6 +57,8 @@ def create_parser():
help=LIST_HELP) help=LIST_HELP)
parser.add_argument("-d", "--debug", action="store_true", parser.add_argument("-d", "--debug", action="store_true",
help=DEBUG_HELP) help=DEBUG_HELP)
parser.add_argument("-r", "--right-to-left", action="store_true",
help="Draw widgets from right to left, rather than left to right (which is the default)")
parser.add_argument("-f", "--logfile", default="~/bumblebee-status-debug.log", parser.add_argument("-f", "--logfile", default="~/bumblebee-status-debug.log",
help="Location of the debug log file") help="Location of the debug log file")
parser.add_argument("-i", "--iconset", default="auto", parser.add_argument("-i", "--iconset", default="auto",
@ -100,6 +102,9 @@ class Config(bumblebee.store.Store):
def debug(self): def debug(self):
return self._args.debug return self._args.debug
def reverse(self):
return self._args.right_to_left
def logfile(self): def logfile(self):
return os.path.expanduser(self._args.logfile) return os.path.expanduser(self._args.logfile)

View file

@ -83,10 +83,11 @@ class Widget(bumblebee.store.Store):
class I3BarOutput(object): class I3BarOutput(object):
"""Manage output according to the i3bar protocol""" """Manage output according to the i3bar protocol"""
def __init__(self, theme): def __init__(self, theme, config=None):
self._theme = theme self._theme = theme
self._widgets = [] self._widgets = []
self._started = False self._started = False
self._config = config
def started(self): def started(self):
return self._started return self._started
@ -143,7 +144,10 @@ class I3BarOutput(object):
def flush(self): def flush(self):
"""Flushes output""" """Flushes output"""
sys.stdout.write(json.dumps(self._widgets)) widgets = self._widgets
if self._config and self._config.reverse():
widgets = list(reversed(widgets))
sys.stdout.write(json.dumps(widgets))
def end(self): def end(self):
"""Finalizes output""" """Finalizes output"""