diff --git a/CommonClient.py b/CommonClient.py index b1d9aeb15624..cbf3b714ff49 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -24,7 +24,7 @@ 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 @@ 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 08e5dba8cdb8..75d42b549b59 100644 --- a/Utils.py +++ b/Utils.py @@ -850,6 +850,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() @@ -885,6 +892,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: