diff --git a/CommonClient.py b/CommonClient.py index c367bd47ee..5fbc0f1b06 100755 --- a/CommonClient.py +++ b/CommonClient.py @@ -24,7 +24,7 @@ if __name__ == "__main__": from MultiServer import CommandProcessor, mark_raw from NetUtils import (Endpoint, decode, NetworkItem, encode, JSONtoTextParser, ClientStatus, Permission, NetworkSlot, RawJSONtoTextParser, add_json_text, add_json_location, add_json_item, JSONTypes, HintStatus, SlotType) -from Utils import Version, stream_input, async_start +from Utils import gui_enabled, Version, stream_input, async_start from worlds import network_data_package, AutoWorldRegister import os import ssl @@ -35,9 +35,6 @@ if typing.TYPE_CHECKING: logger = logging.getLogger("Client") -# without terminal, we have to use gui mode -gui_enabled = not sys.stdout or "--nogui" not in sys.argv - @Utils.cache_argsless def get_ssl_context(): diff --git a/Utils.py b/Utils.py index a7121fa391..bf46d0832d 100644 --- a/Utils.py +++ b/Utils.py @@ -914,6 +914,13 @@ def open_directory(title: str, suggest: str = "") -> typing.Optional[str]: def messagebox(title: str, text: str, error: bool = False) -> None: + if not gui_enabled: + if error: + logging.error(f"{title}: {text}") + else: + logging.info(f"{title}: {text}") + return + if is_kivy_running(): from kvui import MessageBox MessageBox(title, text, error).open() @@ -949,6 +956,9 @@ def messagebox(title: str, text: str, error: bool = False) -> None: root.update() +gui_enabled = not sys.stdout or "--nogui" not in sys.argv +"""Checks if the user wanted no GUI mode and has a terminal to use it with.""" + def title_sorted(data: typing.Iterable, key=None, ignore: typing.AbstractSet[str] = frozenset(("a", "the"))): """Sorts a sequence of text ignoring typical articles like "a" or "the" in the beginning.""" def sorter(element: Union[str, Dict[str, Any]]) -> str: