From bfe90a1c457bd52d6c359b925cafdaaaf4312a18 Mon Sep 17 00:00:00 2001 From: kuben Date: Sun, 28 Jul 2019 11:56:39 +0200 Subject: [PATCH] Begin implementing screen thread in lemonbar --- .i3/lemonbar/i3_lemonbar_common.py | 6 ++--- .i3/lemonbar/i3_lemonbar_launcher.py | 40 +++++++++++++++++----------- .i3/lemonbar/i3_workspaces.py | 8 +++--- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.i3/lemonbar/i3_lemonbar_common.py b/.i3/lemonbar/i3_lemonbar_common.py index 963506a..6a4c5bf 100755 --- a/.i3/lemonbar/i3_lemonbar_common.py +++ b/.i3/lemonbar/i3_lemonbar_common.py @@ -3,7 +3,7 @@ from enum import Enum import i3_lemonbar_config as config -p_bluetooth = None +p_screen = None kill_on_unfocus = [] class bar_mode(Enum): @@ -61,8 +61,8 @@ def bluetooth(args): btcargs = [a.replace('pxc550', '00:16:94:22:29:0E') for a in btcargs] btcargs.append('\n') inp = ' '.join(btcargs) - p_bluetooth.stdin.write(inp) - p_bluetooth.stdin.flush() + p_screen.stdin.write(inp) + p_screen.stdin.flush() show_secs = False def toggle_secs(args): diff --git a/.i3/lemonbar/i3_lemonbar_launcher.py b/.i3/lemonbar/i3_lemonbar_launcher.py index 836d628..9967028 100755 --- a/.i3/lemonbar/i3_lemonbar_launcher.py +++ b/.i3/lemonbar/i3_lemonbar_launcher.py @@ -110,7 +110,7 @@ def clean_up(): nice_delete(config.fifo_file_executor) nice_term(p_conky_slow) nice_term(p_conky_fast) - nice_term(common.p_bluetooth) + nice_term(common.p_screen) if i3_ws_obj is not None: i3_ws_obj.quit() sys.exit(0) @@ -134,7 +134,7 @@ def parse_status(): with open(config.fifo_file_status, 'r', buffering=1) as fifo_read: # Let parser read from fifo logger.debug("FIFO {} opened for reading".format(config.fifo_file_status)) - lemonparser.parse_line('WSPINA1___main INA2___web FOC5___terms INA6___stats ') + lemonparser.parse_line('WSPINA1___main INA2___web FOC5___terms INA6___stats ') # TODO modular while True: try: data = fifo_read.readline() # Blocking read @@ -148,9 +148,11 @@ def parse_status(): #logger.debug('Parsed "{0}"'.format(psd)) except BrokenPipeError: logger.debug('Broken pipe in parse status thread, exiting') + health_logger.info('Broken pipe in parse status thread, exiting') clean_up() except: logger.debug('Unknown exception in parse status thread, exiting') + health_logger.info('Unknown exception in parse status thread, exiting') clean_up() def exec_commands(): @@ -175,9 +177,10 @@ def exec_commands(): logger.debug('Read: "{0}"'.format(data.strip('\n'))) except BrokenPipeError: logger.debug('Broken pipe in exec commands thread, exiting') + health_logger.info('Broken pipe in exec commands thread, exiting') clean_up() except: - logger.debug('Unknown exception in exec commands thread, exiting') + health_logger.info('Unknown exception in exec commands thread, exiting') raise clean_up() def strip_ansi_unicode(s): @@ -187,18 +190,19 @@ def strip_ansi_unicode(s): strip_unicode = (strip_ansi.encode('ascii', 'ignore')).decode('utf-8') return strip_unicode -def handle_bluetooth(): - common.p_bluetooth = subprocess.Popen('bluetoothctl' +def user_screen(): + # Attach to screen session, creating if needed, in UTF-8 mode + common.p_screen = subprocess.Popen('screen -D -R -U -S lemonbar' # TODO lemonbar_user ,stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) - for line in common.p_bluetooth.stdout: + for line in common.p_screen.stdout: #try: - logger.debug('Bluetooth read line {}'.format(line.strip('\n'))) - with open(config.fifo_file_status, 'w') as fifo: - clean_line = strip_ansi_unicode(line) - if (not clean_line.startswith('[bluetooth]') - and not clean_line.startswith('[CHG]') - and not clean_line.isspace()): - fifo.write('RESP [bluetoothctl] ' + clean_line) + logger.debug('Screen read line {}'.format(line.strip('\n'))) + # with open(config.fifo_file_status, 'w') as fifo: + # clean_line = strip_ansi_unicode(line) + # if (not clean_line.startswith('[bluetooth]') + # and not clean_line.startswith('[CHG]') + # and not clean_line.isspace()): + # fifo.write('RESP [bluetoothctl] ' + clean_line) #except: # raise @@ -207,12 +211,18 @@ class i3_thread: all_threads = [] # Static, contains all started threads def __init__(self, target, desc): - self.thread = Thread(target = target) + self.thread = Thread(target = self.__class__.run, args=(target,desc)) self.desc = desc self.all_threads.append(self) + health_logger.info('"%s" starting', desc) self.thread.start() + # Wrapper around the target + def run(target, desc): + target() + health_logger.info('"%s" reached end', desc) + def join_threads(): for i3_th in i3_thread.all_threads: i3_th.thread.join() @@ -254,7 +264,7 @@ if __name__ == "__main__": i3_thread(target = exec_commands, desc='Exec commands thread') i3_thread(target = parse_status, desc='Parse status thread') i3_thread(target = write_sys_status, desc='Write sys status thread') - i3_thread(target = handle_bluetooth, desc='Bluetooth thread') + i3_thread(target = user_screen, desc='Screen thread for user commands') logger.debug('Threads started') i3_thread.join_threads() diff --git a/.i3/lemonbar/i3_workspaces.py b/.i3/lemonbar/i3_workspaces.py index 02e2eec..5cd1838 100755 --- a/.i3/lemonbar/i3_workspaces.py +++ b/.i3/lemonbar/i3_workspaces.py @@ -39,10 +39,10 @@ def img_path(num): class State(object): # workspace states - focused = 'FOC' - active = 'ACT' + focused = 'FOC' + active = 'ACT' inactive = 'INA' - urgent = 'URG' + urgent = 'URG' def get_state(self, workspace, output): if workspace['focused']: @@ -183,4 +183,4 @@ if __name__ == '__main__': except KeyboardInterrupt: print('') # force new line # finally: - # ws.quit() +# ws.quit()