created all_modules tuple and cleaned up
This commit is contained in:
parent
f20c2a1d76
commit
03e19af3c7
3 changed files with 19 additions and 135 deletions
|
@ -1,3 +1,4 @@
|
|||
from os import altsep
|
||||
from threading import Thread
|
||||
from subprocess import run
|
||||
from time import sleep
|
||||
|
@ -8,7 +9,7 @@ class Module:
|
|||
text = ""
|
||||
|
||||
# Parse the raw module configuration
|
||||
def __init__(self, module_config, padding):
|
||||
def __init__(self, module_config, padding, all_modules):
|
||||
# Attributes that will be extracted from the config
|
||||
self.name = ""
|
||||
self.alignment = ""
|
||||
|
@ -18,6 +19,9 @@ class Module:
|
|||
self.refresh = 0
|
||||
self.post =""
|
||||
self.padding = padding
|
||||
# We pass in a tuple containing the lists of modules sorted by
|
||||
# alignment, so we can print all of them.
|
||||
self.all_modules = all_modules
|
||||
|
||||
for option in module_config:
|
||||
match option:
|
||||
|
@ -77,9 +81,6 @@ class Module:
|
|||
self.pre = ("%{A" + str(button)+ ":" + button_options["command"] + ":}") + self.pre
|
||||
self.post += "%{A}"
|
||||
|
||||
def get_text(self):
|
||||
return self.text
|
||||
|
||||
def generate_text(self):
|
||||
text = self.pre + self.padding + self.prefix
|
||||
text += run(self.command, shell=True, capture_output=True, text=True).stdout.strip()
|
||||
|
@ -87,17 +88,17 @@ class Module:
|
|||
self.text = text
|
||||
|
||||
def thread_callback(self):
|
||||
self.generate_text()
|
||||
print(self.text)
|
||||
#while True:
|
||||
# self.text = self.generate_text()
|
||||
# #print_bar()
|
||||
# if self.refresh == 0:
|
||||
# break
|
||||
# sleep(self.refresh/1000)
|
||||
while True:
|
||||
# Generate new text
|
||||
self.generate_text()
|
||||
|
||||
print(self.text)
|
||||
|
||||
if self.refresh == 0:
|
||||
break
|
||||
|
||||
sleep(self.refresh/1000)
|
||||
|
||||
def start_thread(self):
|
||||
thread = Thread(target=self.thread_callback)
|
||||
thread.start()
|
||||
|
||||
|
||||
|
|
|
@ -1,66 +1,18 @@
|
|||
from Module import Module
|
||||
from parse_config_file import get_bar_config_and_module_config_list
|
||||
#from threading import Thread
|
||||
#from subprocess import run
|
||||
#from time import sleep
|
||||
#from config_parsing import get_validated_config, parse_module
|
||||
#
|
||||
#running_modules_dict = {"left": {}, "center": {}, "right": {}}
|
||||
#
|
||||
#def print_bar():
|
||||
# for alignment in running_modules_dict:
|
||||
# match alignment:
|
||||
# case "left":
|
||||
# print("%{l}" + margin, end="")
|
||||
# case "center":
|
||||
# print("%{c}", end="")
|
||||
# case "right":
|
||||
# print("%{r}", end="")
|
||||
# # convert group to list so we can access subsequent items
|
||||
# group = list(running_modules_dict[alignment].values())
|
||||
# for index, module in enumerate(group):
|
||||
# print(module, end="")
|
||||
# # IF module is not the last AND it has text
|
||||
# if index != (len(group) - 1) and len(module) > 0:
|
||||
# # THEN only print seperator if the module is eventually followed
|
||||
# # by a module with text
|
||||
# for i in range(index + 1, len(group)):
|
||||
# if len(group[i]) > 0:
|
||||
# print(seperator, end="")
|
||||
# break;
|
||||
# if alignment == "right":
|
||||
# print(margin, end="")
|
||||
#
|
||||
# print(flush=True)
|
||||
#
|
||||
#def create_module_string(pre, prefix, command, post):
|
||||
# cmd_output = run(command, shell=True, capture_output=True, text=True).stdout.strip()
|
||||
# if cmd_output != "":
|
||||
# return (pre + padding + prefix + cmd_output + padding + post)
|
||||
# else:
|
||||
# return cmd_output
|
||||
#
|
||||
#
|
||||
#def new_module_thread(alignment, pre, name, prefix, command, post, refresh):
|
||||
# running_modules_dict[alignment][name] = ""
|
||||
# while True:
|
||||
# module_string = create_module_string(pre, prefix, command, post)
|
||||
# running_modules_dict[alignment][name] = module_string
|
||||
# print_bar()
|
||||
# if refresh == 0:
|
||||
# break
|
||||
# sleep(refresh/1000)
|
||||
|
||||
|
||||
def main():
|
||||
bar_config, module_config_list = get_bar_config_and_module_config_list("/home/noah/src/easyconf-lemonbar/data/testing_config.yml")
|
||||
padding = bar_config["padding"]
|
||||
|
||||
left_modules = []
|
||||
center_modules = []
|
||||
right_modules = []
|
||||
|
||||
all_modules = (left_modules, center_modules, right_modules)
|
||||
|
||||
for module_config in module_config_list:
|
||||
module = Module(module_config, padding)
|
||||
module = Module(module_config, padding, all_modules)
|
||||
match module.alignment:
|
||||
case "left":
|
||||
left_modules.append(module)
|
||||
|
|
|
@ -84,72 +84,3 @@ def get_lemonbar_flags(config):
|
|||
case 'line_color':
|
||||
flags += (" -U '" + configuration_options[option] + "'")
|
||||
return flags.strip()
|
||||
|
||||
def parse_module(module):
|
||||
alignment = ""
|
||||
pre = ""
|
||||
name = ""
|
||||
prefix = ""
|
||||
command = ""
|
||||
refresh = 0
|
||||
post =""
|
||||
|
||||
for option in module:
|
||||
match option:
|
||||
case "name":
|
||||
name = module[option]
|
||||
case "command":
|
||||
command = module[option]
|
||||
case "refresh":
|
||||
refresh = module[option]
|
||||
case "prefix":
|
||||
prefix = module[option]
|
||||
|
||||
format_options = module["format"]
|
||||
for option in format_options:
|
||||
match option:
|
||||
case "align":
|
||||
alignment = format_options[option]
|
||||
case "offset":
|
||||
pre = ("%{O" + str(format_options[option]) + "}") + pre
|
||||
case "bg_color":
|
||||
pre = ("%{B" + format_options[option] + "}") + pre
|
||||
post += "%{B-}"
|
||||
case "fg_color":
|
||||
pre = ("%{F" + format_options[option] + "}") + pre
|
||||
post += "%{F-}"
|
||||
case "font":
|
||||
pre = ("%{T" + format_options[option] + "}") + pre
|
||||
post += "%{T-}"
|
||||
case "line":
|
||||
line_options = format_options[option]
|
||||
for line_option in line_options:
|
||||
match line_option:
|
||||
case "type":
|
||||
if line_options[line_option] == "underline":
|
||||
pre = ("%{+u}") + pre
|
||||
post += ("%{-u}")
|
||||
elif line_options[line_option] == "overline":
|
||||
pre = ("%{+o}") + pre
|
||||
post += ("%{-o}")
|
||||
case "color":
|
||||
pre = ("%{U" + line_options[line_option] + "}") + pre
|
||||
post += "%{U-}"
|
||||
case "button":
|
||||
button_options = format_options[option]
|
||||
button = 1
|
||||
match button_options["activator"]:
|
||||
case "left":
|
||||
button = 1
|
||||
case "middle":
|
||||
button = 2
|
||||
case "right":
|
||||
button = 3
|
||||
case "scrup":
|
||||
button = 4
|
||||
case "scrdown":
|
||||
button = 5
|
||||
pre = ("%{A" + str(button)+ ":" + button_options["command"] + ":}") + pre
|
||||
post += "%{A}"
|
||||
|
||||
return [alignment, pre, name, prefix, command, post, refresh]
|
||||
|
|
Loading…
Reference in a new issue