mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Serverproxy manager (#61)
* Create serverproxy_manager.py * Replace use of direct RenderServerProxy with ServerProxyManager method
This commit is contained in:
@@ -27,6 +27,7 @@ from .widgets.menubar import MenuBar
|
||||
from .widgets.proportional_image_label import ProportionalImageLabel
|
||||
from .widgets.statusbar import StatusBar
|
||||
from .widgets.toolbar import ToolBar
|
||||
from src.api.serverproxy_manager import ServerProxyManager
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -48,7 +49,6 @@ class MainWindow(QMainWindow):
|
||||
# Load the queue
|
||||
self.engine_browser_window = None
|
||||
self.server_info_group = None
|
||||
self.server_proxies = {}
|
||||
self.current_hostname = None
|
||||
self.subprocess_runner = None
|
||||
|
||||
@@ -177,8 +177,7 @@ class MainWindow(QMainWindow):
|
||||
def __background_update(self):
|
||||
while True:
|
||||
self.update_servers()
|
||||
# self.fetch_jobs()
|
||||
# todo: fix job updates - issues with threading
|
||||
self.fetch_jobs()
|
||||
time.sleep(0.5)
|
||||
|
||||
def closeEvent(self, event):
|
||||
@@ -198,33 +197,44 @@ class MainWindow(QMainWindow):
|
||||
|
||||
@property
|
||||
def current_server_proxy(self):
|
||||
return self.server_proxies.get(self.current_hostname, None)
|
||||
return ServerProxyManager.get_proxy_for_hostname(self.current_hostname)
|
||||
|
||||
def server_picked(self):
|
||||
"""Update the table and Server Info box when a server is changed"""
|
||||
"""Update the UI elements relevant to the server selection."""
|
||||
try:
|
||||
# Retrieve the new hostname selected by the user
|
||||
new_hostname = self.server_list_view.currentItem().text()
|
||||
|
||||
# Check if the hostname has changed to avoid unnecessary updates
|
||||
if new_hostname != self.current_hostname:
|
||||
# Update the current hostname and clear the job list
|
||||
self.current_hostname = new_hostname
|
||||
self.job_list_view.setRowCount(0)
|
||||
self.fetch_jobs(clear_table=True)
|
||||
|
||||
# Select the first row if there are jobs listed
|
||||
if self.job_list_view.rowCount():
|
||||
self.job_list_view.selectRow(0)
|
||||
|
||||
# Update the Server Info box when a server is changed
|
||||
self.server_info_hostname.setText(self.current_hostname or "unknown")
|
||||
server_info = ZeroconfServer.get_hostname_properties(self.current_hostname)
|
||||
if server_info:
|
||||
self.server_info_os.setText(f"OS: {server_info['system_os']} {server_info['system_os_version']}")
|
||||
self.server_info_cpu.setText(f"CPU: {server_info['system_cpu']} - {server_info.get('system_cpu_cores')} cores")
|
||||
else:
|
||||
self.server_info_os.setText(f"OS: Unknown")
|
||||
self.server_info_cpu.setText(f"CPU: Unknown")
|
||||
# Update server information display
|
||||
self.update_server_info_display(new_hostname)
|
||||
|
||||
except AttributeError:
|
||||
# Handle cases where the server list view might not be properly initialized
|
||||
pass
|
||||
|
||||
def update_server_info_display(self, hostname):
|
||||
"""Updates the server information section of the UI."""
|
||||
self.server_info_hostname.setText(hostname or "unknown")
|
||||
server_info = ZeroconfServer.get_hostname_properties(hostname)
|
||||
|
||||
# Use the get method with defaults to avoid KeyError
|
||||
os_info = f"OS: {server_info.get('system_os', 'Unknown')} {server_info.get('system_os_version', '')}"
|
||||
cpu_info = f"CPU: {server_info.get('system_cpu', 'Unknown')} - {server_info.get('system_cpu_cores', 'Unknown')} cores"
|
||||
|
||||
self.server_info_os.setText(os_info.strip())
|
||||
self.server_info_cpu.setText(cpu_info)
|
||||
|
||||
def fetch_jobs(self, clear_table=False):
|
||||
|
||||
if not self.current_server_proxy:
|
||||
@@ -380,10 +390,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
# Update proxys
|
||||
for hostname in found_servers:
|
||||
if not self.server_proxies.get(hostname, None):
|
||||
new_proxy = RenderServerProxy(hostname=hostname)
|
||||
new_proxy.start_background_update()
|
||||
self.server_proxies[hostname] = new_proxy
|
||||
ServerProxyManager.get_proxy_for_hostname(hostname) # setup background updates
|
||||
|
||||
# Add in all the missing servers
|
||||
current_server_list = []
|
||||
|
||||
Reference in New Issue
Block a user