lemonbar: temp fixes

lemonbar: temp
This commit is contained in:
kuben
2019-09-19 08:32:03 +02:00
parent 2f31eef54b
commit a86415f264
3 changed files with 54 additions and 67 deletions

View File

@@ -1,4 +1,4 @@
import subprocess, os, getpass
import subprocess, os
import re # regexp
from enum import Enum
@@ -10,7 +10,7 @@ kill_on_unfocus = []
logger = None
health_logger = None
screen = None
screen_send_cmd = lambda s : None # TODO temporary until move actions to modules
parsing_queue = None
class bar_mode(Enum):
@@ -26,7 +26,7 @@ mode = bar_mode.normal
floatterm_args = lambda prog : ['terminator', '-r', 'FLOAT_TERM', '-p'
, 'dark', '-e', 'echo kill_unfocus $$ > {}; exec {}'.format(
config.fifo_file_executor, prog)]
config.fifo_file_executor, prog)] # TODO URGENT solve without fifo
def date_comm(args):
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
@@ -67,7 +67,7 @@ def bluetooth(args):
btcargs = args.split()[1:]
btcargs = [a.replace('pxc550', '00:16:94:22:29:0E') for a in btcargs]
inp = ' '.join(btcargs)
screen.send_cmd('bluetoothctl ' + inp)
screen_send_cmd('bluetoothctl ' + inp)
show_secs = False
def toggle_secs(args):
@@ -122,32 +122,3 @@ def create_new_fifo(fifo_file):
logger.error('''Failed, couldn't create fifo file''')
os.remove(config.pid_file) # Clean up own PID file
sys.exit(0)
class LemonbarScreen:
# Start, stop and send commands to screen instance
# Start detached, in UTF-8 mode. Log to fifo
start_flags = ['-d', '-m', '-U', '-L', '-Logfile', config.fifo_screen_log]
def __init__(self):
self.identifier = 'lemonbar_{}_{}'.format(getpass.getuser(), os.getpid())
create_new_fifo(config.fifo_screen_log)
self.send(self.start_flags) # Start screen
self.send_cmd('stty -echo') # Do not echo what is written to screen terminal
self.send_colon('logfile flush 0.1') # Log quickly
def destroy(self):
self.send_colon('kill')
def send(self, args):
# Send something to our screen instance
subprocess.call(['screen', '-S', self.identifier] + args)
def send_cmd(self, cmd):
# Send terminal input to our screen instance
self.send(['-X', 'stuff', cmd + '\n'])
def send_colon(self, cmd):
# Send colon command to our screen instance
self.send(['-X', 'colon', cmd + '\n'])

View File

@@ -83,7 +83,6 @@ def nice_delete(f):
def clean_up():
common.logger.debug('Cleaning up')
common.screen.destroy()
nice_delete(config.pid_file)
nice_delete(config.fifo_file_status)
nice_term(p_conky_slow)
@@ -166,39 +165,13 @@ def exec_commands():
break
except:
common.logger.debug('Exception occured executing command\n Line in: {}\n Data: {}'.format(line_in, line_in[l:].split()))
common.logger.debug('Exception occured executing command\n Line in: {}\n Data: {}'.format(data, data[l:].split()))
if len(data) == 0:
common.logger.debug("Lemonbar output closed")
break
common.logger.debug('Read: "{0}"'.format(data.strip('\n')))
def user_screen():
# Create screen session, in UTF-8 mode, logging to fifo
common.screen = common.LemonbarScreen()
with open(config.fifo_screen_log, 'r', buffering=1) as screen_read:
empty_count = 0
while empty_count < 3:
try:
line = screen_read.readline().strip('\n')
line = common.strip_ansi_unicode(line)
common.logger.debug('Screen read line {}'.format(line))
if (not line.startswith('[CHG]')
and not line.isspace()):
#common.logger.debug('put in queue {}'.format(line))
queue_parse_job('RESP {}\n'.format(line))
if not line:
# End loop if many empty lines in a row
empty_count = empty_count + 1
else:
empty_count = 0
except:
raise
common.screen.destroy()
nice_delete(config.fifo_screen_log)
class i3_thread:
""" Helper class to start and stop threads"""
all_threads = [] # Static, contains all started threads
@@ -260,7 +233,6 @@ if __name__ == "__main__":
i3_thread(target = parse_status, desc='Parse status thread')
i3_thread(target = keep_fifo_open, desc='')
i3_thread(target = put_fifo_in_queue, desc='')
i3_thread(target = user_screen, desc='Screen thread for user commands')
modules.start_all()
common.logger.debug('Threads started')

View File

@@ -1,5 +1,7 @@
import threading
import subprocess
import contextlib
import os, getpass
import i3_lemonbar_config as config
import i3_lemonbar_common as common
@@ -357,14 +359,25 @@ class i3Module(LemonModule):
subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km])
class ScreenModule(LemonModule):
# Start, stop and send commands to screen instance
# Start detached, in UTF-8 mode. Log to fifo
start_flags = ['-d', '-m', '-U', '-L', '-Logfile', config.fifo_screen_log]
def __init__(self):
self.prefix = 'RESP'
self.prefix = ''
super().__init__()
def _start_module(self):
# No external commands needed
self.status_handle = None
self.identifier = 'lemonbar_{}_{}'.format(getpass.getuser(), os.getpid())
self.empty_count = 0
common.screen_send_cmd = self.send_cmd
common.create_new_fifo(config.fifo_screen_log)
self.send(self.start_flags) # Start screen
self.send_cmd('stty -echo') # Do not echo what is written to screen terminal
self.send_colon('logfile flush 0.1') # Log quickly
self.status_handle = open(config.fifo_screen_log, 'r', buffering=1)
self.controls = parser.ButtonsUnit('controls', order=-10)
self.response = parser.IconTextUnit('response', order=10)
@@ -385,11 +398,42 @@ class ScreenModule(LemonModule):
parser.g_parser.register_unit(self.controls)
def _stop_module(self):
self.send_colon('kill')
self.status_handle.close()
with contextlib.suppress(FileNotFoundError):
os.remove(config.fifo_screen_log)
parser.g_parser.remove_unit(self.response)
parser.g_parser.remove_unit(self.controls)
def _parse_data(self, data):
self.response.items = [('', ' '.join(data))]
line = ' '.join(data)
line = common.strip_ansi_unicode(line)
common.logger.debug('Screen read line {}'.format(line))
if (not line.startswith('[CHG]')
and not line.isspace()):
self.response.items = [('', line)]
if not line:
# End loop if many empty lines in a row
self.empty_count = self.empty_count + 1
if self.empty_count > 3:
common.logger.error('Too many empty lines, aborting')
# TODO actually abort
else:
self.empty_count = 0
def send(self, args):
# Send something to our screen instance
subprocess.call(['screen', '-S', self.identifier] + args)
def send_cmd(self, cmd):
# Send terminal input to our screen instance
self.send(['-X', 'stuff', cmd + '\n'])
def send_colon(self, cmd):
# Send colon command to our screen instance
self.send(['-X', 'colon', cmd + '\n'])
class PowerOptionsModule(LemonModule):