mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2026-01-22 02:47:39 +01:00
Compare commits
3 Commits
async-http
...
0d4fd8852d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d4fd8852d | ||
|
|
7719764604 | ||
|
|
b0741929a3 |
@@ -49,17 +49,17 @@ def create_details_page(app, software, backswitch_function):
|
|||||||
back_button.pack(anchor="nw", side="left")
|
back_button.pack(anchor="nw", side="left")
|
||||||
|
|
||||||
# progress bar #
|
# progress bar #
|
||||||
progress_bar = software.progress_bar_wrapper.new(navbar)
|
#progress_bar = software.progress_bar_wrapper.new(navbar)
|
||||||
progress_bar.pack(anchor="nw", side="left", padx=20, pady=5)
|
#progress_bar.pack(anchor="nw", side="left", padx=20, pady=5)
|
||||||
|
|
||||||
# progress bar text #
|
# progress bar text #
|
||||||
progress_text = software.progress_bar_wrapper.new_text(navbar)
|
#progress_text = software.progress_bar_wrapper.new_text(navbar)
|
||||||
progress_text.pack(anchor="nw", side="left", padx=20, pady=5)
|
#progress_text.pack(anchor="nw", side="left", padx=20, pady=5)
|
||||||
|
|
||||||
elements.append(navbar)
|
elements.append(navbar)
|
||||||
elements.append(back_button)
|
elements.append(back_button)
|
||||||
elements.append(progress_bar)
|
#elements.append(progress_bar)
|
||||||
elements.append(progress_text)
|
#elements.append(progress_text)
|
||||||
|
|
||||||
# thumbnail image #
|
# thumbnail image #
|
||||||
thumbnail_image = customtkinter.CTkButton(app, text="", image=img, width=500, height=700,
|
thumbnail_image = customtkinter.CTkButton(app, text="", image=img, width=500, height=700,
|
||||||
@@ -132,7 +132,7 @@ def create_details_page(app, software, backswitch_function):
|
|||||||
remove_text = "Remove (not implemented)" # FIXME: change text once implemented
|
remove_text = "Remove (not implemented)" # FIXME: change text once implemented
|
||||||
|
|
||||||
install_button = customtkinter.CTkButton(button_frame, text=install_text,
|
install_button = customtkinter.CTkButton(button_frame, text=install_text,
|
||||||
command=lambda: software.install())
|
command=lambda: software.install_async())
|
||||||
|
|
||||||
# add remove button #
|
# add remove button #
|
||||||
remove_button = customtkinter.CTkButton(button_frame, text=remove_text,
|
remove_button = customtkinter.CTkButton(button_frame, text=remove_text,
|
||||||
|
|||||||
@@ -138,15 +138,13 @@ class HTTP(DataBackend):
|
|||||||
# the content is needed for the UI now and not cached, it's needs to be downloaded synchroniously #
|
# the content is needed for the UI now and not cached, it's needs to be downloaded synchroniously #
|
||||||
# as there cannot be a meaningful UI-draw without it. #
|
# as there cannot be a meaningful UI-draw without it. #
|
||||||
r = requests.get(self._get_url(), params={ "path" : path, "as_string": True })
|
r = requests.get(self._get_url(), params={ "path" : path, "as_string": True })
|
||||||
print("Request Content:", r.text)
|
|
||||||
# cache the download imediatelly #
|
# cache the download imediatelly #
|
||||||
with open(local_file, encoding="utf-8", mode="w") as f:
|
with open(local_file, encoding="utf-8", mode="w") as f:
|
||||||
f.write( r.text)
|
f.write(r.text)
|
||||||
|
|
||||||
# return the content #
|
|
||||||
print("Content for", fullpath, ":", r.text)
|
|
||||||
|
|
||||||
if return_content:
|
if return_content:
|
||||||
|
print("Content for", fullpath, ":", r.text)
|
||||||
return r.text
|
return r.text
|
||||||
else:
|
else:
|
||||||
return local_file
|
return local_file
|
||||||
|
|||||||
91
infowidget.py
Normal file
91
infowidget.py
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
# in the background queue write filename in sqlite db
|
||||||
|
# get filename for sqlitedb
|
||||||
|
# get the size with info=1 from server
|
||||||
|
# only display for size>10M
|
||||||
|
# make a list of pregressbars
|
||||||
|
|
||||||
|
# start background thread with main list and main widget
|
||||||
|
# update list and widget
|
||||||
|
|
||||||
|
# update list and widget
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import ttk
|
||||||
|
import threading
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
import string
|
||||||
|
|
||||||
|
class ProgressBarApp:
|
||||||
|
def __init__(self, root):
|
||||||
|
self.root = root
|
||||||
|
self.root.title("Dynamic Progress Bars")
|
||||||
|
|
||||||
|
self.delete_all_button = tk.Button(root, text="Delete All Finished", command=self.delete_all_finished, state=tk.DISABLED)
|
||||||
|
self.delete_all_button.pack(pady=5)
|
||||||
|
|
||||||
|
self.frame = tk.Frame(root)
|
||||||
|
self.frame.pack(pady=10)
|
||||||
|
|
||||||
|
self.progress_bars = [] # Store tuples of (progressbar, frame, duration, delete_button)
|
||||||
|
|
||||||
|
self.running = True
|
||||||
|
threading.Thread(target=self.add_progress_bars, daemon=True).start()
|
||||||
|
|
||||||
|
def add_progress_bars(self):
|
||||||
|
while self.running:
|
||||||
|
time.sleep(3) # Wait before adding a new progress bar
|
||||||
|
|
||||||
|
frame = tk.Frame(self.frame)
|
||||||
|
frame.pack(fill=tk.X, pady=2)
|
||||||
|
|
||||||
|
progress = ttk.Progressbar(frame, length=200, mode='determinate')
|
||||||
|
progress.pack(side=tk.LEFT, padx=5)
|
||||||
|
|
||||||
|
delete_button = tk.Button(frame, text="Delete", command=lambda f=frame: self.delete_progress(f), state=tk.DISABLED)
|
||||||
|
delete_button.pack(side=tk.LEFT, padx=5)
|
||||||
|
|
||||||
|
random_letter = random.choice(string.ascii_uppercase)
|
||||||
|
label = tk.Label(frame, text=random_letter)
|
||||||
|
label.pack(side=tk.LEFT, padx=5)
|
||||||
|
|
||||||
|
duration = random.randint(1, 10) # Random fill time
|
||||||
|
threading.Thread(target=self.fill_progress, args=(progress, duration, frame, delete_button), daemon=True).start()
|
||||||
|
|
||||||
|
def fill_progress(self, progress, duration, frame, delete_button):
|
||||||
|
for i in range(101): # Fill progress bar over 'duration' seconds
|
||||||
|
time.sleep(duration / 100)
|
||||||
|
if not progress.winfo_exists(): # Check if progress bar still exists
|
||||||
|
return
|
||||||
|
self.root.after(0, progress.config, {"value": i})
|
||||||
|
|
||||||
|
self.root.after(0, delete_button.config, {"state": tk.NORMAL})
|
||||||
|
|
||||||
|
self.progress_bars.append((progress, frame, duration, delete_button))
|
||||||
|
self.update_delete_all_button()
|
||||||
|
|
||||||
|
def delete_progress(self, frame):
|
||||||
|
frame.destroy()
|
||||||
|
self.progress_bars = [(p, f, d, b) for p, f, d, b in self.progress_bars if f != frame]
|
||||||
|
self.update_delete_all_button()
|
||||||
|
|
||||||
|
def delete_all_finished(self):
|
||||||
|
for _, frame, _, _ in self.progress_bars:
|
||||||
|
frame.destroy()
|
||||||
|
self.progress_bars.clear()
|
||||||
|
self.update_delete_all_button()
|
||||||
|
|
||||||
|
def update_delete_all_button(self):
|
||||||
|
if self.progress_bars:
|
||||||
|
self.delete_all_button.config(state=tk.NORMAL)
|
||||||
|
else:
|
||||||
|
self.delete_all_button.config(state=tk.DISABLED)
|
||||||
|
|
||||||
|
def on_close(self):
|
||||||
|
self.running = False
|
||||||
|
self.root.destroy()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
root = tk.Tk()
|
||||||
|
app = ProgressBarApp(root)
|
||||||
|
root.protocol("WM_DELETE_WINDOW", app.on_close)
|
||||||
|
root.mainloop()
|
||||||
@@ -17,7 +17,7 @@ def unpack_software(software_cache_path, target_path):
|
|||||||
'''Unpack a downloaded software to the target location'''
|
'''Unpack a downloaded software to the target location'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def install_registry_file(registry_file, game_path=None):
|
def install_registry_file(registry_file):
|
||||||
'''Install a given registy file'''
|
'''Install a given registy file'''
|
||||||
|
|
||||||
# test path:
|
# test path:
|
||||||
@@ -27,13 +27,6 @@ def install_registry_file(registry_file, game_path=None):
|
|||||||
p = subprocess.Popen(["wine64", "start", "regedit", registry_file],
|
p = subprocess.Popen(["wine64", "start", "regedit", registry_file],
|
||||||
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
print("Running regedit for wine..")
|
print("Running regedit for wine..")
|
||||||
else:
|
|
||||||
# windows sucky sucky #
|
|
||||||
if not os.path.isabs(registry_file):
|
|
||||||
registry_file = os.path.join(os.getcwd(), registry_file)
|
|
||||||
|
|
||||||
p = subprocess.Popen(["python", "regedit.py", registry_file],
|
|
||||||
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
|
||||||
|
|
||||||
print(p.communicate())
|
print(p.communicate())
|
||||||
|
|
||||||
@@ -59,7 +52,7 @@ def run_exe(path, synchronous=False):
|
|||||||
paths = path
|
paths = path
|
||||||
|
|
||||||
# sanity check path is list #
|
# sanity check path is list #
|
||||||
if not type(path) == list:
|
if not type(paths) == list:
|
||||||
raise AssertionError("ERROR: run_exe could not build a list of paths")
|
raise AssertionError("ERROR: run_exe could not build a list of paths")
|
||||||
|
|
||||||
if os.name != "nt":
|
if os.name != "nt":
|
||||||
@@ -85,7 +78,10 @@ def run_exe(path, synchronous=False):
|
|||||||
p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File",
|
p = subprocess.Popen(["powershell", "-ExecutionPolicy", "Bypass", "-File",
|
||||||
"windows_run_as_admin.ps1", json.dumps(paths)],
|
"windows_run_as_admin.ps1", json.dumps(paths)],
|
||||||
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
|
try:
|
||||||
print(p.communicate())
|
print(p.communicate())
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
print("WARNING: cannot show you ERROR from exe because output contained illegal characters. This maybe because your refused the admin prompt.")
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|||||||
14
regedit.py
14
regedit.py
@@ -1,14 +0,0 @@
|
|||||||
from pyuac.main_decorator import main_requires_admin
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
@main_requires_admin(return_output=True)
|
|
||||||
def main(registry_file):
|
|
||||||
p = subprocess.Popen(["regedit", registry_file],
|
|
||||||
subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
|
||||||
stdout, stderr = p.communicate()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
registry_file = sys.argv[-1]
|
|
||||||
rv = main(registry_file)
|
|
||||||
print(rv)
|
|
||||||
41
software.py
41
software.py
@@ -8,6 +8,9 @@ import pathlib
|
|||||||
import tqdm
|
import tqdm
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import jinja_helper
|
import jinja_helper
|
||||||
|
import threading
|
||||||
|
import sys
|
||||||
|
import tkinter
|
||||||
|
|
||||||
class Software:
|
class Software:
|
||||||
|
|
||||||
@@ -30,10 +33,10 @@ class Software:
|
|||||||
raise e
|
raise e
|
||||||
self.invalid = True
|
self.invalid = True
|
||||||
|
|
||||||
if not progress_bar_wrapper:
|
# if not progress_bar_wrapper:
|
||||||
raise AssertionError()
|
# raise AssertionError()
|
||||||
|
|
||||||
self.progress_bar_wrapper = progress_bar_wrapper
|
# self.progress_bar_wrapper = progress_bar_wrapper
|
||||||
|
|
||||||
def _load_from_yaml(self):
|
def _load_from_yaml(self):
|
||||||
|
|
||||||
@@ -90,17 +93,21 @@ class Software:
|
|||||||
try:
|
try:
|
||||||
zip_ref.extract(member, software_path)
|
zip_ref.extract(member, software_path)
|
||||||
count += 1
|
count += 1
|
||||||
self.progress_bar_wrapper.get_pb().set(count/len(total_count))
|
#self.progress_bar_wrapper.get_pb().set(count/len(total_count))
|
||||||
self.progress_bar_wrapper.get_pb().update_idletasks()
|
#self.progress_bar_wrapper.get_pb().update_idletasks()
|
||||||
self.progress_bar_wrapper.set_text(
|
#self.progress_bar_wrapper.set_text(
|
||||||
text="Extracting: {:.2f}%".format(count/len(total_count)*100))
|
# text="Extracting: {:.2f}%".format(count/len(total_count)*100))
|
||||||
except zipfile.error as e:
|
except zipfile.error as e:
|
||||||
pass # TODO ???
|
pass # TODO ???
|
||||||
#zip_ref.extractall(software_path)
|
#zip_ref.extractall(software_path)
|
||||||
|
|
||||||
self.progress_bar_wrapper.set_text(text="Loading..")
|
#self.progress_bar_wrapper.set_text(text="Loading..")
|
||||||
self.progress_bar_wrapper.update()
|
#self.progress_bar_wrapper.update()
|
||||||
|
|
||||||
|
def install_async(self):
|
||||||
|
|
||||||
|
thread = threading.Thread(target=self.install)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
'''Install this software from the backend'''
|
'''Install this software from the backend'''
|
||||||
@@ -115,8 +122,8 @@ class Software:
|
|||||||
webbrowser.open(self.link_only)
|
webbrowser.open(self.link_only)
|
||||||
return
|
return
|
||||||
|
|
||||||
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:
|
||||||
@@ -124,7 +131,7 @@ class Software:
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
print("No main_dir:", path)
|
print("No main_dir:", path)
|
||||||
raise AssertionError("No main_dir for this software")
|
raise AssertionError("No main_dir for this software")
|
||||||
local_file = self.backend.get(remote_file, self.cache_dir)
|
local_file = self.backend.get(remote_file, self.cache_dir, wait=True)
|
||||||
|
|
||||||
# execute or unpack #
|
# execute or unpack #
|
||||||
if local_file.endswith(".exe"):
|
if local_file.endswith(".exe"):
|
||||||
@@ -143,8 +150,10 @@ class Software:
|
|||||||
print("Install dir Registry:", target_install_dir)
|
print("Install dir Registry:", target_install_dir)
|
||||||
path = jinja_helper.render_path(path, target_install_dir, self.directory)
|
path = jinja_helper.render_path(path, target_install_dir, self.directory)
|
||||||
|
|
||||||
|
if sys.platform == "win32":
|
||||||
admin_run_list.append(path)
|
admin_run_list.append(path)
|
||||||
# localaction.install_registry_file(path)
|
else:
|
||||||
|
localaction.install_registry_file(path)
|
||||||
|
|
||||||
# install dependencies #
|
# install dependencies #
|
||||||
if self.dependencies:
|
if self.dependencies:
|
||||||
@@ -179,11 +188,13 @@ class Software:
|
|||||||
os.makedirs(dest_dir, exist_ok=True)
|
os.makedirs(dest_dir, exist_ok=True)
|
||||||
shutil.copy(tmp, dest_dir)
|
shutil.copy(tmp, dest_dir)
|
||||||
|
|
||||||
self.progress_bar_wrapper.set_text(text="")
|
#self.progress_bar_wrapper.set_text(text="")
|
||||||
|
try:
|
||||||
if self.run_button:
|
if self.run_button:
|
||||||
self.run_button.configure(state=tkinter.NORMAL)
|
self.run_button.configure(state=tkinter.NORMAL)
|
||||||
self.run_button.configure(fg_color="green")
|
self.run_button.configure(fg_color="green")
|
||||||
|
except tkinter.TclError:
|
||||||
|
print("INFO: No longer in installation view - no button to update")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
'''Run the configured exe for this software'''
|
'''Run the configured exe for this software'''
|
||||||
|
|||||||
Reference in New Issue
Block a user