lemonbar: Cleaning up
Add connection to i3ws object. Log exceptions with debugger
This commit is contained in:
@@ -15,7 +15,6 @@ conky.config = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
conky.text = [[
|
conky.text = [[
|
||||||
CNK_FAST \
|
|
||||||
${time %a %d %b %H:%M:%S} \
|
${time %a %d %b %H:%M:%S} \
|
||||||
${exec ~/.i3/lemonbar/get_vol.sh} \
|
${exec ~/.i3/lemonbar/get_vol.sh} \
|
||||||
${if_up wlp3s0}${downspeedf wlp3s0} ${upspeedf wlp3s0}\
|
${if_up wlp3s0}${downspeedf wlp3s0} ${upspeedf wlp3s0}\
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ conky.config = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
conky.text = [[
|
conky.text = [[
|
||||||
CNK_SLOW \
|
|
||||||
${cpu} \
|
${cpu} \
|
||||||
${mem} \
|
${mem} \
|
||||||
${fs_used_perc /} \
|
${fs_used_perc /} \
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ kill_on_unfocus = []
|
|||||||
logger = None
|
logger = None
|
||||||
health_logger = None
|
health_logger = None
|
||||||
|
|
||||||
screen_send_cmd = lambda s : None # TODO temporary until move actions to modules
|
|
||||||
write_queue = None # TODO Actually, why is this a queue? Just last element is important
|
write_queue = None # TODO Actually, why is this a queue? Just last element is important
|
||||||
|
|
||||||
# TODO bar mode can be moved to i3Module
|
# TODO bar mode can be moved to i3Module
|
||||||
@@ -25,13 +24,6 @@ class bar_mode(Enum):
|
|||||||
|
|
||||||
mode = bar_mode.normal
|
mode = bar_mode.normal
|
||||||
|
|
||||||
show_secs = False
|
|
||||||
|
|
||||||
# Keymaps
|
|
||||||
def_keymap = 'pl'
|
|
||||||
keymaps = {'firefox': 'se'}
|
|
||||||
cur_class = ''
|
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
|
ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
|
||||||
def strip_ansi_unicode(s):
|
def strip_ansi_unicode(s):
|
||||||
|
|||||||
@@ -154,8 +154,9 @@ def exec_commands():
|
|||||||
try:
|
try:
|
||||||
modules.do_action(data)
|
modules.do_action(data)
|
||||||
|
|
||||||
except:
|
except Exception as e:
|
||||||
common.logger.debug('Exception occured executing command\n Line in: {}'.format(data))
|
common.logger.debug('Exception occured executing command\n Line in: {}'.format(data))
|
||||||
|
common.logger.debug(str(e))
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
common.logger.debug("Lemonbar output closed")
|
common.logger.debug("Lemonbar output closed")
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ class LemonModule(threading.Thread):
|
|||||||
self._stop_module()
|
self._stop_module()
|
||||||
|
|
||||||
def parse(self, line):
|
def parse(self, line):
|
||||||
# TODO get rid of prefix
|
data = line.split()
|
||||||
data = line[len(self.prefix):].split()
|
|
||||||
self._parse_data(data) # Update correct field
|
self._parse_data(data) # Update correct field
|
||||||
|
|
||||||
formatted_line = parser.format_line() # Construct entire line
|
formatted_line = parser.format_line() # Construct entire line
|
||||||
@@ -53,11 +52,7 @@ class LemonModule(threading.Thread):
|
|||||||
action = action_arr[0]
|
action = action_arr[0]
|
||||||
if (action in self.actions):
|
if (action in self.actions):
|
||||||
func = self.actions[action]
|
func = self.actions[action]
|
||||||
if len(action_arr) == 1:
|
func(*action_arr[1:]) # Unpack arguments, if any
|
||||||
# Function has no arguments
|
|
||||||
func()
|
|
||||||
else:
|
|
||||||
func(action_arr[1:])
|
|
||||||
|
|
||||||
def format_load(data, module, alert):
|
def format_load(data, module, alert):
|
||||||
# Helper function to format network modules
|
# Helper function to format network modules
|
||||||
@@ -79,7 +74,7 @@ def format_load(data, module, alert):
|
|||||||
class ConkyFastModule(LemonModule):
|
class ConkyFastModule(LemonModule):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prefix = 'CNK_FAST'
|
self.show_secs = False
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def _start_module(self):
|
def _start_module(self):
|
||||||
@@ -135,7 +130,7 @@ class ConkyFastModule(LemonModule):
|
|||||||
|
|
||||||
# Date and time
|
# Date and time
|
||||||
self.date.items = [(config.icon_clock, ' '.join(data[0:3]))]
|
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):
|
def nmtui(self):
|
||||||
p = subprocess.Popen(['xterm', '-class', 'FLOAT_TERM', '-e', 'nmtui'])
|
p = subprocess.Popen(['xterm', '-class', 'FLOAT_TERM', '-e', 'nmtui'])
|
||||||
@@ -145,18 +140,17 @@ class ConkyFastModule(LemonModule):
|
|||||||
p = subprocess.Popen(['pavucontrol', '--class=FLOAT_PAVU'])
|
p = subprocess.Popen(['pavucontrol', '--class=FLOAT_PAVU'])
|
||||||
common.kill_on_unfocus.append(p.pid)
|
common.kill_on_unfocus.append(p.pid)
|
||||||
|
|
||||||
def date_comm(args):
|
def date_comm(self):
|
||||||
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
|
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
|
||||||
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
|
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
|
||||||
, '--close-on-unfocus'])
|
, '--close-on-unfocus'])
|
||||||
|
|
||||||
def toggle_secs(args):
|
def toggle_secs(self):
|
||||||
common.show_secs = not common.show_secs
|
self.show_secs = not self.show_secs
|
||||||
|
|
||||||
class ConkySlowModule(LemonModule):
|
class ConkySlowModule(LemonModule):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prefix = 'CNK_SLOW'
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def _start_module(self):
|
def _start_module(self):
|
||||||
@@ -236,6 +230,7 @@ class ConkySlowModule(LemonModule):
|
|||||||
common.kill_on_unfocus.append(p.pid)
|
common.kill_on_unfocus.append(p.pid)
|
||||||
|
|
||||||
def lang_comm(self):
|
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'])
|
subprocess.Popen(['sh', '/home/kuba/.i3/scripts/lang.sh', 'next'])
|
||||||
|
|
||||||
def dpms_comm(self):
|
def dpms_comm(self):
|
||||||
@@ -254,6 +249,10 @@ class i3Module(LemonModule):
|
|||||||
self.win_title = ''
|
self.win_title = ''
|
||||||
self.workspaces = ''
|
self.workspaces = ''
|
||||||
|
|
||||||
|
self.def_keymap = 'pl'
|
||||||
|
self.keymaps = {'firefox': 'se'}
|
||||||
|
self.cur_class = ''
|
||||||
|
|
||||||
def _start_module(self):
|
def _start_module(self):
|
||||||
self.i3_ws_obj = wspaces.i3ws(logger=common.logger)
|
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)
|
self.i3_ws_obj.focus_callbacks.append(self.parse_title)
|
||||||
|
|
||||||
# Add callbacks for special actions
|
# Add callbacks for special actions
|
||||||
self.i3_ws_obj.change_callbacks.append(i3Module.set_bg)
|
self.i3_ws_obj.change_callbacks.append(self.set_bg)
|
||||||
self.i3_ws_obj.focus_callbacks.append(i3Module.set_keymap)
|
self.i3_ws_obj.focus_callbacks.append(self.set_keymap)
|
||||||
self.i3_ws_obj.focus_callbacks.append(i3Module.kill_floating_windows)
|
self.i3_ws_obj.focus_callbacks.append(self.kill_floating_windows)
|
||||||
|
|
||||||
def _stop_module(self):
|
def _stop_module(self):
|
||||||
parser.g_parser.remove_unit(self.displays)
|
parser.g_parser.remove_unit(self.displays)
|
||||||
@@ -378,7 +377,7 @@ class i3Module(LemonModule):
|
|||||||
9: '9',
|
9: '9',
|
||||||
}.get(int(num), 'default')
|
}.get(int(num), 'default')
|
||||||
|
|
||||||
def set_bg(i3ws):
|
def set_bg(self, i3ws):
|
||||||
cmd_args = ['sh', '/home/kuba/scripts/set_bg.sh']
|
cmd_args = ['sh', '/home/kuba/scripts/set_bg.sh']
|
||||||
for output in i3ws.outputs:
|
for output in i3ws.outputs:
|
||||||
if output.active:
|
if output.active:
|
||||||
@@ -386,7 +385,7 @@ class i3Module(LemonModule):
|
|||||||
cmd_args.append(bg)
|
cmd_args.append(bg)
|
||||||
subprocess.call(cmd_args)
|
subprocess.call(cmd_args)
|
||||||
|
|
||||||
def kill_floating_windows(i3ws):
|
def kill_floating_windows(self, i3ws):
|
||||||
if i3ws.focused_window is None:
|
if i3ws.focused_window is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -401,26 +400,24 @@ class i3Module(LemonModule):
|
|||||||
common.logger.debug('Tried killing process {} but it doesn\'t exist'.format(pid))
|
common.logger.debug('Tried killing process {} but it doesn\'t exist'.format(pid))
|
||||||
common.kill_on_unfocus = []
|
common.kill_on_unfocus = []
|
||||||
|
|
||||||
def set_keymap(i3ws):
|
def set_keymap(self, i3ws):
|
||||||
if i3ws.focused_window is None:
|
if i3ws.focused_window is None:
|
||||||
return
|
return
|
||||||
wclass = i3ws.focused_window.window_class
|
wclass = i3ws.focused_window.window_class
|
||||||
common.cur_class = wclass
|
self.cur_class = wclass
|
||||||
|
|
||||||
if wclass in common.keymaps:
|
if wclass in self.keymaps:
|
||||||
new_km = common.keymaps[wclass]
|
new_km = self.keymaps[wclass]
|
||||||
common.logger.debug('Setting {} as keymap for {}'.format(new_km, wclass))
|
common.logger.debug('Setting {} as keymap for {}'.format(new_km, wclass))
|
||||||
else:
|
else:
|
||||||
new_km = common.def_keymap
|
new_km = self.def_keymap
|
||||||
common.logger.debug('Setting default keymap {} for {}'.format(new_km, wclass))
|
common.logger.debug('Setting default keymap {} for {}'.format(new_km, wclass))
|
||||||
subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km])
|
subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km])
|
||||||
|
|
||||||
def i3msg_comm(self, args):
|
def i3msg_comm(self, *cmd):
|
||||||
# TODO this is not needed anymore. Use i3ws object directly
|
self.i3_ws_obj.command(' '.join(cmd))
|
||||||
subprocess.Popen(['i3-msg'] + args)
|
|
||||||
|
|
||||||
def set_mode(self, args):
|
def set_mode(self, new_mode):
|
||||||
new_mode = args[0]
|
|
||||||
if new_mode == "cycle":
|
if new_mode == "cycle":
|
||||||
common.mode = common.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]
|
start_flags = ['-d', '-m', '-U', '-L', '-Logfile', config.fifo_screen_log]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prefix = ''
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def _start_module(self):
|
def _start_module(self):
|
||||||
self.identifier = 'lemonbar_{}_{}'.format(getpass.getuser(), os.getpid())
|
self.identifier = 'lemonbar_{}_{}'.format(getpass.getuser(), os.getpid())
|
||||||
self.empty_count = 0
|
self.empty_count = 0
|
||||||
common.screen_send_cmd = self.send_cmd
|
|
||||||
common.create_new_fifo(config.fifo_screen_log)
|
common.create_new_fifo(config.fifo_screen_log)
|
||||||
self.send(self.start_flags) # Start screen
|
self.send(self.start_flags) # Start screen
|
||||||
self.send_cmd('stty -echo') # Do not echo what is written to screen terminal
|
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
|
# Send colon command to our screen instance
|
||||||
self.send(['-X', 'colon', cmd + '\n'])
|
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]
|
btcargs = [a.replace('pxc550', '00:16:94:22:29:0E') for a in args]
|
||||||
inp = ' '.join(btcargs)
|
inp = ' '.join(btcargs)
|
||||||
common.screen_send_cmd('bluetoothctl ' + inp)
|
self.send_cmd('bluetoothctl ' + inp)
|
||||||
|
|
||||||
class PowerOptionsModule(LemonModule):
|
class PowerOptionsModule(LemonModule):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.prefix = ''
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def _start_module(self):
|
def _start_module(self):
|
||||||
|
|||||||
@@ -141,6 +141,9 @@ class i3ws(object):
|
|||||||
out += item
|
out += item
|
||||||
return self.end_format % out
|
return self.end_format % out
|
||||||
|
|
||||||
|
def command(self, cmd):
|
||||||
|
self.conn.command(cmd)
|
||||||
|
|
||||||
def display(self, text):
|
def display(self, text):
|
||||||
global print_stdout
|
global print_stdout
|
||||||
if print_stdout:
|
if print_stdout:
|
||||||
|
|||||||
Reference in New Issue
Block a user