From e1752506c5111bc6e94dc9396734eaa65224d44d Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 24 Jul 2020 14:51:26 +0100 Subject: [PATCH] Move "only run once" code into def enforce_single_instance() --- EDMarketConnector.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 8867dfbf..c48ed103 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -880,13 +880,12 @@ class AppWindow(object): self.theme_menubar.grid_remove() self.blank_menubar.grid(row=0, columnspan=2, sticky=tk.NSEW) -# Run the app -if __name__ == "__main__": +def enforce_single_instance() -> None: # Ensure only one copy of the app is running under this user account. OSX does this automatically. Linux TODO. if platform == 'win32': import ctypes - from ctypes.wintypes import * + from ctypes.wintypes import HWND, LPWSTR, LPCWSTR, INT, BOOL, LPARAM EnumWindows = ctypes.windll.user32.EnumWindows GetClassName = ctypes.windll.user32.GetClassNameW GetClassName.argtypes = [HWND, LPWSTR, ctypes.c_int] @@ -935,6 +934,10 @@ if __name__ == "__main__": EnumWindows(enumwindowsproc, 0) +# Run the app +if __name__ == "__main__": + + enforce_single_instance() if getattr(sys, 'frozen', False): # By default py2exe tries to write log to dirname(sys.executable) which fails when installed import tempfile