diff --git a/client_details.py b/client_details.py index 2775ecc..9ab7c64 100644 --- a/client_details.py +++ b/client_details.py @@ -2,7 +2,7 @@ import PIL import tkinter import customtkinter import imagetools - +import os def show_large_picture(app, path): '''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", command=lambda: software.run()) run_button.pack(padx=10, pady=15, anchor="sw", side="left") + software.run_button = run_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(fg_color="gray") diff --git a/software.py b/software.py index 1e53d69..9705cc9 100644 --- a/software.py +++ b/software.py @@ -1,4 +1,5 @@ import yaml +import tkinter import os import localaction import zipfile @@ -15,6 +16,7 @@ class Software: self.meta_file = meta_file self.directory = os.path.dirname(meta_file) self.backend = backend + self.run_button = None print("Software Directory:", self.directory) 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.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) @@ -59,7 +61,7 @@ class Software: return None return self.pictures[0] - + def _extract_to_target(self, cache_src, target): '''Extract a cached, downloaded zip to the target location''' @@ -69,7 +71,7 @@ class Software: os.makedirs(software_path, exist_ok=True) with zipfile.ZipFile(cache_src, 'r') as zip_ref: - + total_count = zip_ref.infolist() count = 0 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.tk_parent.update_idletasks() path = os.path.join(self.directory, "main_dir") - + try: remote_file = self.backend.list(path, fullpaths=True)[0] except IndexError: @@ -117,7 +119,7 @@ class Software: localaction.run_exe(local_file) elif local_file.endswith(".zip"): self._extract_to_target(local_file, self.backend.install_dir) - + # download & install registry files # for rf in self.reg_files: path = self.backend.get(rf, cache_dir=self.cache_dir) @@ -155,7 +157,11 @@ class Software: shutil.copy(tmp, dest_dir) 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): '''Run the configured exe for this software''' @@ -167,6 +173,6 @@ class Software: if 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: localaction.run_exe(self.run_exe)