diff options
Diffstat (limited to 'monitor_menu/__main__.py')
-rw-r--r-- | monitor_menu/__main__.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/monitor_menu/__main__.py b/monitor_menu/__main__.py index fce1a65..91942e2 100644 --- a/monitor_menu/__main__.py +++ b/monitor_menu/__main__.py @@ -127,7 +127,7 @@ class MonitorMenu: self.profiles = profiles self.d = dialog.Dialog(autowidgetsize=True) - def run(self, graphical_server: GraphicalServer | None = None): + def run(self, *, graphical_server: GraphicalServer | None = None, apply_exit=False): choices = [] i = 0 @@ -135,17 +135,20 @@ class MonitorMenu: choices.append((str(i), p.name)) i += 1 - code, profile_idx = self.d.menu( - 'Select the profile you want to use.', - choices=choices) + while True: + 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(graphical_server=graphical_server) - except IndexError: - raise NoMatchingProfile from None + try: + self.profiles[int(profile_idx)].apply(graphical_server=graphical_server) + if apply_exit: + return + except IndexError: + raise NoMatchingProfile from None def main(): @@ -153,7 +156,8 @@ def main(): parser.add_argument("--log-level", "--loglevel", type=LogLevel, default="info") parser.add_argument("--graphical-server", choices=("wayland", "xorg")) subparser = parser.add_subparsers(dest="command") - subparser.add_parser("run") + run_parser = subparser.add_parser("run") + run_parser.add_argument("--apply-exit", action="store_true") apply_parser = subparser.add_parser("apply") identifier_group = apply_parser.add_mutually_exclusive_group(required=True) identifier_group.add_argument("--index", type=int) @@ -172,8 +176,10 @@ def main(): profiles = [Profile.from_json_dict(item) for item in data] match args.command: - case "run" | None: + case None: MonitorMenu(profiles).run(graphical_server=args.graphical_server) + case "run": + MonitorMenu(profiles).run(apply_exit=args.apply_exit, graphical_server=args.graphical_server) case "apply": if args.index is not None: try: |