summaryrefslogtreecommitdiff
path: root/monitor-menu.py
diff options
context:
space:
mode:
Diffstat (limited to 'monitor-menu.py')
-rwxr-xr-xmonitor-menu.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/monitor-menu.py b/monitor-menu.py
index f8baa7a..8a77c41 100755
--- a/monitor-menu.py
+++ b/monitor-menu.py
@@ -83,28 +83,25 @@ class Profile:
subprocess.run(feh_cmd, check=False)
-class MonitorMenu():
- def __init__(self, config_file='~/.config/monitor-profiles.json'):
- with open(expanduser(config_file)) as fh:
- data = json.load(fh)
- self.profiles = [Profile.from_json_dict(item) for item in data]
+class MonitorMenu:
+ def __init__(self, profiles: list[Profile]) -> None:
+ self.profiles = profiles
self.d = dialog.Dialog(autowidgetsize=True)
- def run(self, profile_idx=None):
+ def run(self):
choices = []
- if profile_idx is None:
- i = 0
- for p in self.profiles:
- choices.append((str(i), p.name))
- i += 1
+ i = 0
+ for p in self.profiles:
+ choices.append((str(i), p.name))
+ i += 1
- code, profile_idx = self.d.menu(
- 'Select the profile you want to use.',
- choices=choices)
+ code, profile_idx = self.d.menu(
+ 'Select the profile you want to use.',
+ choices=choices)
- if code in (self.d.ESC, self.d.CANCEL):
- return
+ if code in (self.d.ESC, self.d.CANCEL):
+ return
try:
self.profiles[int(profile_idx)].apply()
@@ -119,12 +116,18 @@ def main():
args = parser.parse_args()
logging.basicConfig(level=args.log_level.numerical_level)
- menu = MonitorMenu()
+ config_file = '~/.config/monitor-profiles.json'
+ with open(expanduser(config_file)) as fh:
+ data = json.load(fh)
+ profiles = [Profile.from_json_dict(item) for item in data]
- if args.index is not None:
- menu.run(profile_idx=args.index)
+ if args.index is None:
+ MonitorMenu(profiles).run()
else:
- menu.run()
+ try:
+ profiles[args.index].apply()
+ except IndexError:
+ raise NoMatchingProfile from None
if __name__ == '__main__':