summaryrefslogtreecommitdiff
path: root/monitor_menu/__main__.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2023-05-14 18:33:49 +0200
committerOlivier Gayot <olivier.gayot@sigexec.com>2023-05-14 18:43:05 +0200
commit73382682c8cfb3c87cae9d46d00c25829bbb9150 (patch)
treec5e4ddc5f256d1ebea6ed9bcb2af201b546321fb /monitor_menu/__main__.py
parent255f7df0df82206f9fcc26a707b1f7a86d146cb6 (diff)
When using the menu, do not exit after applying a profile
By default, when using the TUI, we will now stay in the menu after applying a profile. This allows to more easily fix the display is things go wrong after applying a profile. That said, sometimes the old behavior may be needed, so one can use the `run --apply-exit` option. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'monitor_menu/__main__.py')
-rw-r--r--monitor_menu/__main__.py30
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: