diff --git a/dialogs.py b/dialogs.py index a1fb098..539d243 100644 --- a/dialogs.py +++ b/dialogs.py @@ -5,11 +5,11 @@ class Messagebox(Toplevel): - def __init__(self, parent, title, details, icon, *, buttons) -> bool: + def __init__(self, parent, title, details, icon, *, buttons) -> None: super().__init__() self.withdraw() - self.result = None + self.result: bool | None = None self.big_frame = Frame(self) self.big_frame.pack(fill="both", expand=True) @@ -79,8 +79,8 @@ def __init__(self, parent, title, details, icon, *, buttons) -> bool: text=button_value[0], width=18, command=partial(self.on_button, button_value[1]), - style=self.style, - state=self.state, + style=self.style, # type: ignore + state=self.state, # type: ignore ) if self.default: self.button.bind("", self.button["command"]) diff --git a/main.py b/main.py index 5da9b9a..f01b5a1 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,9 @@ if not data_dir.exists(): # Create the directory if it doesn't exist data_dir.mkdir(parents=True) - data_file.touch("dark\nmetric") + data_file.touch() + with open(data_file, "r+") as file: + file.write("dark\nmetric") # Ensure file exists and contains the correct data if data_file.exists(): @@ -112,7 +114,7 @@ def __init__(self): self.iconphoto(False, logo_img) except TclError: try: - self.iconphoto("./assets/icon.ico") + self.iconphoto("./assets/icon.ico") # type: ignore except TclError: pass @@ -297,6 +299,11 @@ def owm_search(self, _: Event | None = None) -> None: self.reset_app() return + # Removing redundancy + def failed_weather_request() -> None: + self.cityname.configure(text="City: Not Found") + self.reset_app() + # Check if city exists try: observation = mgr.weather_at_place(city) @@ -306,8 +313,12 @@ def owm_search(self, _: Event | None = None) -> None: or TimeoutError or InvalidSSLCertificateError ): - self.cityname.configure(text="City: Not Found") - self.reset_app() + failed_weather_request() + return + + # Check that observation is not None + if observation is None: + failed_weather_request() return # Get weather data