80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
import subprocess
|
|
|
|
class VBoxManagerGUI:
|
|
def __init__(self, root):
|
|
self.root = root
|
|
self.root.title("VirtualBox Manager")
|
|
|
|
# Frames
|
|
self.frame_vm_list = ttk.Frame(self.root, padding="10")
|
|
self.frame_vm_list.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
|
|
|
|
self.frame_buttons = ttk.Frame(self.root, padding="10")
|
|
self.frame_buttons.grid(row=1, column=0, padx=10, pady=10, sticky="nsew")
|
|
|
|
# VM List
|
|
self.label_vm_list = ttk.Label(self.frame_vm_list, text="VM List:")
|
|
self.label_vm_list.grid(row=0, column=0, sticky="w")
|
|
|
|
self.vm_listbox = tk.Listbox(self.frame_vm_list, height=10, selectmode=tk.SINGLE)
|
|
self.vm_listbox.grid(row=1, column=0, sticky="nsew")
|
|
|
|
# Buttons
|
|
self.button_create_vm = ttk.Button(self.frame_buttons, text="Create VM", command=self.create_vm)
|
|
self.button_create_vm.grid(row=0, column=0, padx=5)
|
|
|
|
self.button_start_vm = ttk.Button(self.frame_buttons, text="Start VM", command=self.start_vm)
|
|
self.button_start_vm.grid(row=0, column=1, padx=5)
|
|
|
|
self.button_stop_vm = ttk.Button(self.frame_buttons, text="Stop VM", command=self.stop_vm)
|
|
self.button_stop_vm.grid(row=0, column=2, padx=5)
|
|
|
|
# Configure grid weights
|
|
self.root.grid_columnconfigure(0, weight=1)
|
|
self.root.grid_rowconfigure(0, weight=1)
|
|
self.root.grid_rowconfigure(1, weight=0)
|
|
|
|
# Populate VM List
|
|
self.update_vm_list()
|
|
|
|
def create_vm(self):
|
|
# Implement logic to create a VirtualBox VM
|
|
pass
|
|
|
|
def start_vm(self):
|
|
selected_vm = self.vm_listbox.get(tk.ACTIVE)
|
|
if selected_vm:
|
|
subprocess.run(["vboxmanage", "startvm", selected_vm])
|
|
|
|
def stop_vm(self):
|
|
selected_vm = self.vm_listbox.get(tk.ACTIVE)
|
|
if selected_vm:
|
|
subprocess.run(["vboxmanage", "controlvm", selected_vm, "poweroff"])
|
|
|
|
def update_vm_list(self):
|
|
try:
|
|
# Run the vboxmanage list vms command
|
|
result = subprocess.run(["vboxmanage", "list", "vms"], capture_output=True, text=True)
|
|
output_lines = result.stdout.splitlines()
|
|
|
|
# Clear the existing items in the Listbox
|
|
self.vm_listbox.delete(0, tk.END)
|
|
|
|
# Parse the output and update the Listbox
|
|
for line in output_lines:
|
|
parts = line.split()
|
|
if len(parts) >= 2:
|
|
vm_name = parts[0]
|
|
self.vm_listbox.insert(tk.END, vm_name)
|
|
|
|
except Exception as e:
|
|
# Handle exceptions (e.g., vboxmanage not found)
|
|
print(f"Error updating VM list: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
root = tk.Tk()
|
|
app = VBoxManagerGUI(root)
|
|
root.mainloop()
|