Create wrapper class that handles launching the lemonbar process
and in and out threads
This commit is contained in:
@@ -20,9 +20,10 @@ class LemonModule(threading.Thread):
|
||||
if isinstance(attr_instance, parser.LemonUnit):
|
||||
yield attr_instance
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, lemonbar_wrapper):
|
||||
self.actions = {}
|
||||
super().__init__()
|
||||
self.lemonbar_wrapper = lemonbar_wrapper
|
||||
self._start_module()
|
||||
|
||||
for unit in self.units():
|
||||
@@ -43,7 +44,7 @@ class LemonModule(threading.Thread):
|
||||
break
|
||||
|
||||
parsed = self.parse(line)
|
||||
common.bar_in_shelf.put(parsed)
|
||||
self.lemonbar_wrapper.buffer_in.put(parsed)
|
||||
|
||||
def stop(self):
|
||||
self._stop_module()
|
||||
@@ -87,8 +88,8 @@ def format_load(data, module, alert):
|
||||
|
||||
class DateTimeModule(LemonModule):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, lemonbar_wrapper):
|
||||
super().__init__(lemonbar_wrapper)
|
||||
|
||||
def _start_module(self):
|
||||
class DateTimeThread(threading.Thread):
|
||||
@@ -187,7 +188,7 @@ conky_end_body = """
|
||||
]]"""
|
||||
class ConkyFastModule(LemonModule):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, lemonbar_wrapper):
|
||||
self.conky_config = (conky_config(update_interval=1)
|
||||
+ conky_begin_body
|
||||
+ """\\
|
||||
@@ -196,7 +197,7 @@ ${exec ~/.i3/lemonbar/get_vol.sh} """
|
||||
(conky_net('wlp3s0')
|
||||
+ conky_net('enp2s0')))
|
||||
+ conky_end_body)
|
||||
super().__init__()
|
||||
super().__init__(lemonbar_wrapper)
|
||||
|
||||
def _start_module(self):
|
||||
self.p_handle = subprocess.Popen(['conky', '-c', '-'],
|
||||
@@ -260,7 +261,7 @@ ${exec ~/.i3/lemonbar/get_vol.sh} """
|
||||
|
||||
class ConkySlowModule(LemonModule):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, lemonbar_wrapper):
|
||||
self.conky_config = (conky_config()
|
||||
+ conky_begin_body
|
||||
+ """\\
|
||||
@@ -275,7 +276,7 @@ ${exec brillo} """ if common.hostname() != 'kubaDesktop' else '')
|
||||
${exec /home/kuba/.i3/scripts/lang.sh show} \\
|
||||
${exec ~/.i3/lemonbar/get_vol.sh}"""
|
||||
+ conky_end_body)
|
||||
super().__init__()
|
||||
super().__init__(lemonbar_wrapper)
|
||||
|
||||
def _start_module(self):
|
||||
self.p_handle = subprocess.Popen(['conky', '-c', '-'],
|
||||
@@ -369,8 +370,8 @@ class i3Module(LemonModule):
|
||||
# Handles outputs (displays), workspaces and active window
|
||||
# TODO trigger formatting
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, lemonbar_wrapper):
|
||||
super().__init__(lemonbar_wrapper)
|
||||
self.displays = ''
|
||||
self.win_title = ''
|
||||
self.workspaces = ''
|
||||
@@ -555,8 +556,8 @@ class ScreenModule(LemonModule):
|
||||
# Start detached, in UTF-8 mode. Log to fifo
|
||||
start_flags = ['-d', '-m', '-U', '-L', '-Logfile', config.fifo_screen_log]
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, lemonbar_wrapper):
|
||||
super().__init__(lemonbar_wrapper)
|
||||
|
||||
def _start_module(self):
|
||||
self.identifier = 'lemonbar_{}_{}'.format(getpass.getuser(), os.getpid())
|
||||
@@ -629,8 +630,8 @@ class ScreenModule(LemonModule):
|
||||
|
||||
class PowerOptionsModule(LemonModule):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, lemonbar_wrapper):
|
||||
super().__init__(lemonbar_wrapper)
|
||||
|
||||
def _start_module(self):
|
||||
# No external commands needed
|
||||
@@ -689,12 +690,12 @@ def do_action(keyword):
|
||||
for module in all_modules:
|
||||
module.do_action(keyword)
|
||||
|
||||
def start_all():
|
||||
def start_all(lemonbar_wrapper):
|
||||
global all_modules
|
||||
|
||||
all_modules = []
|
||||
for cls in get_active_modules():
|
||||
all_modules.append(cls())
|
||||
all_modules.append(cls(lemonbar_wrapper))
|
||||
|
||||
for module in all_modules:
|
||||
module.start()
|
||||
|
||||
Reference in New Issue
Block a user