|
6 | 6 | __author__ = 'Simon Robinson' |
7 | 7 | __copyright__ = 'Copyright (c) 2023 Simon Robinson' |
8 | 8 | __license__ = 'Apache 2.0' |
9 | | -__version__ = '2023-11-02' # ISO 8601 (YYYY-MM-DD) |
| 9 | +__version__ = '2023-11-06' # ISO 8601 (YYYY-MM-DD) |
10 | 10 | __package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only |
11 | 11 |
|
12 | 12 | import abc |
|
60 | 60 | # where not having to install GUI-only requirements can be helpful - see the proxy's readme (the `--no-gui` option) |
61 | 61 | MISSING_GUI_REQUIREMENTS = [] |
62 | 62 |
|
63 | | -try: |
64 | | - import pystray # the menu bar/taskbar GUI |
65 | | -except ImportError as gui_requirement_import_error: |
66 | | - MISSING_GUI_REQUIREMENTS.append(gui_requirement_import_error) |
67 | | - |
| 63 | +no_gui_parser = argparse.ArgumentParser(add_help=False) |
| 64 | +no_gui_parser.add_argument('--no-gui', action='store_false', dest='gui') |
| 65 | +no_gui_args = no_gui_parser.parse_known_args()[0] |
| 66 | +if no_gui_args.gui: |
| 67 | + try: |
| 68 | + import pystray # the menu bar/taskbar GUI |
| 69 | + except Exception as gui_requirement_import_error: # see #204 - incomplete pystray installation can throw exceptions |
| 70 | + MISSING_GUI_REQUIREMENTS.append(gui_requirement_import_error) |
| 71 | + no_gui_args.gui = False # we need the dummy implementation |
68 | 72 |
|
| 73 | +if not no_gui_args.gui: |
69 | 74 | class DummyPystray: # dummy implementation allows initialisation to complete |
70 | 75 | class Icon: |
71 | 76 | pass |
72 | 77 |
|
73 | 78 |
|
74 | 79 | pystray = DummyPystray # this is just to avoid unignorable IntelliJ warnings about naming and spacing |
| 80 | +del no_gui_parser |
| 81 | +del no_gui_args |
75 | 82 |
|
76 | 83 | try: |
77 | 84 | # noinspection PyUnresolvedReferences |
@@ -104,7 +111,7 @@ class Icon: |
104 | 111 | try: |
105 | 112 | # PyUnresolvedReferences; see: youtrack.jetbrains.com/issue/PY-11963 (same for others with this suppression) |
106 | 113 | # noinspection PyPackageRequirements,PyUnresolvedReferences |
107 | | - import PyObjCTools # SIGTERM handling (only needed when in GUI mode; `signal` is sufficient otherwise) |
| 114 | + import PyObjCTools.MachSignals # SIGTERM handling (only needed in GUI mode; `signal` is sufficient otherwise) |
108 | 115 | except ImportError as gui_requirement_import_error: |
109 | 116 | MISSING_GUI_REQUIREMENTS.append(gui_requirement_import_error) |
110 | 117 |
|
|
0 commit comments