Save geometry to win registry
This commit is contained in:
parent
71bf316076
commit
211f319f75
@ -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
|
||||||
|
@ -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"
|
@ -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 *
|
||||||
|
|
||||||
@ -13,11 +12,11 @@ class BOIIIWD(ctk.CTk):
|
|||||||
# 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"{920}x{560}")
|
self.geometry(f"{920}x{560}")
|
||||||
except:
|
except:
|
||||||
@ -195,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)
|
||||||
@ -322,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())
|
||||||
|
Loading…
Reference in New Issue
Block a user