mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
Report Engine Download Status in UI (#64)
* Report downloads in status bar * Update engine_browser.py UI with any active downloads
This commit is contained in:
@@ -4,6 +4,7 @@ import subprocess
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from PyQt6.QtCore import QTimer
|
||||
from PyQt6.QtWidgets import (
|
||||
QMainWindow, QWidget, QVBoxLayout, QPushButton, QTableWidget, QTableWidgetItem, QHBoxLayout, QAbstractItemView,
|
||||
QHeaderView, QProgressBar, QLabel, QMessageBox
|
||||
@@ -28,6 +29,7 @@ class EngineBrowserWindow(QMainWindow):
|
||||
self.setGeometry(100, 100, 500, 300)
|
||||
self.engine_data = []
|
||||
self.initUI()
|
||||
self.init_timer()
|
||||
|
||||
def initUI(self):
|
||||
# Central widget
|
||||
@@ -82,6 +84,12 @@ class EngineBrowserWindow(QMainWindow):
|
||||
|
||||
self.update_download_status()
|
||||
|
||||
def init_timer(self):
|
||||
# Set up the timer
|
||||
self.timer = QTimer(self)
|
||||
self.timer.timeout.connect(self.update_download_status)
|
||||
self.timer.start(1000)
|
||||
|
||||
def update_table(self):
|
||||
|
||||
def update_table_worker():
|
||||
@@ -124,9 +132,15 @@ class EngineBrowserWindow(QMainWindow):
|
||||
hide_progress = not bool(running_tasks)
|
||||
self.progress_bar.setHidden(hide_progress)
|
||||
self.progress_label.setHidden(hide_progress)
|
||||
|
||||
# todo: update progress bar with status
|
||||
self.progress_label.setText(f"Downloading {len(running_tasks)} engines")
|
||||
# Update the status labels
|
||||
if len(EngineManager.download_tasks) == 0:
|
||||
new_status = ""
|
||||
elif len(EngineManager.download_tasks) == 1:
|
||||
task = EngineManager.download_tasks[0]
|
||||
new_status = f"Downloading {task.engine.capitalize()} {task.version}..."
|
||||
else:
|
||||
new_status = f"Downloading {len(EngineManager.download_tasks)} engines..."
|
||||
self.progress_label.setText(new_status)
|
||||
|
||||
def launch_button_click(self):
|
||||
engine_info = self.engine_data[self.table_widget.currentRow()]
|
||||
|
||||
@@ -9,6 +9,7 @@ from PyQt6.QtGui import QPixmap
|
||||
from PyQt6.QtWidgets import QStatusBar, QLabel
|
||||
|
||||
from src.api.server_proxy import RenderServerProxy
|
||||
from src.engines.engine_manager import EngineManager
|
||||
from src.utilities.misc_helper import resources_dir
|
||||
|
||||
|
||||
@@ -28,17 +29,23 @@ class StatusBar(QStatusBar):
|
||||
proxy = RenderServerProxy(socket.gethostname())
|
||||
proxy.start_background_update()
|
||||
image_names = {'Ready': 'GreenCircle.png', 'Offline': "RedSquare.png"}
|
||||
last_update = None
|
||||
|
||||
# Check for status change every 1s on background thread
|
||||
while True:
|
||||
new_status = proxy.status()
|
||||
if new_status is not last_update:
|
||||
new_image_name = image_names.get(new_status, 'Synchronize.png')
|
||||
image_path = os.path.join(resources_dir(), 'icons', new_image_name)
|
||||
self.label.setPixmap((QPixmap(image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio)))
|
||||
self.messageLabel.setText(new_status)
|
||||
last_update = new_status
|
||||
new_image_name = image_names.get(new_status, 'Synchronize.png')
|
||||
image_path = os.path.join(resources_dir(), 'icons', new_image_name)
|
||||
self.label.setPixmap((QPixmap(image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio)))
|
||||
|
||||
# add download status
|
||||
if EngineManager.download_tasks:
|
||||
if len(EngineManager.download_tasks) == 1:
|
||||
task = EngineManager.download_tasks[0]
|
||||
new_status = f"{new_status} | Downloading {task.engine.capitalize()} {task.version}..."
|
||||
else:
|
||||
new_status = f"{new_status} | Downloading {len(EngineManager.download_tasks)} engines"
|
||||
|
||||
self.messageLabel.setText(new_status)
|
||||
time.sleep(1)
|
||||
|
||||
background_thread = threading.Thread(target=background_update,)
|
||||
|
||||
Reference in New Issue
Block a user