From cc7075c3dc3859c15eb2beca17d9c78820b68e99 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 14:19:43 -0500 Subject: [PATCH 01/13] Create factory system --- app/factory.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/factory.py diff --git a/app/factory.py b/app/factory.py new file mode 100644 index 0000000..605716b --- /dev/null +++ b/app/factory.py @@ -0,0 +1,29 @@ +from typing import Type, TypeVar +from abc import ABC, abstractmethod + +T = TypeVar("T") + + +class Factory[T](ABC): + @abstractmethod + def instantiate(*args, **kwargs) -> T: + pass + + +def factorify(T: Type[T], *default_args, **default_kwargs) -> Factory[T]: + def merged_args(default_args, args): + if len(args) >= len(default_args): + return [*args] + return [*args, *default_args[len(args) :]] + + def merged_kwargs(default_kwargs, kwargs): + return {**default_kwargs, **kwargs} + + class CustomFactory(Factory[T]): + def instantiate(*args, **kwargs) -> T: + return T( + *merged_args(default_args, args), + **merged_kwargs(default_kwargs, kwargs), + ) + + return CustomFactory From 8bc6e0507221e8e8c9f30419561a358264dc0fb7 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 16:15:53 -0500 Subject: [PATCH 02/13] Delete factory --- app/factory.py | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 app/factory.py diff --git a/app/factory.py b/app/factory.py deleted file mode 100644 index 605716b..0000000 --- a/app/factory.py +++ /dev/null @@ -1,29 +0,0 @@ -from typing import Type, TypeVar -from abc import ABC, abstractmethod - -T = TypeVar("T") - - -class Factory[T](ABC): - @abstractmethod - def instantiate(*args, **kwargs) -> T: - pass - - -def factorify(T: Type[T], *default_args, **default_kwargs) -> Factory[T]: - def merged_args(default_args, args): - if len(args) >= len(default_args): - return [*args] - return [*args, *default_args[len(args) :]] - - def merged_kwargs(default_kwargs, kwargs): - return {**default_kwargs, **kwargs} - - class CustomFactory(Factory[T]): - def instantiate(*args, **kwargs) -> T: - return T( - *merged_args(default_args, args), - **merged_kwargs(default_kwargs, kwargs), - ) - - return CustomFactory From 62ce271ad738d73f102b1eddd7c12060162f05e4 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 16:35:00 -0500 Subject: [PATCH 03/13] Implement some kind of tricky dependency injection system --- external_services/__init__.py | 5 +++ external_services/configuration.py | 11 ++++++ external_services/mail.py | 10 ++++++ mail/__init__.py | 15 +++++++- mail/mailjet.py | 56 ++++++++++++++++-------------- main.py | 9 +++-- 6 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 external_services/__init__.py create mode 100644 external_services/configuration.py create mode 100644 external_services/mail.py diff --git a/external_services/__init__.py b/external_services/__init__.py new file mode 100644 index 0000000..69ceae0 --- /dev/null +++ b/external_services/__init__.py @@ -0,0 +1,5 @@ +from mail import MailService + + +class ExternalServices: + mail_service: MailService = None diff --git a/external_services/configuration.py b/external_services/configuration.py new file mode 100644 index 0000000..2a75760 --- /dev/null +++ b/external_services/configuration.py @@ -0,0 +1,11 @@ +from external_services import ExternalServices + + +def _configure_mail(): + from .mail import mail_service + + ExternalServices.mail_service = mail_service + + +def configure(): + _configure_mail() diff --git a/external_services/mail.py b/external_services/mail.py new file mode 100644 index 0000000..2445a9d --- /dev/null +++ b/external_services/mail.py @@ -0,0 +1,10 @@ +import config +from mail.mailjet import MailJetService + +MAILJET_API_KEY = config.get("MAILJET_API_KEY") +MAILJET_API_SECRET = config.get("MAILJET_API_SECRET") + +mail_service = MailJetService( + api_key=MAILJET_API_KEY, + api_secret=MAILJET_API_SECRET, +) diff --git a/mail/__init__.py b/mail/__init__.py index d50b9fd..b5ebf83 100644 --- a/mail/__init__.py +++ b/mail/__init__.py @@ -1 +1,14 @@ -from .mailjet import send_mail +from abc import ABC, abstractmethod + + +class MailService(ABC): + @abstractmethod + def send_mail( + self, + email_from: str, + email_to: str, + subject: str, + text_part: str, + html_part: str | None = None, + ) -> bool: + return False diff --git a/mail/mailjet.py b/mail/mailjet.py index 638a994..21b658c 100644 --- a/mail/mailjet.py +++ b/mail/mailjet.py @@ -1,34 +1,38 @@ from mailjet_rest import Client -import config -MAILJET_API_KEY = config.get("MAILJET_API_KEY") -MAILJET_API_SECRET = config.get("MAILJET_API_SECRET") +from mail import MailService -mailjet = Client(auth=(MAILJET_API_KEY, MAILJET_API_SECRET), version="v3.1") +class MailJetService(MailService): + def __init__(self, api_key: str, api_secret: str, debug: bool = False) -> None: + super().__init__() + self._mailjet_client = Client(auth=(api_key, api_secret), version="v3.1") + self._debug = debug -def send_mail( - email_from: str, - email_to: str, - subject: str, - text_part: str, - html_part: str | None = None, -) -> bool: - data = { - "Messages": [ - { - "From": {"Email": email_from}, - "To": [{"Email": email_to}], - "Subject": subject, - "TextPart": text_part, - "HTMLPart": html_part, - } - ] - } + def send_mail( + self, + email_from: str, + email_to: str, + subject: str, + text_part: str, + html_part: str | None = None, + ) -> bool: + data = { + "Messages": [ + { + "From": {"Email": email_from}, + "To": [{"Email": email_to}], + "Subject": subject, + "TextPart": text_part, + "HTMLPart": html_part, + } + ] + } - response = mailjet.send.create(data=data) + response = self._mailjet_client.send.create(data=data) - print(response.status_code) - print(response.json()) + if self._debug: + print(response.status_code) + print(response.json()) - return response.ok + return response.ok diff --git a/main.py b/main.py index dfc8d13..85e209d 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,6 @@ from time import sleep import PySimpleGUIQt as sg -from mail import send_mail from monitoring import is_lol_runing import config @@ -10,6 +9,12 @@ import project_resource +from external_services import ExternalServices +import external_services.configuration as external_services_config + +external_services_config.configure() +mail_service = ExternalServices.mail_service + DEFAULT_MAIL_SENDER = config.get("DEFAULT_MAIL_SENDER") @@ -21,7 +26,7 @@ def monitor_user(): email_sent = False if subscriber_email: - email_sent = send_mail( + email_sent = mail_service.send_mail( DEFAULT_MAIL_SENDER, subscriber_email, "LoL Monitor Warning", From cd6c2407dfe27e98ec85138c51958ae2148976db Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 16:38:52 -0500 Subject: [PATCH 04/13] Move use_data --- main.py | 2 +- userdata.py => user_data/__init__.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename userdata.py => user_data/__init__.py (100%) diff --git a/main.py b/main.py index 85e209d..98b0f06 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from monitoring import is_lol_runing import config -from userdata import get_user_data, set_user_data +from user_data import get_user_data, set_user_data import project_resource diff --git a/userdata.py b/user_data/__init__.py similarity index 100% rename from userdata.py rename to user_data/__init__.py From 5b24559f5954723197f48fe2acf64aa2caab5369 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 16:45:31 -0500 Subject: [PATCH 05/13] Pass instead of return --- mail/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail/__init__.py b/mail/__init__.py index b5ebf83..a65319a 100644 --- a/mail/__init__.py +++ b/mail/__init__.py @@ -11,4 +11,4 @@ def send_mail( text_part: str, html_part: str | None = None, ) -> bool: - return False + pass From 250ff425c61ff7af61adec5c7cfcb2c8ed28839f Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 17:02:07 -0500 Subject: [PATCH 06/13] Di system for user_data --- external_services/__init__.py | 4 +++- external_services/configuration.py | 7 +++++++ external_services/user_data.py | 3 +++ main.py | 19 +++++++++++-------- user_data/__init__.py | 14 ++++++++------ user_data/pysg_provider.py | 15 +++++++++++++++ 6 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 external_services/user_data.py create mode 100644 user_data/pysg_provider.py diff --git a/external_services/__init__.py b/external_services/__init__.py index 69ceae0..6d72ac3 100644 --- a/external_services/__init__.py +++ b/external_services/__init__.py @@ -1,5 +1,7 @@ from mail import MailService +from user_data import UserDataProvider class ExternalServices: - mail_service: MailService = None + mail_service: MailService + user_data_provider: UserDataProvider diff --git a/external_services/configuration.py b/external_services/configuration.py index 2a75760..2b3a099 100644 --- a/external_services/configuration.py +++ b/external_services/configuration.py @@ -7,5 +7,12 @@ def _configure_mail(): ExternalServices.mail_service = mail_service +def _configure_user_data(): + from .user_data import user_data_provider + + ExternalServices.user_data_provider = user_data_provider + + def configure(): _configure_mail() + _configure_user_data() diff --git a/external_services/user_data.py b/external_services/user_data.py new file mode 100644 index 0000000..84fe8f0 --- /dev/null +++ b/external_services/user_data.py @@ -0,0 +1,3 @@ +from user_data.pysg_provider import SgUserDataProvider + +user_data_provider = SgUserDataProvider("__lol_monitor__") diff --git a/main.py b/main.py index 98b0f06..7a7b390 100644 --- a/main.py +++ b/main.py @@ -5,8 +5,6 @@ from monitoring import is_lol_runing import config -from user_data import get_user_data, set_user_data - import project_resource from external_services import ExternalServices @@ -14,6 +12,7 @@ external_services_config.configure() mail_service = ExternalServices.mail_service +user_data = ExternalServices.user_data_provider DEFAULT_MAIL_SENDER = config.get("DEFAULT_MAIL_SENDER") @@ -21,8 +20,8 @@ def monitor_user(): while True: if is_lol_runing(): - subscriber_email = get_user_data("subscriber_email") - name = get_user_data("name", "Someone") + subscriber_email = user_data.get_user_data("subscriber_email") + name = user_data.get_user_data("name", "Someone") email_sent = False if subscriber_email: @@ -48,11 +47,15 @@ def monitor_user(): def run_main_window(): layout = [ [sg.Text("Settings")], - [sg.Text("Your Name"), sg.InputText(get_user_data("name", ""), key="-NAME-")], + [ + sg.Text("Your Name"), + sg.InputText(user_data.get_user_data("name", ""), key="-NAME-"), + ], [ sg.Text("Subscriber Email"), sg.InputText( - get_user_data("subscriber_email", ""), key="-SUBSCRIBER_EMAIL-" + user_data.get_user_data("subscriber_email", ""), + key="-SUBSCRIBER_EMAIL-", ), ], [sg.Button("Save"), sg.Button("Close")], @@ -69,8 +72,8 @@ def run_main_window(): event, values = window.read() if event == "Save": - set_user_data("name", values["-NAME-"]) - set_user_data("subscriber_email", values["-SUBSCRIBER_EMAIL-"]) + user_data.set_user_data("name", values["-NAME-"]) + user_data.set_user_data("subscriber_email", values["-SUBSCRIBER_EMAIL-"]) elif event in [sg.WINDOW_CLOSED, "Close"]: break diff --git a/user_data/__init__.py b/user_data/__init__.py index fa43f86..5b2245e 100644 --- a/user_data/__init__.py +++ b/user_data/__init__.py @@ -1,9 +1,11 @@ -import PySimpleGUIQt as sg +from abc import ABC, abstractmethod -def set_user_data(key: str, value: str) -> None: - sg.user_settings_set_entry(key, value) +class UserDataProvider(ABC): + @abstractmethod + def set_user_data(self, key: str, value: str) -> None: + pass - -def get_user_data(key: str, default: str | None = None) -> str | None: - return sg.user_settings_get_entry(key, default) + @abstractmethod + def get_user_data(self, key: str, default: str | None = None) -> str | None: + pass diff --git a/user_data/pysg_provider.py b/user_data/pysg_provider.py new file mode 100644 index 0000000..6ba5d51 --- /dev/null +++ b/user_data/pysg_provider.py @@ -0,0 +1,15 @@ +import PySimpleGUIQt as sg + +from user_data import UserDataProvider + + +class SgUserDataProvider(UserDataProvider): + def __init__(self, settings_prefix: str = "") -> None: + super().__init__() + self._settings_prefix = settings_prefix + + def set_user_data(self, key: str, value: str) -> None: + sg.user_settings_set_entry(self._settings_prefix + key, value) + + def get_user_data(self, key: str, default: str | None = None) -> str | None: + return sg.user_settings_get_entry(self._settings_prefix + key, default) From 4f3567c3a189411c5fc625efec154d71106e3829 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 17:12:03 -0500 Subject: [PATCH 07/13] Handle kill events --- main.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 7a7b390..71b30f8 100644 --- a/main.py +++ b/main.py @@ -87,7 +87,7 @@ def run_system_tray(): ) while True: - menu_item = tray.read() + menu_item = tray.read(0) if menu_item == "Exit": break @@ -99,7 +99,20 @@ def run_system_tray(): tray.close() -if __name__ == "__main__": +def exit_application(signum, frame): + exit() + + +def main(): + import signal + + signal.signal(signal.SIGINT, exit_application) + signal.signal(signal.SIGTERM, exit_application) + lol_monitor_thread = threading.Thread(target=monitor_user, daemon=True) lol_monitor_thread.start() run_system_tray() + + +if __name__ == "__main__": + main() From 7b078835d391f3fe6efbef0915a8f745f48a83bf Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 17:25:36 -0500 Subject: [PATCH 08/13] Rename project_resource --- config.py | 4 ++-- file_utils.py | 7 +++++++ main.py | 6 +++--- project_resource.py | 7 ------- 4 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 file_utils.py delete mode 100644 project_resource.py diff --git a/config.py b/config.py index 15a0b2f..885d86a 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,7 @@ from dotenv import dotenv_values -import project_resource +import file_utils -_config = dotenv_values(project_resource.get_path(".env")) +_config = dotenv_values(file_utils.get_absolute_path(".env")) def get(key: str) -> str | None: diff --git a/file_utils.py b/file_utils.py new file mode 100644 index 0000000..29a0d8f --- /dev/null +++ b/file_utils.py @@ -0,0 +1,7 @@ +import os + +CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) + + +def get_absolute_path(local_path: str) -> str: + return os.path.join(CURRENT_DIRECTORY, local_path) diff --git a/main.py b/main.py index 71b30f8..1831dfc 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from monitoring import is_lol_runing import config -import project_resource +import file_utils from external_services import ExternalServices import external_services.configuration as external_services_config @@ -65,7 +65,7 @@ def run_main_window(): "LoL Monitor", layout, size=(300, 1), - icon=project_resource.get_path("rat.ico"), + icon=file_utils.get_absolute_path("rat.ico"), ) while True: @@ -83,7 +83,7 @@ def run_main_window(): def run_system_tray(): tray = sg.SystemTray( menu=["", ["Open", "Exit"]], - filename=project_resource.get_path("rat.ico"), + filename=file_utils.get_absolute_path("rat.ico"), ) while True: diff --git a/project_resource.py b/project_resource.py deleted file mode 100644 index f038418..0000000 --- a/project_resource.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) - - -def get_path(path: str) -> str: - return os.path.join(CURRENT_DIRECTORY, path) From f4ac9c8c8b2fdeec832004bd0142c6b8336c7314 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 19:03:42 -0500 Subject: [PATCH 09/13] Tray encapsulation --- tray/__init__.py | 31 +++++++++++++++++++++++++++++++ tray/pysg_tray.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tray/__init__.py create mode 100644 tray/pysg_tray.py diff --git a/tray/__init__.py b/tray/__init__.py new file mode 100644 index 0000000..ed74549 --- /dev/null +++ b/tray/__init__.py @@ -0,0 +1,31 @@ +from abc import ABC, abstractmethod + + +class Tray(ABC): + DOUBLE_CLICK_EVENT = "__DOUBLE_CLICK__" + + def __init__(self, icon_path: str, menu_items: list[str]) -> None: + self._icon_path = icon_path + self._menu_items = menu_items + self._visible = True + self._closed = False + self._listeners: dict[str,] = {} + + def set_visible(self, visible): + self._visible = visible + + def is_visible(self): + return self._visible + + def close(self): + self._closed = True + + def is_closed(self): + return self._closed + + def attach_listener(self, key, listener): + self._listeners[key] = listener + + @abstractmethod + def run(): + pass diff --git a/tray/pysg_tray.py b/tray/pysg_tray.py new file mode 100644 index 0000000..9156ac1 --- /dev/null +++ b/tray/pysg_tray.py @@ -0,0 +1,34 @@ +import PySimpleGUIQt as sg + +from tray import Tray + + +class SgTray(Tray): + DOUBLE_CLICK_EVENT = sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED + + def __init__(self, icon_path: str, menu_items: list[str]) -> None: + super().__init__(icon_path, menu_items) + + self._tray = sg.SystemTray( + menu=["", self._menu_items], + filename=self._icon_path, + ) + + def set_visible(self, visible): + super().set_visible(visible) + + if self.is_visible(): + self._tray.un_hide() + else: + self._tray.hide() + + def close(self): + super().close() + self._tray.close() + + def run(self): + while not self.is_closed(): + menu_item = self._tray.read(0) + + if menu_item in self._listeners: + self._listeners[menu_item](self) From c082d9a46615f4badfcd812e757a15c4cc253dc7 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 19:04:37 -0500 Subject: [PATCH 10/13] Add trayclass to di --- external_services/__init__.py | 4 ++++ external_services/configuration.py | 7 +++++++ external_services/tray.py | 3 +++ 3 files changed, 14 insertions(+) create mode 100644 external_services/tray.py diff --git a/external_services/__init__.py b/external_services/__init__.py index 6d72ac3..2be76f1 100644 --- a/external_services/__init__.py +++ b/external_services/__init__.py @@ -1,7 +1,11 @@ +from typing import Type + from mail import MailService from user_data import UserDataProvider +from tray import Tray class ExternalServices: mail_service: MailService user_data_provider: UserDataProvider + Tray: Type[Tray] diff --git a/external_services/configuration.py b/external_services/configuration.py index 2b3a099..28084ab 100644 --- a/external_services/configuration.py +++ b/external_services/configuration.py @@ -13,6 +13,13 @@ def _configure_user_data(): ExternalServices.user_data_provider = user_data_provider +def _configure_tray_class(): + from .tray import TrayClass + + ExternalServices.Tray = TrayClass + + def configure(): _configure_mail() _configure_user_data() + _configure_tray_class() diff --git a/external_services/tray.py b/external_services/tray.py new file mode 100644 index 0000000..71cb4cc --- /dev/null +++ b/external_services/tray.py @@ -0,0 +1,3 @@ +from tray.pysg_tray import SgTray + +TrayClass = SgTray From bc8b22bcd2387ca3609ba8c1e52cc83e650e497d Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Sat, 23 Mar 2024 19:05:18 -0500 Subject: [PATCH 11/13] Use tray from di --- main.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 1831dfc..9cf533f 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ external_services_config.configure() mail_service = ExternalServices.mail_service user_data = ExternalServices.user_data_provider +Tray = ExternalServices.Tray DEFAULT_MAIL_SENDER = config.get("DEFAULT_MAIL_SENDER") @@ -81,22 +82,19 @@ def run_main_window(): def run_system_tray(): - tray = sg.SystemTray( - menu=["", ["Open", "Exit"]], - filename=file_utils.get_absolute_path("rat.ico"), - ) - - while True: - menu_item = tray.read(0) - - if menu_item == "Exit": - break - elif menu_item in [sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED, "Open"]: - tray.hide() - run_main_window() - tray.un_hide() - - tray.close() + def close_tray(tray: Tray): + tray.close() + + def open_window(tray: Tray): + tray.set_visible(False) + run_main_window() + tray.set_visible(True) + + tray = Tray(file_utils.get_absolute_path("rat.ico"), ["Open", "Exit"]) + tray.attach_listener("Exit", close_tray) + tray.attach_listener("Open", open_window) + tray.attach_listener(Tray.DOUBLE_CLICK_EVENT, open_window) + tray.run() def exit_application(signum, frame): From 7ec5f29d069cf440ccaeac614aeb6a452f2e8812 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Tue, 3 Dec 2024 21:56:51 -0500 Subject: [PATCH 12/13] add default keys in case missing --- external_services/mail.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/external_services/mail.py b/external_services/mail.py index 2445a9d..658d2f0 100644 --- a/external_services/mail.py +++ b/external_services/mail.py @@ -1,8 +1,8 @@ import config from mail.mailjet import MailJetService -MAILJET_API_KEY = config.get("MAILJET_API_KEY") -MAILJET_API_SECRET = config.get("MAILJET_API_SECRET") +MAILJET_API_KEY = config.get("MAILJET_API_KEY") or "" +MAILJET_API_SECRET = config.get("MAILJET_API_SECRET") or "" mail_service = MailJetService( api_key=MAILJET_API_KEY, From 1925372251589452e0109bbb101476cb2ca33039 Mon Sep 17 00:00:00 2001 From: Agustin Nieto Date: Tue, 3 Dec 2024 22:55:29 -0500 Subject: [PATCH 13/13] Update button names --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 9cf533f..9f7012b 100644 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ def run_main_window(): key="-SUBSCRIBER_EMAIL-", ), ], - [sg.Button("Save"), sg.Button("Close")], + [sg.Button("Save"), sg.Button("Hide")], ] window = sg.Window( @@ -75,7 +75,7 @@ def run_main_window(): if event == "Save": user_data.set_user_data("name", values["-NAME-"]) user_data.set_user_data("subscriber_email", values["-SUBSCRIBER_EMAIL-"]) - elif event in [sg.WINDOW_CLOSED, "Close"]: + elif event in [sg.WINDOW_CLOSED, "Hide"]: break window.close()