Start implementing actions in modules. Change terminator to xterm as it doesnt spawn another child process

This commit is contained in:
kuben
2019-09-19 21:56:11 +02:00
parent 9097a98884
commit 106f9fe47f
4 changed files with 34 additions and 7 deletions

View File

@@ -25,8 +25,7 @@ class bar_mode(Enum):
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)] # TODO URGENT solve without fifo
, 'dark', '-e', 'exec {}'.format(prog)] # TODO implement kill on lost focus
def date_comm(args):
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
@@ -76,7 +75,7 @@ def toggle_secs(args):
# Keymaps
def_keymap = 'pl'
keymaps = {'Firefox': 'se'}
keymaps = {'firefox': 'se'}
cur_class = ''
def set_lang(args):
global keymaps
@@ -87,7 +86,7 @@ commands_dict = {'toggle_secs': toggle_secs
,'date': date_comm
,'pavu': pavu_comm
,'load': htop_comm
,'wlan': nmtui_comm
#,'wlan': nmtui_comm
,'dpms': dpms_comm
,'i3-msg': i3msg_comm
,'switch_lang': lang_comm

View File

@@ -157,6 +157,7 @@ def exec_commands():
if data[:l] == key:
func(data)
break
modules.do_action(data.split()[0])
except:
common.logger.debug('Exception occured executing command\n Line in: {}\n Data: {}'.format(data, data[l:].split()))

View File

@@ -9,10 +9,12 @@ import i3_lemonbar_parser as parser
import i3_workspaces as wspaces
class LemonModule(threading.Thread):
# Module generates some status message, parses it, and handles on click actions
# Module spawns process that generates some status message, which the module parses and
# sends to lemonbar queue. On click actions are registered with the module.
# Every module runs in its own thread
def __init__(self):
self.actions = {}
super().__init__()
self._start_module()
@@ -43,6 +45,15 @@ class LemonModule(threading.Thread):
formatted_line = parser.format_line() # Construct entire line
return formatted_line
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()
# TODO If this is a floating window action, save handle to thread, so we may kill it
def format_load(data, module, alert):
# Helper function to format network modules
# Changes colors scheme to inactive when interfaces are down, or to alert when
@@ -85,6 +96,7 @@ class ConkyFastModule(LemonModule):
parser.g_parser.register_unit(self.date)
parser.g_parser.register_unit(self.time)
self.register_action('wlan', self.nmtui)
def _stop_module(self):
if self.p_handle is not None:
self.p_handle.terminate()
@@ -116,6 +128,9 @@ class ConkyFastModule(LemonModule):
self.date.items = [(config.icon_clock, ' '.join(data[0:3]))]
self.time.items = [('', data[3] if common.show_secs else data[3][:-3])]
def nmtui(self):
subprocess.Popen(['xterm', '-class', 'FLOAT_TERM', '-e', 'nmtui'])
class ConkySlowModule(LemonModule):
def __init__(self):
@@ -462,9 +477,18 @@ class PowerOptionsModule(LemonModule):
, ' Abort (Esc) | System (l) lock, (e) logout, (s) suspend, (h) hibernate'
, ', (r) reboot, (Shift+s) shutdown'])
def start_all():
def do_action(keyword):
global m_conky_fast, m_conky_slow, m_i3ws
m_i3ws.do_action(keyword)
m_conky_slow.do_action(keyword)
m_conky_fast.do_action(keyword)
m_screen.do_action(keyword)
m_power.do_action(keyword)
def start_all():
global m_conky_fast, m_conky_slow, m_i3ws, m_screen, m_power
m_i3ws = i3Module()
m_conky_slow = ConkySlowModule()
m_conky_fast = ConkyFastModule()
@@ -478,7 +502,7 @@ def start_all():
m_power.start()
def stop_all():
global m_conky_fast, m_conky_slow, m_i3ws
global m_conky_fast, m_conky_slow, m_i3ws, m_screen, m_power
m_i3ws.stop()
m_conky_slow.stop()