mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-07 23:41:35 +01:00
feat: only enable run button if installed
This commit is contained in:
@@ -2,7 +2,7 @@ import PIL
|
|||||||
import tkinter
|
import tkinter
|
||||||
import customtkinter
|
import customtkinter
|
||||||
import imagetools
|
import imagetools
|
||||||
|
import os
|
||||||
|
|
||||||
def show_large_picture(app, path):
|
def show_large_picture(app, path):
|
||||||
'''Show a full-window version of the clicked picture'''
|
'''Show a full-window version of the clicked picture'''
|
||||||
@@ -150,9 +150,10 @@ def create_details_page(app, software, backswitch_function):
|
|||||||
run_button = customtkinter.CTkButton(button_frame, text="Run",
|
run_button = customtkinter.CTkButton(button_frame, text="Run",
|
||||||
command=lambda: software.run())
|
command=lambda: software.run())
|
||||||
run_button.pack(padx=10, pady=15, anchor="sw", side="left")
|
run_button.pack(padx=10, pady=15, anchor="sw", side="left")
|
||||||
|
software.run_button = run_button
|
||||||
|
|
||||||
# install button #
|
# install button #
|
||||||
if not software.run_exe:
|
if not software.run_exe or not os.path.isfile(software.run_exe):
|
||||||
run_button.configure(state=tkinter.DISABLED)
|
run_button.configure(state=tkinter.DISABLED)
|
||||||
run_button.configure(fg_color="gray")
|
run_button.configure(fg_color="gray")
|
||||||
|
|
||||||
|
|||||||
20
software.py
20
software.py
@@ -1,4 +1,5 @@
|
|||||||
import yaml
|
import yaml
|
||||||
|
import tkinter
|
||||||
import os
|
import os
|
||||||
import localaction
|
import localaction
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -15,6 +16,7 @@ class Software:
|
|||||||
self.meta_file = meta_file
|
self.meta_file = meta_file
|
||||||
self.directory = os.path.dirname(meta_file)
|
self.directory = os.path.dirname(meta_file)
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
|
self.run_button = None
|
||||||
print("Software Directory:", self.directory)
|
print("Software Directory:", self.directory)
|
||||||
|
|
||||||
self.cache_dir = backend.cache_dir or os.path.join("cache", self.directory.lstrip("/").lstrip("\\"))
|
self.cache_dir = backend.cache_dir or os.path.join("cache", self.directory.lstrip("/").lstrip("\\"))
|
||||||
@@ -48,7 +50,7 @@ class Software:
|
|||||||
|
|
||||||
self.pictures = [ self.backend.get(pp, self.cache_dir, new_connection=True) for pp in
|
self.pictures = [ self.backend.get(pp, self.cache_dir, new_connection=True) for pp in
|
||||||
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True, new_connection=True) ]
|
self.backend.list(os.path.join(self.directory, "pictures"), fullpaths=True, new_connection=True) ]
|
||||||
|
|
||||||
self.reg_files = self.backend.list(os.path.join(self.directory, "registry_files"), fullpaths=True, new_connection=True)
|
self.reg_files = self.backend.list(os.path.join(self.directory, "registry_files"), fullpaths=True, new_connection=True)
|
||||||
|
|
||||||
|
|
||||||
@@ -59,7 +61,7 @@ class Software:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
return self.pictures[0]
|
return self.pictures[0]
|
||||||
|
|
||||||
def _extract_to_target(self, cache_src, target):
|
def _extract_to_target(self, cache_src, target):
|
||||||
'''Extract a cached, downloaded zip to the target location'''
|
'''Extract a cached, downloaded zip to the target location'''
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ class Software:
|
|||||||
os.makedirs(software_path, exist_ok=True)
|
os.makedirs(software_path, exist_ok=True)
|
||||||
|
|
||||||
with zipfile.ZipFile(cache_src, 'r') as zip_ref:
|
with zipfile.ZipFile(cache_src, 'r') as zip_ref:
|
||||||
|
|
||||||
total_count = zip_ref.infolist()
|
total_count = zip_ref.infolist()
|
||||||
count = 0
|
count = 0
|
||||||
for member in tqdm.tqdm(total_count, desc='Extracting '):
|
for member in tqdm.tqdm(total_count, desc='Extracting '):
|
||||||
@@ -101,7 +103,7 @@ class Software:
|
|||||||
self.progress_bar_wrapper.set_text(text="Please wait..")
|
self.progress_bar_wrapper.set_text(text="Please wait..")
|
||||||
self.progress_bar_wrapper.tk_parent.update_idletasks()
|
self.progress_bar_wrapper.tk_parent.update_idletasks()
|
||||||
path = os.path.join(self.directory, "main_dir")
|
path = os.path.join(self.directory, "main_dir")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remote_file = self.backend.list(path, fullpaths=True)[0]
|
remote_file = self.backend.list(path, fullpaths=True)[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -117,7 +119,7 @@ class Software:
|
|||||||
localaction.run_exe(local_file)
|
localaction.run_exe(local_file)
|
||||||
elif local_file.endswith(".zip"):
|
elif local_file.endswith(".zip"):
|
||||||
self._extract_to_target(local_file, self.backend.install_dir)
|
self._extract_to_target(local_file, self.backend.install_dir)
|
||||||
|
|
||||||
# download & install registry files #
|
# download & install registry files #
|
||||||
for rf in self.reg_files:
|
for rf in self.reg_files:
|
||||||
path = self.backend.get(rf, cache_dir=self.cache_dir)
|
path = self.backend.get(rf, cache_dir=self.cache_dir)
|
||||||
@@ -155,7 +157,11 @@ class Software:
|
|||||||
shutil.copy(tmp, dest_dir)
|
shutil.copy(tmp, dest_dir)
|
||||||
|
|
||||||
self.progress_bar_wrapper.set_text(text="")
|
self.progress_bar_wrapper.set_text(text="")
|
||||||
|
if self.run_button:
|
||||||
|
self.run_button.configure(state=tkinter.NORMAL)
|
||||||
|
self.run_button.configure(fg_color="green")
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
'''Run the configured exe for this software'''
|
'''Run the configured exe for this software'''
|
||||||
|
|
||||||
@@ -167,6 +173,6 @@ class Software:
|
|||||||
|
|
||||||
if self.run_exe:
|
if self.run_exe:
|
||||||
if os.name == "nt" or not ".lnk" in self.run_exe:
|
if os.name == "nt" or not ".lnk" in self.run_exe:
|
||||||
localaction.run_exe(os.path.join(self.backend.install_dir, self.title, self.run_exe))
|
localaction.run_exe(os.path.join(self.backend.install_dir, self.title, self.run_exe))
|
||||||
else:
|
else:
|
||||||
localaction.run_exe(self.run_exe)
|
localaction.run_exe(self.run_exe)
|
||||||
|
|||||||
Reference in New Issue
Block a user