limit the choices in argparse to the enum values

This commit is contained in:
2023-01-20 23:28:31 +01:00
parent e03df61601
commit 7dd8363dcc
2 changed files with 10 additions and 4 deletions

View File

@ -5,6 +5,7 @@ from PyQt5.QtWidgets import QApplication
from . import ctrl_c, theme
from .mainwin import MainWindow
from .mdi import MDIWindowMode
def main():
@ -26,7 +27,7 @@ def handle_clargs():
parser.add_argument("-e", "--examples", dest="add_examples", action="store_true", help="Add example data")
parser.add_argument("-w", "--window-mode", default="multi", help='Set the window mode to either "single", "multi" or "tabs"')
parser.add_argument("-w", "--window-mode", default="multi", choices=MDIWindowMode.values(), help="Set the initial window mode")
return parser.parse_args().__dict__

View File

@ -8,9 +8,14 @@ from ..menus import BarMenu
class MDIWindowMode(str, enum.Enum):
MULTI = "multi"
SINGLE = "single"
MULTI = "multi"
TABS = "tabs"
TABS = "tabs"
@classmethod
def values(cls):
return tuple(i.value for i in cls)
class MDIArea(QMdiArea):
@ -37,7 +42,7 @@ class MDIArea(QMdiArea):
menu.addAction("Close inactive", self.closeInactiveSubWindows)
def set_window_mode(self, mode:MDIWindowMode) -> None:
def set_window_mode(self, mode: MDIWindowMode) -> None:
mode_enablers = {
MDIWindowMode.SINGLE: self.enable_single_window_mode,
MDIWindowMode.MULTI: self.enable_multiple_windows_mode,