Skip to content

Commit fa473ba

Browse files
committed
handlers and settings bugs
1 parent 0a2b764 commit fa473ba

File tree

2 files changed

+15
-216
lines changed

2 files changed

+15
-216
lines changed

core/database_handler.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,25 @@ def check_for_updates(app_version: str, urls: tuple[str], handlers: Any, warn_if
107107
body = data['body']
108108

109109
except StatusCodeNot200:
110-
return handlers[0](31, f"The Status Code of URL...\n\n{urls[0]}\n\n...is not 200, meaning DoomMapGuesser is unable to access the latest release.")
110+
return handlers[0](36, f"The Status Code of URL...\n\n{urls[0]}\n\n...is not 200, meaning DoomMapGuesser is unable to access the latest release.")
111111

112112
except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError):
113-
return handlers[0](24, "Unable to connect via HTTP. This might be caused by a bad Internet connection.")
113+
return handlers[0](33, "Unable to connect via HTTP. This might be caused by a bad Internet connection.")
114114

115115
except (TimeoutError, requests.exceptions.Timeout):
116-
return handlers[0](21, f"The URL...\n\n({urls[0]})\n\n...took too long to respond to the GET request.")
116+
return handlers[0](34, f"The URL...\n\n({urls[0]})\n\n...took too long to respond to the GET request.")
117117

118118
except (requests.exceptions.InvalidURL, requests.exceptions.InvalidSchema, requests.exceptions.MissingSchema):
119-
return handlers[0](27, f"The URL...\n\n({urls[0]})\n\n...is invalid.")
119+
return handlers[0](35, f"The URL...\n\n({urls[0]})\n\n...is invalid.")
120+
121+
except UnicodeError as e:
122+
return handlers[0](39, f"Failed to translate the website's data to valid Unicode.\n{e}")
123+
124+
except json.JSONDecodeError as e:
125+
return handlers[0](38, f"Failed to decode JSON data from release stored at:\n\n{urls[0]}\n\nAre you sure this URL points to a JSON/raw JSON object?\n{e}")
120126

121127
except Exception as e:
122-
return handlers[0](28, f"Unknown error when trying to obtain the data on the latest release.\nError Details:\n{e}")
128+
return handlers[0](37, f"Unknown error when trying to obtain the data on the latest release.\nError Details:\n{e}")
123129

124130
if app_version != latest:
125131
handlers[2]('info', 'DoomMapGuesser - Update Available', f"A new update for DoomMapGuesser is available!\n\nWhat's new in DoomMapGuesser {latest}?\n{body}", [

core/settings.py

Lines changed: 4 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -10,221 +10,14 @@
1010

1111
# pylint: disable=W0718
1212

13-
class __CloseDialogError(Exception): ...
13+
1414

1515

1616
REGULAR_KEYS: tuple[str] = ("theme", "databases", "imageRatio", "imageWidth", "widthIsHeight", "checkUpdates", "excludeRule", "zoomBoost", "smallFonts")
1717

1818

1919
class StrictModeError(Exception): ... # [<] teachers be like :| (this was such a stupid comment, gawdamn)
20-
21-
22-
class __SettingsObjectCopy:
23-
def __init__(self, master: Any) -> None:
24-
"""
25-
# __SettingsObjectCopy
26-
27-
Serves as a copy of SettingsObject that doesn't allow for as much features.
28-
29-
:param master: SettingsObject class
30-
"""
31-
32-
self._SETTINGS: dict[str, int | bool | str | float | list[list[str, str, str]] | None] = master._SETTINGS
33-
self.error_handler = master.error_handler
34-
self._MASTER = master
35-
36-
def load(self) -> None:
37-
""""""
38-
39-
self._MASTER.load()
40-
41-
self._SETTINGS = self._MASTER._SETTINGS.copy()
42-
43-
def save_settings(self, **kw) -> None:
44-
"""
45-
## save_settings
46-
Automatically save the settings using the default inner settings of the class.
47-
48-
:param indent: how many spaces as indentation *(int, defaults to 4)*
49-
"""
50-
51-
self._MASTER._SETTINGS = self._SETTINGS
52-
self._MASTER.save_settings(**kw)
53-
del self
54-
55-
@property
56-
def databases(self) -> list[list[str, str, str]]:
57-
return self._SETTINGS['databases']
58-
59-
@databases.setter
60-
def databases(self, value: list[list[str, str, str]]):
61-
value.pop(0)
62-
self._SETTINGS['databases'] = value
63-
64-
@databases.deleter
65-
def databases(self):
66-
self._SETTINGS['databases'].clear()
67-
68-
@property
69-
def theme(self) -> str:
70-
match self._SETTINGS['theme']:
71-
case 1:
72-
return "light"
73-
74-
case 2:
75-
return "dark"
76-
77-
case _:
78-
return "auto"
79-
80-
@theme.setter
81-
def theme(self, value: str | int):
82-
if isinstance(value, int):
83-
self._SETTINGS['theme'] = value
84-
return
85-
86-
match value:
87-
case 'light':
88-
value = 1
89-
90-
case 'dark':
91-
value = 2
92-
93-
case _:
94-
value = 0
95-
96-
self._SETTINGS['theme'] = value
97-
98-
@property
99-
def image_ratio(self) -> bool:
100-
return self._SETTINGS['imageRatio']
101-
102-
@image_ratio.setter
103-
def image_ratio(self, value: str):
104-
match value:
105-
case '16:9' | '1:1':
106-
print('Good image ratio.')
107-
108-
case _:
109-
value = 'detect'
110-
111-
self._SETTINGS['imageRatio'] = value
112-
113-
@property
114-
def image_width(self) -> int:
115-
return self._SETTINGS['imageWidth']
116-
117-
@image_width.setter
118-
def image_width(self, value: int):
119-
self._SETTINGS['imageWidth'] = value
120-
121-
@property
122-
def use_width_as_height(self) -> bool:
123-
return self._SETTINGS['widthIsHeight']
124-
125-
@use_width_as_height.setter
126-
def use_width_as_height(self, value: bool):
127-
self._SETTINGS['widthIsHeight'] = value
128-
129-
@property
130-
def zoom_boost(self) -> float:
131-
return self._SETTINGS['zoomBoost']
132-
133-
@zoom_boost.setter
134-
def zoom_boost(self, value: float):
135-
self._SETTINGS['zoomBoost'] = value
136-
137-
@property
138-
def check_for_updates_on_startup(self) -> bool:
139-
return self._SETTINGS['checkUpdates']
140-
141-
@check_for_updates_on_startup.setter
142-
def check_for_updates_on_startup(self, value: bool):
143-
self._SETTINGS['checkUpdates'] = value
144-
145-
'''
146-
@property
147-
def autoupdate(self) -> bool:
148-
"""
149-
# Levels of Auto Updating
150-
151-
**Key name:** `autoUpdateLevel`
152-
153-
0. **Always ask** (Default)
154-
1. **Always update**
155-
2. **Update if the latest is a major**
156-
3. **Never update**
157-
158-
Auto Updating only works if **Check for Updates on Startup** (key name is `checkUpdates`) is enabled (set to `True`).
159-
160-
Both Auto Updates and Check for Updates require a stable Internet connection.
161-
"""
162-
163-
return self._SETTINGS['autoUpdateLevel']
164-
165-
@autoupdate.setter
166-
def autoupdate(self, value: bool):
167-
if value < 0 or value > 3:
168-
value = 0 # [i] set to default
169-
170-
self._SETTINGS['autoUpdateLevel'] = value
171-
'''
172-
173-
@property
174-
def small_fonts(self) -> bool:
175-
return self._SETTINGS['smallFonts']
176-
177-
@small_fonts.setter
178-
def small_fonts(self, value: bool):
179-
"""
180-
# small_fonts
181-
182-
**Key name:** `smallFonts`
183-
184-
0. **Disabled**, which allows for the best UI experience
185-
1. **Enabled**, which allows for DoomMapGuesser to be played in smaller monitors
186-
"""
187-
188-
self._SETTINGS['smallFonts'] = value
189-
190-
@property
191-
def exclude_rule_for_e3m1_e3m9(self, **kw) -> str | None:
192-
"""
193-
# exclude_rule_for_e3m1_e3m9
194-
195-
Whether to use **Hell Keep** or **Warrens** or both, even!
196-
197-
:param obj: the object to save - if not specified, will save itself
198-
:param object: same as above but this one does not take priority
199-
200-
Returns:
201-
str: either 'warrens', 'hellkeep' or 'both' depending on what the user chose *(None if set to show none)*
202-
"""
203-
204-
__obj = kw.get('obj', None)
205-
206-
if __obj is None:
207-
__obj = kw.get('object', None)
208-
209-
a: str | None = self._SETTINGS['excludeRule']
210-
211-
if a not in ('warrens', 'hell_keep', 'both'):
212-
self._SETTINGS['excludeRule'] = None
213-
214-
if __obj is None:
215-
self.save_settings()
216-
217-
else:
218-
self.dump_settings(__obj)
219-
220-
return self._SETTINGS['excludeRule']
221-
222-
@exclude_rule_for_e3m1_e3m9.setter
223-
def exclude_rule_for_e3m1_e3m9(self, value: str | None):
224-
if value not in ('warrens', 'hell_keep', 'both'):
225-
value = None
226-
227-
self._SETTINGS['excludeRule'] = value
20+
class __CloseDialogError(Exception): ...
22821

22922

23023
class SettingsObject:
@@ -311,7 +104,7 @@ def image_ratio(self) -> bool:
311104
@image_ratio.setter
312105
def image_ratio(self, value: str):
313106
match value:
314-
case '16:9' | '1:1':
107+
case '16:9' | '1:1' | '16:9 (Landscape)' | '1:1 (Square)':
315108
print('Good image ratio.')
316109

317110
case _:
@@ -593,7 +386,7 @@ def image_ratio(self) -> bool:
593386
@image_ratio.setter
594387
def image_ratio(self, value: str):
595388
match value:
596-
case '16:9' | '1:1':
389+
case '16:9' | '1:1' | '16:9 (Landscape)' | '1:1 (Square)':
597390
print('Good image ratio.')
598391

599392
case _:

0 commit comments

Comments
 (0)