diff --git a/SNIClient.py b/SNIClient.py index 0563b494..e313feff 100644 --- a/SNIClient.py +++ b/SNIClient.py @@ -18,7 +18,7 @@ from json import loads, dumps import ModuleUpdate ModuleUpdate.update() -from Utils import init_logging +from Utils import init_logging, messagebox if __name__ == "__main__": init_logging("SNIClient", exception_logger="Client") @@ -1303,7 +1303,11 @@ async def main(): if args.diff_file: import Patch logging.info("Patch file was supplied. Creating sfc rom..") - meta, romfile = Patch.create_rom_file(args.diff_file) + try: + meta, romfile = Patch.create_rom_file(args.diff_file) + except Exception as e: + messagebox('Error', str(e), True) + raise if "server" in meta: args.connect = meta["server"] logging.info(f"Wrote rom file to {romfile}") @@ -1366,8 +1370,13 @@ def get_alttp_settings(romfile: str): if gui_enabled: - from tkinter import Tk, PhotoImage, Label, LabelFrame, Frame, Button - applyPromptWindow = Tk() + try: + from tkinter import Tk, PhotoImage, Label, LabelFrame, Frame, Button + applyPromptWindow = Tk() + except Exception as e: + logging.error('Could not load tkinter, which is likely not installed.') + return '', False + applyPromptWindow.resizable(False, False) applyPromptWindow.protocol('WM_DELETE_WINDOW', lambda: onButtonClick()) logo = PhotoImage(file=Utils.local_path('data', 'icon.png')) diff --git a/Utils.py b/Utils.py index a19f66bf..e13a5fe7 100644 --- a/Utils.py +++ b/Utils.py @@ -568,6 +568,9 @@ def open_filename(title: str, filetypes: typing.Sequence[typing.Tuple[str, typin def messagebox(title: str, text: str, error: bool = False) -> None: + def run(*args: str): + return subprocess.run(args, capture_output=True, text=True).stdout.split('\n', 1)[0] or None + def is_kivy_running(): if 'kivy' in sys.modules: from kivy.app import App @@ -579,6 +582,15 @@ def messagebox(title: str, text: str, error: bool = False) -> None: MessageBox(title, text, error).open() return + if is_linux and not 'tkinter' in sys.modules: + # prefer native dialog + kdialog = shutil.which('kdialog') + if kdialog: + return run(kdialog, f'--title={title}', '--error' if error else '--msgbox', text) + zenity = shutil.which('zenity') + if zenity: + return run(zenity, f'--title={title}', f'--text={text}', '--error' if error else '--info') + # fall back to tk try: import tkinter