Skip to content

Commit 4c51dda

Browse files
committed
TESTING NEXT DAY AND THEN IT'S ON LESGOOO
1 parent 19c25b8 commit 4c51dda

File tree

5 files changed

+544
-171
lines changed

5 files changed

+544
-171
lines changed

core/database_handler.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any
33
import requests
44
from PIL import Image
5+
import simple_webbrowser
56
import io
67

78
# pylint: disable=W0718
@@ -13,7 +14,7 @@ class StatusCodeNot200(Exception): ...
1314

1415
def __get_online_database(url: str, handler: Any) -> dict | int:
1516
try:
16-
response = requests.get(url=url, allow_redirects=False, timeout=1)
17+
response = requests.get(url=url, allow_redirects=False, timeout=1.5)
1718

1819
if response.status_code != 200:
1920
raise StatusCodeNot200(f"status code is {response.status_code} and not 200")
@@ -59,7 +60,7 @@ def get_image(source: str, handler: Any, **kw):
5960
del _
6061

6162
try:
62-
response = requests.get(url=source, allow_redirects=False, timeout=1.3)
63+
response = requests.get(url=source, allow_redirects=False, timeout=1.7)
6364

6465
if response.status_code != 200:
6566
raise StatusCodeNot200(f"status code is {response.status_code} and not 200")
@@ -92,3 +93,52 @@ def get_image(source: str, handler: Any, **kw):
9293
return handler(28, f"Unknown error when trying to read the chosen image with URL with PIL:\n\n{source}\n\nError Details:\n{e}")
9394

9495
return image
96+
97+
98+
def check_for_updates(app_version: str, urls: tuple[str], handlers: Any, warn_if_match: bool = False) -> int | bool:
99+
try:
100+
response = requests.get(urls[0], allow_redirects=False, timeout=1.2)
101+
102+
if response.status_code != 200:
103+
raise StatusCodeNot200(f"status code is {response.status_code} and not 200")
104+
105+
data = response.json()
106+
latest = data['tag_name']
107+
body = data['body']
108+
109+
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.")
111+
112+
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.")
114+
115+
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.")
117+
118+
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.")
120+
121+
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}")
123+
124+
if app_version != latest:
125+
handlers[2]('info', 'DoomMapGuesser - Update Available', f"A new update for DoomMapGuesser is available!\n\nWhat's new in DoomMapGuesser {latest}?\n{body}", [
126+
{
127+
'text': "Update",
128+
'type': "PRIMARY",
129+
'command': lambda: simple_webbrowser.website(urls[1])
130+
},
131+
{
132+
'text': "Don't Update",
133+
'type': "DEFAULT",
134+
'command': "TYPE_CLOSE"
135+
}
136+
])
137+
138+
return False
139+
140+
if warn_if_match:
141+
handlers[1]('sucess', "DoomMapGuesser is up-to-date", f"Congrats!\nDoomMapGuesser {app_version} is up-to-date!")
142+
return True
143+
144+

core/settings.py

Lines changed: 209 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,213 @@ def exclude_rule_for_e3m1_e3m9(self, value: str | None):
228228

229229

