[core] Minor refactoring
Use a small helper function from util, tidy up some parts of the output.
This commit is contained in:
parent
a93fa4aa5c
commit
f306366629
4 changed files with 18 additions and 23 deletions
|
@ -1,8 +1,7 @@
|
|||
import os
|
||||
import shlex
|
||||
import inspect
|
||||
import threading
|
||||
import subprocess
|
||||
import bumblebee.util
|
||||
|
||||
def output(args):
|
||||
import bumblebee.outputs.i3
|
||||
|
@ -57,8 +56,7 @@ class Command(object):
|
|||
cmd(self._event, self._widget)
|
||||
else:
|
||||
c = cmd.format(*args, **kwargs)
|
||||
DEVNULL = open(os.devnull, 'wb')
|
||||
subprocess.Popen(shlex.split(c), stdout=DEVNULL, stderr=DEVNULL)
|
||||
bumblebee.util.execute(c, False)
|
||||
|
||||
class Output(object):
|
||||
def __init__(self, config):
|
||||
|
@ -103,14 +101,14 @@ class Output(object):
|
|||
def wait(self):
|
||||
self._wait.wait(self._config.parameter("interval", 1))
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def draw(self, widgets, theme):
|
||||
if not type(widgets) is list:
|
||||
widgets = [ widgets ]
|
||||
self._draw(widgets, theme)
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def _draw(self, widgets, theme):
|
||||
pass
|
||||
|
||||
|
|
|
@ -51,10 +51,6 @@ class Output(bumblebee.output.Output):
|
|||
"separator_block_width": 0,
|
||||
})
|
||||
|
||||
sep = theme.default_separators(widget)
|
||||
sep = sep if sep else False
|
||||
width = theme.separator_block_width(widget)
|
||||
width = width if width else 0
|
||||
self._data.append({
|
||||
u"full_text": " {} {} {}".format(
|
||||
theme.prefix(widget),
|
||||
|
@ -65,8 +61,8 @@ class Output(bumblebee.output.Output):
|
|||
"background": theme.background(widget),
|
||||
"name": widget.module(),
|
||||
"instance": widget.instance(),
|
||||
"separator": sep,
|
||||
"separator_block_width": width,
|
||||
"separator": theme.default_separators(widget, False),
|
||||
"separator_block_width": theme.separator_block_width(widget, 0),
|
||||
})
|
||||
theme.next_widget()
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ class Theme:
|
|||
def separator(self, widget):
|
||||
return self._get(widget, "separator")
|
||||
|
||||
def default_separators(self, widget):
|
||||
return self._get(widget, "default-separators")
|
||||
def default_separators(self, widget, default):
|
||||
return self._get(widget, "default-separators", default)
|
||||
|
||||
def separator_color(self, widget):
|
||||
return self.background(widget)
|
||||
|
@ -98,8 +98,8 @@ class Theme:
|
|||
def separator_background(self, widget):
|
||||
return self._background[1]
|
||||
|
||||
def separator_block_width(self, widget):
|
||||
return self._get(widget, "separator-block-width")
|
||||
def separator_block_width(self, widget, default):
|
||||
return self._get(widget, "separator-block-width", default)
|
||||
|
||||
def _get(self, widget, name, default = None):
|
||||
module = widget.module()
|
||||
|
|
|
@ -21,12 +21,13 @@ def durationfmt(duration):
|
|||
|
||||
return res
|
||||
|
||||
def execute(cmd):
|
||||
def execute(cmd, wait=True):
|
||||
args = shlex.split(cmd)
|
||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
out, err = p.communicate()
|
||||
|
||||
if wait:
|
||||
out, err = p.communicate()
|
||||
if p.returncode != 0:
|
||||
raise RuntimeError("{} exited with {}".format(cmd, p.returncode))
|
||||
|
||||
return out.decode("utf-8")
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue