Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Moosems committed May 11, 2024
1 parent 273a606 commit c84e48b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
8 changes: 4 additions & 4 deletions dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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("<Return>", self.button["command"])
Expand Down
19 changes: 15 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit c84e48b

Please sign in to comment.