230230
class SettingsObject:
231+
class __SettingsObjectCopy:
232+
def __init__(self, master: Any) -> None:
233+
"""
234+
# __SettingsObjectCopy
235+
236+
Serves as a copy of SettingsObject that doesn't allow for as much features.
237+
238+
:param master: SettingsObject class
239+
"""
240+
241+
self._SETTINGS: dict[str, int | bool | str | float | list[list[str, str, str]] | None] = master._SETTINGS
242+
self.error_handler = master.error_handler
243+
self._MASTER = master
244+
245+
def load(self) -> None:
246+
""""""
247+
248+
self._MASTER.load()
249+
250+
self._SETTINGS = self._MASTER._SETTINGS.copy()
251+
252+
def save_settings(self, **kw) -> None:
253+
"""
254+
## save_settings
255+
Automatically save the settings using the default inner settings of the class.
256+
257+
:param indent: how many spaces as indentation *(int, defaults to 4)*
258+
"""
259+
260+
self._MASTER._SETTINGS = self._SETTINGS
261+
self._MASTER.save_settings(**kw)
262+
del self
263+
264+
@property
265+
def databases(self) -> list[list[str, str, str]]:
266+
return self._SETTINGS['databases']
267+
268+
@databases.setter
269+
def databases(self, value: list[list[str, str, str]]):
270+
value.pop(0)
271+
self._SETTINGS['databases'] = value
272+
273+
@databases.deleter
274+
def databases(self):
275+
self._SETTINGS['databases'].clear()
276+
277+
@property
278+
def theme(self) -> str:
279+
match self._SETTINGS['theme']:
280+
case 1:
281+
return "light"
282+
283+
case 2:
284+
return "dark"
285+
286+
case _:
287+
return "auto"
288+
289+
@theme.setter
290+
def theme(self, value: str | int):
291+
if isinstance(value, int):
292+
self._SETTINGS['theme'] = value
293+
return
294+
295+
match value:
296+
case 'light':
297+
value = 1
298+
299+
case 'dark':
300+
value = 2
301+
302+
case _:
303+
value = 0
304+
305+
self._SETTINGS['theme'] = value
306+
307+
@property
308+
def image_ratio(self) -> bool:
309+
return self._SETTINGS['imageRatio']
310+
311+
@image_ratio.setter
312+
def image_ratio(self, value: str):
313+
match value:
314+
case '16:9' | '1:1':
315+
print('Good image ratio.')
316+
317+
case _:
318+
value = 'detect'
319+
320+
self._SETTINGS['imageRatio'] = value
321+
322+
@property
323+
def image_width(self) -> int:
324+
return self._SETTINGS['imageWidth']
325+
326+
@image_width.setter
327+
def image_width(self, value: int):
328+
self._SETTINGS['imageWidth'] = value
329+
330+
@property
331+
def use_width_as_height(self) -> bool:
332+
return self._SETTINGS['widthIsHeight']
333+
334+
@use_width_as_height.setter
335+
def use_width_as_height(self, value: bool):
336+
self._SETTINGS['widthIsHeight'] = value
337+
338+
@property
339+
def zoom_boost(self) -> float:
340+
return self._SETTINGS['zoomBoost']
341+
342+
@zoom_boost.setter
343+
def zoom_boost(self, value: float):
344+
self._SETTINGS['zoomBoost'] = value
345+
346+
@property
347+
def check_for_updates_on_startup(self) -> bool:
348+
return self._SETTINGS['checkUpdates']
349+
350+
@check_for_updates_on_startup.setter
351+
def check_for_updates_on_startup(self, value: bool):
352+
self._SETTINGS['checkUpdates'] = value
353+
354+
'''
355+
@property
356+
def autoupdate(self) -> bool:
357+
"""
358+
# Levels of Auto Updating
359+
360+
**Key name:** `autoUpdateLevel`
361+
362+
0. **Always ask** (Default)
363+
1. **Always update**
364+
2. **Update if the latest is a major**
365+
3. **Never update**
366+
367+
Auto Updating only works if **Check for Updates on Startup** (key name is `checkUpdates`) is enabled (set to `True`).
368+
369+
Both Auto Updates and Check for Updates require a stable Internet connection.
370+
"""
371+
372+
return self._SETTINGS['autoUpdateLevel']
373+
374+
@autoupdate.setter
375+
def autoupdate(self, value: bool):
376+
if value < 0 or value > 3:
377+
value = 0 # [i] set to default
378+
379+
self._SETTINGS['autoUpdateLevel'] = value
380+
'''
381+
382+
@property
383+
def small_fonts(self) -> bool:
384+
return self._SETTINGS['smallFonts']
385+
386+
@small_fonts.setter
387+
def small_fonts(self, value: bool):
388+
"""
389+
# small_fonts
390+
391+
**Key name:** `smallFonts`
392+
393+
0. **Disabled**, which allows for the best UI experience
394+
1. **Enabled**, which allows for DoomMapGuesser to be played in smaller monitors
395+
"""
396+
397+
self._SETTINGS['smallFonts'] = value
398+
399+
@property
400+
def exclude_rule_for_e3m1_e3m9(self, **kw) -> str | None:
401+
"""
402+
# exclude_rule_for_e3m1_e3m9
403+
404+
Whether to use **Hell Keep** or **Warrens** or both, even!
405+
406+
:param obj: the object to save - if not specified, will save itself
407+
:param object: same as above but this one does not take priority
408+
409+
Returns:
410+
str: either 'warrens', 'hellkeep' or 'both' depending on what the user chose *(None if set to show none)*
411+
"""
412+
413+
__obj = kw.get('obj', None)
414+
415+
if __obj is None:
416+
__obj = kw.get('object', None)
417+
418+
a: str | None = self._SETTINGS['excludeRule']
419+
420+
if a not in ('warrens', 'hell_keep', 'both'):
421+
self._SETTINGS['excludeRule'] = None
422+
423+
if __obj is None:
424+
self.save_settings()
425+
426+
else:
427+
self.dump_settings(__obj)
428+
429+
return self._SETTINGS['excludeRule']
430+
431+
@exclude_rule_for_e3m1_e3m9.setter
432+
def exclude_rule_for_e3m1_e3m9(self, value: str | None):
433+
if value not in ('warrens', 'hell_keep', 'both'):
434+
value = None
435+
436+
self._SETTINGS['excludeRule'] = value
437+
231438
def __init__(self, given_path: str, *_, handler: Any, initial_settings: dict[str, int | bool | str | float | list[list[str, str, str]]] | None = None, **kw) -> None:
232439
"""
233440
# SettingsObject
@@ -482,7 +689,7 @@ def exclude_rule_for_e3m1_e3m9(self, **kw) -> str | None:
482689
:param object: same as above but this one does not take priority
483690
484691
Returns:
485-
str: either 'warrens', 'hellkeep' or 'both' depending on what the user chose *(None if set to show none)*
692+
str: either 'warrens', 'hell_keep' or 'both' depending on what the user chose *(None if set to show none)*
486693
"""
487694

488695
__obj = kw.get('obj', None)
@@ -512,7 +719,7 @@ def exclude_rule_for_e3m1_e3m9(self, value: str | None):
512719

513720
@property
514721
def copy(self):
515-
return __SettingsObjectCopy(self)
722+
return self.__SettingsObjectCopy(self)
516723

517724
def __getitem__(self, key: str) -> int | bool | str | float | list[str] | None:
518725
if self._BE_STRICT:

core/utils_constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33

44
DEFAULT_DB_URL = "https://raw.githubusercontent.com/MF366-Coding/DoomMapGuesser/main/.github/ss_db.json"
5+
REPO_URL = 'https://github.com/MF366-Coding/DoomMapGuesser'
6+
LATEST_URL = 'https://github.com/MF366-Coding/DoomMapGuesser/releases/latest'
7+
LATEST_JSON_URL = "https://api.github.com/repos/MF366-Coding/DoomMapGuesser/releases/latest"
58
VERSION = 'v2.0.0'
69

710
def nullish_operator(value: Any, new_value: Any) -> Any:

0 commit comments

Comments
 (0)