lemonbar: Implement modular approach for conky slow and conky fast
This commit is contained in:
@@ -5,15 +5,14 @@ import subprocess
|
||||
import contextlib
|
||||
from threading import Thread
|
||||
import argparse
|
||||
import re # regexp
|
||||
|
||||
import i3_lemonbar_config as config
|
||||
import i3_lemonbar_common as common
|
||||
import i3_lemonbar_parser as lemonparser
|
||||
import i3_workspaces as wspaces
|
||||
import i3_lemonbar_config as config
|
||||
import i3_lemonbar_common as common
|
||||
import i3_lemonbar_modules as modules
|
||||
import i3_lemonbar_parser as lemonparser
|
||||
import i3_workspaces as wspaces
|
||||
|
||||
p_conky_slow = None
|
||||
p_conky_fast = None
|
||||
p_lemonbar = None
|
||||
i3_ws_obj = None
|
||||
|
||||
@@ -90,22 +89,15 @@ def clean_up():
|
||||
nice_delete(config.pid_file)
|
||||
nice_delete(config.fifo_file_status)
|
||||
nice_term(p_conky_slow)
|
||||
nice_term(p_conky_fast)
|
||||
modules.stop_all()
|
||||
if i3_ws_obj is not None:
|
||||
i3_ws_obj.quit()
|
||||
sys.exit(0)
|
||||
|
||||
def write_sys_status():
|
||||
global p_conky_slow, p_conky_fast, i3_ws_obj
|
||||
# Buffering = 1 to write entire lines
|
||||
with open(config.fifo_file_status, 'w', buffering=1) as fifo:
|
||||
p_conky_slow = subprocess.Popen(['conky', '-c', config.path+'conky_slow'], # Use communicate
|
||||
stdout=fifo, stderr=fifo)
|
||||
common.logger.debug('Started conky slow')
|
||||
p_conky_fast = subprocess.Popen(['conky', '-c', config.path+'conky_fast'],
|
||||
stdout=fifo, stderr=fifo)
|
||||
common.logger.debug('Started conky fast')
|
||||
i3_ws_obj = wspaces.i3ws(fifo_file=config.fifo_file_status)
|
||||
global i3_ws_obj
|
||||
|
||||
i3_ws_obj = wspaces.i3ws(logger=common.logger, fifo_file=config.fifo_file_status)
|
||||
i3_ws_obj.work()
|
||||
|
||||
def queue_parse_job(job):
|
||||
@@ -145,7 +137,11 @@ def parse_status():
|
||||
common.health_logger.info('Queue closed')
|
||||
break
|
||||
|
||||
psd = lemonparser.parse_line(data)
|
||||
# Ugly temporary solution
|
||||
if (isinstance(data, list)):
|
||||
psd = data[0]
|
||||
else:
|
||||
psd = lemonparser.parse_line(data)
|
||||
p_lemonbar.stdin.write(psd + '\n')
|
||||
p_lemonbar.stdin.flush()
|
||||
#common.logger.debug('Read: "{0}"'.format(data))
|
||||
@@ -181,12 +177,6 @@ def exec_commands():
|
||||
break
|
||||
common.logger.debug('Read: "{0}"'.format(data.strip('\n')))
|
||||
|
||||
ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
|
||||
def strip_ansi_unicode(s):
|
||||
# ANSI escape sequences are for colors in terminal and similar
|
||||
strip_ansi = ansi_escape.sub('', s)
|
||||
strip_unicode = (strip_ansi.encode('ascii', 'ignore')).decode('utf-8')
|
||||
return strip_unicode
|
||||
|
||||
def user_screen():
|
||||
# Create screen session, in UTF-8 mode, logging to fifo
|
||||
@@ -196,7 +186,7 @@ def user_screen():
|
||||
while empty_count < 3:
|
||||
try:
|
||||
line = screen_read.readline().strip('\n')
|
||||
line = strip_ansi_unicode(line)
|
||||
line = common.strip_ansi_unicode(line)
|
||||
common.logger.debug('Screen read line {}'.format(line))
|
||||
if (not line.startswith('[CHG]')
|
||||
and not line.isspace()):
|
||||
@@ -276,6 +266,7 @@ if __name__ == "__main__":
|
||||
i3_thread(target = put_fifo_in_queue, desc='')
|
||||
i3_thread(target = write_sys_status, desc='Write sys status thread')
|
||||
i3_thread(target = user_screen, desc='Screen thread for user commands')
|
||||
modules.start_all()
|
||||
|
||||
common.logger.debug('Threads started')
|
||||
i3_thread.join_threads()
|
||||
|
||||
Reference in New Issue
Block a user