From b3aa77b4167128f142993b17edead3a180d67ede Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 25 Aug 2021 01:33:20 -0400 Subject: [PATCH] added the condition property for buttons --- README.md | 3 ++- sysmenu.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 636ad56..b84ea0f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The `global` section can be used to define general styling. this includes: `background`: hex color `foreground`: hex color -`highlight`: hex color (color on hover) +`highlight`: hex color, color on hover `padding_x`: integer `padding_y`: integer @@ -36,6 +36,7 @@ All components have the following properties: Buttons are defined in a section that starts with `button:`, and perform an action when clicked. They're also highlighted on hover. They have the following extra properties: `command`: the shell command to run on click +`condition`: an evaluated expression that returns "true" if the button should be enabled. #### Label diff --git a/sysmenu.py b/sysmenu.py index 872a952..37ce773 100755 --- a/sysmenu.py +++ b/sysmenu.py @@ -94,6 +94,10 @@ def make_button(name: str): ) if 'font' in spec: button.configure(font = font(spec['font'])) + if 'condition' in spec: + state = beval(spec['condition']); + if state.lower() != "true": + button['state'] = 'disabled' components.append(button) def make_label(name: str):