Add VM list refresh
- Add ability to query new VMs every 10 seconds, and redraw the window if a different list is found. - Remove vestigial DPI checking code.
This commit is contained in:
		
							parent
							
								
									a7f15ac8b9
								
							
						
					
					
						commit
						57ffa48257
					
				
							
								
								
									
										56
									
								
								vdiclient.py
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								vdiclient.py
									
									
									
									
									
								
							@ -3,6 +3,7 @@ import proxmoxer # pip install proxmoxer
 | 
				
			|||||||
import PySimpleGUI as sg # pip install PySimpleGUI
 | 
					import PySimpleGUI as sg # pip install PySimpleGUI
 | 
				
			||||||
gui = 'TK'
 | 
					gui = 'TK'
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
 | 
					from datetime import datetime
 | 
				
			||||||
from configparser import ConfigParser
 | 
					from configparser import ConfigParser
 | 
				
			||||||
import random
 | 
					import random
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
@ -36,24 +37,6 @@ class G:
 | 
				
			|||||||
	theme = 'LightBlue'
 | 
						theme = 'LightBlue'
 | 
				
			||||||
	guest_type = 'both'
 | 
						guest_type = 'both'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_dpi():
 | 
					 | 
				
			||||||
	import ctypes
 | 
					 | 
				
			||||||
	import win32api # pip install pywin32
 | 
					 | 
				
			||||||
	shcore = ctypes.windll.shcore
 | 
					 | 
				
			||||||
	monitors = win32api.EnumDisplayMonitors()
 | 
					 | 
				
			||||||
	hresult = shcore.SetProcessDpiAwareness(2)
 | 
					 | 
				
			||||||
	assert hresult == 0
 | 
					 | 
				
			||||||
	dpiX = ctypes.c_uint()
 | 
					 | 
				
			||||||
	dpiY = ctypes.c_uint()
 | 
					 | 
				
			||||||
	for i, monitor in enumerate(monitors):
 | 
					 | 
				
			||||||
		shcore.GetDpiForMonitor(
 | 
					 | 
				
			||||||
			monitor[0].handle,
 | 
					 | 
				
			||||||
			0,
 | 
					 | 
				
			||||||
			ctypes.byref(dpiX),
 | 
					 | 
				
			||||||
			ctypes.byref(dpiY)
 | 
					 | 
				
			||||||
		)
 | 
					 | 
				
			||||||
		return dpiX.value/96
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def loadconfig(config_location = None):
 | 
					def loadconfig(config_location = None):
 | 
				
			||||||
	if config_location:
 | 
						if config_location:
 | 
				
			||||||
		config = ConfigParser(delimiters='=')
 | 
							config = ConfigParser(delimiters='=')
 | 
				
			||||||
@ -209,7 +192,7 @@ def setvmlayout(vms):
 | 
				
			|||||||
	for vm in vms:
 | 
						for vm in vms:
 | 
				
			||||||
		if not vm["status"] == "unknown":
 | 
							if not vm["status"] == "unknown":
 | 
				
			||||||
			connkeyname = f'-CONN|{vm["vmid"]}-'
 | 
								connkeyname = f'-CONN|{vm["vmid"]}-'
 | 
				
			||||||
			layoutcolumn.append([sg.Text(vm['name'], font=["Helvetica", 14]), sg.Button('Connect', font=["Helvetica", 14], key=connkeyname)])
 | 
								layoutcolumn.append([sg.Text(vm['name'], font=["Helvetica", 14], size=(22*G.scaling, 1*G.scaling)), sg.Button('Connect', font=["Helvetica", 14], key=connkeyname)])
 | 
				
			||||||
			layoutcolumn.append([sg.HorizontalSeparator()])
 | 
								layoutcolumn.append([sg.HorizontalSeparator()])
 | 
				
			||||||
	if len(vms) > 5: # We need a scrollbar
 | 
						if len(vms) > 5: # We need a scrollbar
 | 
				
			||||||
		layout.append([sg.Column(layoutcolumn, scrollable = True, size = [450*G.scaling, None] )])
 | 
							layout.append([sg.Column(layoutcolumn, scrollable = True, size = [450*G.scaling, None] )])
 | 
				
			||||||
