-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin10.py
76 lines (63 loc) · 2.11 KB
/
win10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3
import libvirt
import subprocess
import time
import tkinter as tk
from tkinter import ttk
# Define the connection URI and VM name and Delay
uri = "qemu:///system"
vm_name = "win10-2"
time_delay = 10
# Function to update the progress bar
def update_progress_bar(progress, label_text, window, progress_var, progress_label):
progress_var.set(progress)
progress_label.config(text=label_text)
window.update_idletasks()
# Function to close the GUI window
def close_window(window):
print("Closing the window.")
window.destroy()
# Function to check the state of the VM
def check_vm_state():
conn = libvirt.open(uri)
if conn is None:
print("Failed to open connection to the hypervisor")
return None
try:
vm = conn.lookupByName(vm_name)
if vm.isActive():
print(f"The {vm_name} virtual machine is running.")
return vm
else:
print(f"The {vm_name} virtual machine is not running.")
print("Starting the VM...")
vm.create()
return vm
finally:
conn.close()
# Function to start the VM and show the progress bar
def start_vm_and_show_progress(window, progress_var, progress_label):
vm = check_vm_state()
if vm is not None:
for i in range(1, 6):
update_progress_bar(i * 20, f'{i * 20}% completed', window, progress_var, progress_label)
time.sleep(time_delay)
print("Launching looking-glass-client")
subprocess.Popen(['looking-glass-client', '-a' , '-m 88'])
print("looking-glass-client launched")
close_window(window)
# Create the main window
window = tk.Tk()
window.title("VM Startup Progress")
window.geometry("300x100")
# Create a progress bar
progress_var = tk.IntVar()
progress_bar = ttk.Progressbar(window, variable=progress_var, maximum=100)
progress_bar.pack(pady=20)
# Create a label for progress text
progress_label = tk.Label(window, text="0% completed")
progress_label.pack()
# Start the VM and show the progress bar
start_vm_and_show_progress(window, progress_var, progress_label)
# Run the GUI event loop
window.mainloop()