Merge pull request #6 from faroukbmiled/refactored

Bug fixes
This commit is contained in:
Ryuk 2023-09-24 16:43:36 -07:00 committed by GitHub
commit c650a75c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 13 deletions

View File

@ -393,4 +393,25 @@ def check_item_date(down_date, date_updated):
except: except:
return False return False
def get_window_size_from_registry():
try:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, REGISTRY_KEY_PATH, 0, winreg.KEY_READ) as key:
width, _ = winreg.QueryValueEx(key, "WindowWidth")
height, _ = winreg.QueryValueEx(key, "WindowHeight")
x, _ = winreg.QueryValueEx(key, "WindowX")
y, _ = winreg.QueryValueEx(key, "WindowY")
return int(width), int(height), int(x), int(y)
except (FileNotFoundError, OSError, ValueError, FileNotFoundError):
return None, None, None, None
def save_window_size_to_registry(width, height, x, y):
try:
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, REGISTRY_KEY_PATH) as key:
winreg.SetValueEx(key, "WindowWidth", 0, winreg.REG_SZ, str(width))
winreg.SetValueEx(key, "WindowHeight", 0, winreg.REG_SZ, str(height))
winreg.SetValueEx(key, "WindowX", 0, winreg.REG_SZ, str(x))
winreg.SetValueEx(key, "WindowY", 0, winreg.REG_SZ, str(y))
except Exception as e:
print(f"Error saving to registry: {e}")
# End helper functions # End helper functions

View File

@ -18,6 +18,7 @@ from tkinter import END, Event, Menu
import customtkinter as ctk import customtkinter as ctk
import psutil import psutil
import requests import requests
import winreg
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from CTkMessagebox import CTkMessagebox from CTkMessagebox import CTkMessagebox
from PIL import Image from PIL import Image
@ -41,4 +42,5 @@ LATEST_RELEASE_URL = "https://github.com/faroukbmiled/BOIIIWD/releases/latest/do
LIBRARY_FILE = "boiiiwd_library.json" LIBRARY_FILE = "boiiiwd_library.json"
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), '..', 'resources') RESOURCES_DIR = os.path.join(os.path.dirname(__file__), '..', 'resources')
UPDATER_FOLDER = "update" UPDATER_FOLDER = "update"
REGISTRY_KEY_PATH = r"Software\BOIIIWD"
VERSION = "v0.3.1" VERSION = "v0.3.1"

View File

@ -1,4 +1,3 @@
from turtle import title
from src.update_window import check_for_updates_func from src.update_window import check_for_updates_func
from src.helpers import * from src.helpers import *
@ -9,20 +8,21 @@ from src.settings_tab import SettingsTab
class BOIIIWD(ctk.CTk): class BOIIIWD(ctk.CTk):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
# self.app_instance = BOIIIWD()
# configure window # configure window
self.title("BOIII Workshop Downloader - Main") self.title("BOIII Workshop Downloader - Main")
window_info = get_window_size_from_registry()
try: try:
geometry_file = os.path.join(application_path, "boiiiwd_dont_touch.conf") if all(window_info):
if os.path.isfile(geometry_file): width, height, x, y = window_info
with open(geometry_file, "r") as conf: self.geometry(f"{width}x{height}+{x}+{y}")
self.geometry(conf.read())
else: else:
self.geometry(f"{910}x{560}") self.geometry(f"{920}x{560}")
except: except:
self.geometry(f"{910}x{560}") self.geometry(f"{920}x{560}")
self.minsize(920, 560)
if os.path.exists(os.path.join(RESOURCES_DIR, "ryuk.ico")): if os.path.exists(os.path.join(RESOURCES_DIR, "ryuk.ico")):
self.wm_iconbitmap(os.path.join(RESOURCES_DIR, "ryuk.ico")) self.wm_iconbitmap(os.path.join(RESOURCES_DIR, "ryuk.ico"))
@ -194,7 +194,7 @@ class BOIIIWD(ctk.CTk):
self.sidebar_settings_tooltip = CTkToolTip(self.sidebar_settings, message="Settings") self.sidebar_settings_tooltip = CTkToolTip(self.sidebar_settings, message="Settings")
self.sidebar_library_tooltip = CTkToolTip(self.sidebar_library, message="Experimental") self.sidebar_library_tooltip = CTkToolTip(self.sidebar_library, message="Experimental")
self.sidebar_queue_tooltip = CTkToolTip(self.sidebar_queue, message="Experimental") self.sidebar_queue_tooltip = CTkToolTip(self.sidebar_queue, message="Experimental")
self.bind("<Configure>", self.save_window_size) self.bind("<Configure>", lambda e: self.save_window_size_position())
# context_menus # context_menus
self.create_context_menu(self.edit_workshop_id) self.create_context_menu(self.edit_workshop_id)
@ -321,9 +321,14 @@ class BOIIIWD(ctk.CTk):
if library: if library:
self.library_tab.filter_items(self.cevent) self.library_tab.filter_items(self.cevent)
def save_window_size(self, event): def save_window_size_position(self):
with open("boiiiwd_dont_touch.conf", "w") as conf: geometry = self.geometry()
conf.write(self.geometry()) match = re.match(r"(\d+)x(\d+)\+(\d+)\+(\d+)", geometry)
if match:
width, height, x, y = map(int, match.groups())
save_window_size_to_registry(width, height, x, y)
else:
print("Invalid geometry format:", geometry)
def on_closing(self): def on_closing(self):
save_config("DestinationFolder" ,self.edit_destination_folder.get()) save_config("DestinationFolder" ,self.edit_destination_folder.get())
@ -969,7 +974,7 @@ class BOIIIWD(ctk.CTk):
if not self.is_pressed: if not self.is_pressed:
self.after(1, self.label_speed.configure(text=f"Loading...")) self.after(1, self.label_speed.configure(text=f"Loading..."))
self.is_pressed = True self.is_pressed = True
self.library_tab.load_items(self.edit_destination_folder.get()) self.library_tab.load_items(self.edit_destination_folder.get(), dont_add=True)
if self.queue_enabled: if self.queue_enabled:
self.item_skipped = False self.item_skipped = False
start_down_thread = threading.Thread(target=self.queue_download_thread, args=(update,)) start_down_thread = threading.Thread(target=self.queue_download_thread, args=(update,))