formatting configuration options; strip property now determines how/whether to strip an evaluated text property
This commit is contained in:
parent
ad55eab84d
commit
9a0563d8ff
1 changed files with 24 additions and 4 deletions
28
sysmenu.py
28
sysmenu.py
|
@ -48,8 +48,20 @@ def run(command):
|
|||
Popen(command, shell = True)
|
||||
exit()
|
||||
|
||||
def beval(expression):
|
||||
return check_output(f'echo {expression}', shell = True).strip()
|
||||
def beval(expression, striptype = 'both'):
|
||||
output = check_output(f'echo "{expression}"', shell = True).decode('utf-8')
|
||||
if striptype == 'both':
|
||||
return output.strip()
|
||||
elif striptype == 'right':
|
||||
return output.rstrip()
|
||||
elif striptype == 'left':
|
||||
return output.lstrip()
|
||||
elif striptype == 'none':
|
||||
return output
|
||||
else:
|
||||
print(f'sysmenu: invalid strip type "{striptype}"; must be "both", "right", "left", or "none".')
|
||||
exit(1)
|
||||
|
||||
def font(name):
|
||||
sec = f'font:{name}'
|
||||
if sec not in config:
|
||||
|
@ -61,7 +73,10 @@ def make_button(name: str):
|
|||
spec = config[name]
|
||||
text = spec['text']
|
||||
if 'eval' in spec and bool(spec['eval']):
|
||||
text = beval(text)
|
||||
if 'strip' in spec:
|
||||
text = beval(text, spec['strip'])
|
||||
else:
|
||||
text = beval(text)
|
||||
button = Button(
|
||||
root,
|
||||
text = text,
|
||||
|
@ -77,13 +92,18 @@ def make_button(name: str):
|
|||
padx = padding_x,
|
||||
pady = padding_y
|
||||
)
|
||||
if 'font' in spec:
|
||||
button.configure(font = font(spec['font']))
|
||||
components.append(button)
|
||||
|
||||
def make_label(name: str):
|
||||
spec = config[name]
|
||||
text = spec['text']
|
||||
if 'eval' in spec and bool(spec['eval']):
|
||||
text = beval(text)
|
||||
if 'strip' in spec:
|
||||
text = beval(text, spec['strip'])
|
||||
else:
|
||||
text = beval(text)
|
||||
label = Label(
|
||||
root,
|
||||
text = text
|
||||
|
|
Loading…
Reference in a new issue