Start implementing actions in modules. Change terminator to xterm as it doesnt spawn another child process
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user