45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import argparse
|
|
import sys
|
|
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
from . import ctrl_c, theme
|
|
from .mainwin import MainWindow
|
|
from .mdi import MDIWindowMode
|
|
|
|
|
|
def main():
|
|
app = QApplication(sys.argv)
|
|
theme.apply(app)
|
|
ctrl_c.setup(app)
|
|
clargs = handle_clargs()
|
|
mw = MainWindow(**clargs)
|
|
mw.show()
|
|
sys.exit(app.exec())
|
|
|
|
|
|
def handle_clargs():
|
|
DESC = "grum - GUI for Remote Unified Monitoring"
|
|
parser = argparse.ArgumentParser(description=DESC, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
|
|
|
parser.add_argument("-H", "--host", default="localhost", help="Server host name")
|
|
parser.add_argument("-P", "--port", default=8000, type=int, help="Server port number")
|
|
|
|
parser.add_argument("-e", "--examples", dest="add_examples", action="store_true", help="Add example data")
|
|
|
|
parser.add_argument("-w", "--window-mode", default="multi", choices=MDIWindowMode.values(), type=unambiguous_window_mode, help="Set the initial window mode")
|
|
|
|
return parser.parse_args().__dict__
|
|
|
|
|
|
def unambiguous_window_mode(arg):
|
|
cfarg = arg.casefold()
|
|
values = MDIWindowMode.values()
|
|
matches = [i for i in values if i.casefold().startswith(cfarg)]
|
|
if len(matches) == 1:
|
|
return matches[0]
|
|
return arg
|
|
|
|
|
|
|