lemonbar: Move last actions to modules and remove command dict

This commit is contained in:
2019-11-14 19:08:45 +01:00
committed by kuben
parent b8bf0c0f61
commit 1367be34be
3 changed files with 40 additions and 42 deletions

View File

@@ -48,10 +48,16 @@ class LemonModule(threading.Thread):
def register_action(self, keyword, do_action):
self.actions[keyword] = do_action
def do_action(self, keyword):
if (keyword in self.actions):
func = self.actions[keyword]
func()
def do_action(self, command):
action_arr = command.split()
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:])
def format_load(data, module, alert):
# Helper function to format network modules
@@ -229,13 +235,13 @@ class ConkySlowModule(LemonModule):
p = subprocess.Popen(['xterm', '-class', 'FLOAT_TERM', '-e', 'htop'])
common.kill_on_unfocus.append(p.pid)
def lang_comm(args):
def lang_comm(self):
subprocess.Popen(['sh', '/home/kuba/.i3/scripts/lang.sh', 'next'])
def dpms_comm(args):
def dpms_comm(self):
subprocess.Popen(['sh', '/home/kuba/.i3/scripts/dpmsctl.sh'])
def adj_br(args):
def adj_br(self):
subprocess.Popen(['/home/kuba/.i3/scripts/adjbr.sh', '-b', config.fifo_file_executor])
class i3Module(LemonModule):
@@ -261,6 +267,9 @@ class i3Module(LemonModule):
parser.g_parser.register_unit(self.workspaces)
parser.g_parser.register_unit(self.title)
self.register_action('i3-msg' , self.i3msg_comm)
self.register_action('mode' , self.set_mode)
# Add callbacks for parsing
self.i3_ws_obj.change_callbacks.append(self.parse_displays)
self.i3_ws_obj.change_callbacks.append(self.parse_workspaces)
@@ -406,6 +415,20 @@ class i3Module(LemonModule):
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 set_mode(self, args):
new_mode = args[0]
if new_mode == "cycle":
common.mode = common.mode.cycle()
for m in common.bar_mode:
if new_mode == m.name:
common.mode = m
break
class ScreenModule(LemonModule):
# Start, stop and send commands to screen instance
@@ -445,6 +468,8 @@ class ScreenModule(LemonModule):
parser.g_parser.register_unit(self.response)
parser.g_parser.register_unit(self.controls)
self.register_action('bluetooth', self.bluetooth)
def _stop_module(self):
self.send_colon('kill')
self.status_handle.close()
@@ -483,6 +508,11 @@ class ScreenModule(LemonModule):
# Send colon command to our screen instance
self.send(['-X', 'colon', cmd + '\n'])
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)
class PowerOptionsModule(LemonModule):
def __init__(self):