formatting configuration options; strip property now determines how/whether to strip an evaluated text property

This commit is contained in:
Valerie Wolfe 2021-07-09 16:48:51 -04:00
parent ad55eab84d
commit 9a0563d8ff

View file

@ -48,8 +48,20 @@ def run(command):
Popen(command, shell = True) Popen(command, shell = True)
exit() exit()
def beval(expression): def beval(expression, striptype = 'both'):
return check_output(f'echo {expression}', shell = True).strip() 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): def font(name):
sec = f'font:{name}' sec = f'font:{name}'
if sec not in config: if sec not in config:
@ -61,6 +73,9 @@ def make_button(name: str):
spec = config[name] spec = config[name]
text = spec['text'] text = spec['text']
if 'eval' in spec and bool(spec['eval']): if 'eval' in spec and bool(spec['eval']):
if 'strip' in spec:
text = beval(text, spec['strip'])
else:
text = beval(text) text = beval(text)
button = Button( button = Button(
root, root,
@ -77,12 +92,17 @@ def make_button(name: str):
padx = padding_x, padx = padding_x,
pady = padding_y pady = padding_y
) )
if 'font' in spec:
button.configure(font = font(spec['font']))
components.append(button) components.append(button)
def make_label(name: str): def make_label(name: str):
spec = config[name] spec = config[name]
text = spec['text'] text = spec['text']
if 'eval' in spec and bool(spec['eval']): if 'eval' in spec and bool(spec['eval']):
if 'strip' in spec:
text = beval(text, spec['strip'])
else:
text = beval(text) text = beval(text)
label = Label( label = Label(
root, root,