lemonbar: Cleaning up

Add connection to i3ws object. Log exceptions with debugger
This commit is contained in:
2019-12-03 21:11:04 +01:00
committed by kuben
parent 1367be34be
commit c6f48faff0
6 changed files with 32 additions and 44 deletions

View File

@@ -38,8 +38,7 @@ class LemonModule(threading.Thread):
self._stop_module()
def parse(self, line):
# TODO get rid of prefix
data = line[len(self.prefix):].split()
data = line.split()
self._parse_data(data) # Update correct field
formatted_line = parser.format_line() # Construct entire line
@@ -53,11 +52,7 @@ class LemonModule(threading.Thread):
action = action_arr[0]
if (action in self.actions):
func = self.actions[action]
if len(action_arr) == 1:
# Function has no arguments
func()
else:
func(action_arr[1:])
func(*action_arr[1:]) # Unpack arguments, if any
def format_load(data, module, alert):
# Helper function to format network modules
@@ -79,7 +74,7 @@ def format_load(data, module, alert):
class ConkyFastModule(LemonModule):
def __init__(self):
self.prefix = 'CNK_FAST'
self.show_secs = False
super().__init__()
def _start_module(self):
@@ -135,7 +130,7 @@ class ConkyFastModule(LemonModule):
# Date and time
self.date.items = [(config.icon_clock, ' '.join(data[0:3]))]
self.time.items = [('', data[3] if common.show_secs else data[3][:-3])]
self.time.items = [('', data[3] if self.show_secs else data[3][:-3])]
def nmtui(self):
p = subprocess.Popen(['xterm', '-class', 'FLOAT_TERM', '-e', 'nmtui'])
@@ -145,18 +140,17 @@ class ConkyFastModule(LemonModule):
p = subprocess.Popen(['pavucontrol', '--class=FLOAT_PAVU'])
common.kill_on_unfocus.append(p.pid)
def date_comm(args):
def date_comm(self):
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
, '--close-on-unfocus'])
def toggle_secs(args):
common.show_secs = not common.show_secs
def toggle_secs(self):
self.show_secs = not self.show_secs
class ConkySlowModule(LemonModule):
def __init__(self):
self.prefix = 'CNK_SLOW'
super().__init__()
def _start_module(self):
@@ -236,6 +230,7 @@ class ConkySlowModule(LemonModule):
common.kill_on_unfocus.append(p.pid)
def lang_comm(self):
# TODO Connect to i3Module (or let i3Module connect here to update the keymap)
subprocess.Popen(['sh', '/home/kuba/.i3/scripts/lang.sh', 'next'])
def dpms_comm(self):
@@ -254,6 +249,10 @@ class i3Module(LemonModule):
self.win_title = ''
self.workspaces = ''
self.def_keymap = 'pl'
self.keymaps = {'firefox': 'se'}
self.cur_class = ''
def _start_module(self):
self.i3_ws_obj = wspaces.i3ws(logger=common.logger)
@@ -276,9 +275,9 @@ class i3Module(LemonModule):
self.i3_ws_obj.focus_callbacks.append(self.parse_title)
# Add callbacks for special actions
self.i3_ws_obj.change_callbacks.append(i3Module.set_bg)
self.i3_ws_obj.focus_callbacks.append(i3Module.set_keymap)
self.i3_ws_obj.focus_callbacks.append(i3Module.kill_floating_windows)
self.i3_ws_obj.change_callbacks.append(self.set_bg)
self.i3_ws_obj.focus_callbacks.append(self.set_keymap)
self.i3_ws_obj.focus_callbacks.append(self.kill_floating_windows)
def _stop_module(self):
parser.g_parser.remove_unit(self.displays)
@@ -378,7 +377,7 @@ class i3Module(LemonModule):
9: '9',
}.get(int(num), 'default')
def set_bg(i3ws):
def set_bg(self, i3ws):
cmd_args = ['sh', '/home/kuba/scripts/set_bg.sh']
for output in i3ws.outputs:
if output.active:
@@ -386,7 +385,7 @@ class i3Module(LemonModule):
cmd_args.append(bg)
subprocess.call(cmd_args)
def kill_floating_windows(i3ws):
def kill_floating_windows(self, i3ws):
if i3ws.focused_window is None:
return
@@ -401,26 +400,24 @@ class i3Module(LemonModule):
common.logger.debug('Tried killing process {} but it doesn\'t exist'.format(pid))
common.kill_on_unfocus = []
def set_keymap(i3ws):
def set_keymap(self, i3ws):
if i3ws.focused_window is None:
return
wclass = i3ws.focused_window.window_class
common.cur_class = wclass
self.cur_class = wclass
if wclass in common.keymaps:
new_km = common.keymaps[wclass]
if wclass in self.keymaps:
new_km = self.keymaps[wclass]
common.logger.debug('Setting {} as keymap for {}'.format(new_km, wclass))
else:
new_km = common.def_keymap
new_km = self.def_keymap
common.logger.debug('Setting default keymap {} for {}'.format(new_km, wclass))
subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km])
def i3msg_comm(self, args):
# TODO this is not needed anymore. Use i3ws object directly
subprocess.Popen(['i3-msg'] + args)
def i3msg_comm(self, *cmd):
self.i3_ws_obj.command(' '.join(cmd))
def set_mode(self, args):
new_mode = args[0]
def set_mode(self, new_mode):
if new_mode == "cycle":
common.mode = common.mode.cycle()
@@ -436,13 +433,11 @@ class ScreenModule(LemonModule):
start_flags = ['-d', '-m', '-U', '-L', '-Logfile', config.fifo_screen_log]
def __init__(self):
self.prefix = ''
super().__init__()
def _start_module(self):
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
@@ -508,15 +503,14 @@ class ScreenModule(LemonModule):
# Send colon command to our screen instance
self.send(['-X', 'colon', cmd + '\n'])
def bluetooth(self, args):
def bluetooth(self, *args):
btcargs = [a.replace('pxc550', '00:16:94:22:29:0E') for a in args]
inp = ' '.join(btcargs)
common.screen_send_cmd('bluetoothctl ' + inp)
self.send_cmd('bluetoothctl ' + inp)
class PowerOptionsModule(LemonModule):
def __init__(self):
self.prefix = ''
super().__init__()
def _start_module(self):