@ -414,18 +397,33 @@ def loginwindow():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def showvms():
 | 
					def showvms():
 | 
				
			||||||
	vms = getvms()
 | 
						vms = getvms()
 | 
				
			||||||
	if vms == False:
 | 
						newvms = getvms()
 | 
				
			||||||
 | 
						if newvms == False:
 | 
				
			||||||
		return False
 | 
							return False
 | 
				
			||||||
	if len(vms) < 1:
 | 
						if len(newvms) < 1:
 | 
				
			||||||
		win_popup_button('No desktop instances found, please consult with your system administrator', 'OK')
 | 
							win_popup_button('No desktop instances found, please consult with your system administrator', 'OK')
 | 
				
			||||||
		return False
 | 
							return False
 | 
				
			||||||
	layout = setvmlayout(vms)
 | 
						layout = setvmlayout(newvms)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if G.icon:
 | 
						if G.icon:
 | 
				
			||||||
		window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk, icon=G.icon)
 | 
							window = sg.Window(G.title, layout, return_keyboard_events=True, finalize=True, resizable=False, no_titlebar=G.kiosk, icon=G.icon)
 | 
				
			||||||
	else:
 | 
						else:
 | 
				
			||||||
		window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk)
 | 
							window = sg.Window(G.title, layout, return_keyboard_events=True, finalize=True, resizable=False, no_titlebar=G.kiosk)
 | 
				
			||||||
 | 
						timer = datetime.now()
 | 
				
			||||||
	while True:
 | 
						while True:
 | 
				
			||||||
		event, values = window.read()
 | 
							if (datetime.now() - timer).total_seconds() > 10:
 | 
				
			||||||
 | 
								timer = datetime.now()
 | 
				
			||||||
 | 
								newvms = getvms()
 | 
				
			||||||
 | 
								if vms != newvms:
 | 
				
			||||||
 | 
									vms = getvms()
 | 
				
			||||||
 | 
									layout = setvmlayout(newvms)
 | 
				
			||||||
 | 
									window.close()
 | 
				
			||||||
 | 
									if G.icon:
 | 
				
			||||||
 | 
										window = sg.Window(G.title, layout, return_keyboard_events=True, finalize=True, resizable=False, no_titlebar=G.kiosk, icon=G.icon)
 | 
				
			||||||
 | 
									else:
 | 
				
			||||||
 | 
										window = sg.Window(G.title, layout, return_keyboard_events=True,finalize=True, resizable=False, no_titlebar=G.kiosk)
 | 
				
			||||||
 | 
									window.bring_to_front()
 | 
				
			||||||
 | 
							event, values = window.read(timeout = 1000)
 | 
				
			||||||
		if event in ('Logout', None):
 | 
							if event in ('Logout', None):
 | 
				
			||||||
			window.close()
 | 
								window.close()
 | 
				
			||||||
			return False
 | 
								return False
 | 
				
			||||||
@ -442,13 +440,7 @@ def showvms():
 | 
				
			|||||||
	return True
 | 
						return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
	if os.name == 'nt' and gui == 'QT':
 | 
						G.scaling = 1 # TKinter requires integers
 | 
				
			||||||
		G.scaling = get_dpi()
 | 
					 | 
				
			||||||
	else:
 | 
					 | 
				
			||||||
		if gui == 'QT':
 | 
					 | 
				
			||||||
			G.scaling = 1.0 #TODO FIXME: Figure out scaling on Linux
 | 
					 | 
				
			||||||
		else:
 | 
					 | 
				
			||||||
			G.scaling = 1 # TKinter requires integers
 | 
					 | 
				
			||||||
	config_location = None
 | 
						config_location = None
 | 
				
			||||||
	if len(sys.argv) > 1:
 | 
						if len(sys.argv) > 1:
 | 
				
			||||||
		if sys.argv[1] == '--list_themes':
 | 
							if sys.argv[1] == '--list_themes':
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user