Added UI structure and first clan vm manager
This commit is contained in:
parent
f0f6bdce96
commit
50590ecdc4
@ -24,112 +24,18 @@ vms = [
|
||||
VM("clan://clan.lol", True, "/home/user/my-clan"),
|
||||
VM("clan://lassul.lol", False, "/home/user/my-clan"),
|
||||
VM("clan://mic.lol", False, "/home/user/my-clan"),
|
||||
VM("clan://dan.lol", False, "/home/user/my-clan")
|
||||
]
|
||||
|
||||
vms.extend(vms)
|
||||
# vms.extend(vms)
|
||||
# vms.extend(vms)
|
||||
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from .ui.clan_select_list import ClanSelectPage
|
||||
|
||||
class SwitchTreeView(Gtk.ApplicationWindow):
|
||||
def __init__(self, application):
|
||||
super().__init__(application=application, title="Switch TreeView Example")
|
||||
self.set_default_size(300, 200)
|
||||
|
||||
# Create a list store with two strings and a boolean
|
||||
self.liststore = Gtk.ListStore(str, str, bool)
|
||||
# Add some sample data
|
||||
self.liststore.append(["Foo", "Bar", True])
|
||||
self.liststore.append(["Baz", "Qux", False])
|
||||
self.liststore.append(["Quux", "Quuz", True])
|
||||
|
||||
# Create a tree view with the list store as the model
|
||||
self.treeview = Gtk.TreeView(model=self.liststore)
|
||||
self.add(self.treeview)
|
||||
|
||||
# Create a cell renderer for text
|
||||
renderer_text = Gtk.CellRendererText()
|
||||
|
||||
# Create a tree view column for the first string
|
||||
column_text1 = Gtk.TreeViewColumn("Text 1", renderer_text, text=0)
|
||||
# Add the column to the tree view
|
||||
self.treeview.append_column(column_text1)
|
||||
|
||||
# Create another tree view column for the second string
|
||||
column_text2 = Gtk.TreeViewColumn("Text 2", renderer_text, text=1)
|
||||
# Add the column to the tree view
|
||||
self.treeview.append_column(column_text2)
|
||||
|
||||
# Create a cell renderer for toggle
|
||||
renderer_toggle = Gtk.CellRendererToggle()
|
||||
# Set the cell renderer to be activatable
|
||||
renderer_toggle.set_property("activatable", True)
|
||||
# Connect a signal handler to the toggled signal
|
||||
renderer_toggle.connect("toggled", self.on_cell_toggled)
|
||||
|
||||
# Create a tree view column for the switch
|
||||
column_toggle = Gtk.TreeViewColumn("Switch", renderer_toggle, active=2)
|
||||
# Add the column to the tree view
|
||||
self.treeview.append_column(column_toggle)
|
||||
self.show_all()
|
||||
|
||||
def on_cell_toggled(self, widget, path):
|
||||
# Get the current value from the model
|
||||
current_value = self.liststore[path][2]
|
||||
# Toggle the value
|
||||
self.liststore[path][2] = not current_value
|
||||
# Print the updated value
|
||||
print("Switched", path, "to", self.liststore[path][2])
|
||||
|
||||
|
||||
class ClanSelectList(Gtk.Box):
|
||||
def __init__(self, vms):
|
||||
super().__init__()
|
||||
self.vms = vms
|
||||
|
||||
self.list_store = Gtk.ListStore(str, bool, str)
|
||||
for vm in vms:
|
||||
items = list(vm.__dict__.values())
|
||||
print(f"Table: {items}")
|
||||
self.list_store.append(items)
|
||||
|
||||
self.tree_view = Gtk.TreeView(self.list_store)
|
||||
for (idx, (key, value)) in enumerate(vm.__dict__.items()):
|
||||
if isinstance(value, str):
|
||||
renderer = Gtk.CellRendererText()
|
||||
col = Gtk.TreeViewColumn(key.capitalize(), renderer, text=idx)
|
||||
col.set_sort_column_id(idx)
|
||||
self.tree_view.append_column(col)
|
||||
if isinstance(value, bool):
|
||||
renderer = Gtk.CellRendererToggle()
|
||||
renderer.set_property("activatable", True)
|
||||
renderer.connect("toggled", self.on_cell_toggled)
|
||||
col = Gtk.TreeViewColumn(key.capitalize(), renderer, active=idx)
|
||||
col.set_sort_column_id(idx)
|
||||
self.tree_view.append_column(col)
|
||||
|
||||
selection = self.tree_view.get_selection()
|
||||
selection.connect("changed", self.on_select_row)
|
||||
|
||||
|
||||
self.set_border_width(10)
|
||||
self.add(self.tree_view)
|
||||
|
||||
def on_cell_toggled(self, widget, path):
|
||||
print(f"on_cell_toggled: {path}")
|
||||
# Get the current value from the model
|
||||
current_value = self.list_store[path][1]
|
||||
|
||||
print(f"current_value: {current_value}")
|
||||
# Toggle the value
|
||||
self.list_store[path][1] = not current_value
|
||||
# Print the updated value
|
||||
print("Switched", path, "to", self.list_store[path][1])
|
||||
|
||||
|
||||
def on_select_row(self, selection):
|
||||
model, row = selection.get_selected()
|
||||
if row is not None:
|
||||
print(f"Selected {model[row][0]}")
|
||||
|
||||
class ClanJoinPage(Gtk.Box):
|
||||
def __init__(self):
|
||||
@ -138,6 +44,7 @@ class ClanJoinPage(Gtk.Box):
|
||||
self.set_border_width(10)
|
||||
self.add(Gtk.Label(label="Add/Join another clan"))
|
||||
|
||||
|
||||
class MainWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self, application: Gtk.Application) -> None:
|
||||
super().__init__(application=application)
|
||||
@ -145,17 +52,16 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self.set_title("Clan VM Manager")
|
||||
self.connect("delete-event", self.on_quit)
|
||||
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
|
||||
self.add(vbox)
|
||||
|
||||
self.set_border_width(10)
|
||||
|
||||
# Add a notebook layout
|
||||
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html#notebook
|
||||
self.notebook = Gtk.Notebook()
|
||||
vbox.add(self.notebook)
|
||||
|
||||
self.notebook.append_page(ClanSelectList(vms), Gtk.Label(label="Overview"))
|
||||
self.notebook.append_page(ClanSelectPage(vms), Gtk.Label(label="Overview"))
|
||||
self.notebook.append_page(ClanJoinPage(), Gtk.Label(label="Add/Join"))
|
||||
|
||||
# Must be called AFTER all components were added
|
||||
@ -164,10 +70,6 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
def on_quit(self, *args):
|
||||
Gio.Application.quit(self.get_application())
|
||||
|
||||
def on_select_row(self, selection):
|
||||
model, row = selection.get_selected()
|
||||
if row is not None:
|
||||
print(f"Selected {model[row][0]}")
|
||||
|
||||
|
||||
class Application(Gtk.Application):
|
||||
|
0
pkgs/clan-vm-manager/clan_vm_manager/ui/__init__.py
Normal file
0
pkgs/clan-vm-manager/clan_vm_manager/ui/__init__.py
Normal file
90
pkgs/clan-vm-manager/clan_vm_manager/ui/clan_select_list.py
Normal file
90
pkgs/clan-vm-manager/clan_vm_manager/ui/clan_select_list.py
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
|
||||
import gi
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
|
||||
class ClanSelectPage(Gtk.Box):
|
||||
def __init__(self, vms):
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||
|
||||
self.add(ClanSelectList(vms))
|
||||
self.add(ClanSelectButtons(self.on_start_clicked, self.on_stop_clicked, self.on_backup_clicked))
|
||||
|
||||
def on_start_clicked(self, widget):
|
||||
print("Start clicked")
|
||||
|
||||
def on_stop_clicked(self, widget):
|
||||
print("Stop clicked")
|
||||
|
||||
def on_backup_clicked(self, widget):
|
||||
print("Backup clicked")
|
||||
|
||||
class ClanSelectButtons(Gtk.Box):
|
||||
def __init__(self, on_start_clicked, on_stop_clicked, on_backup_clicked):
|
||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
button = Gtk.Button(label="Start", margin_left=10)
|
||||
button.connect("clicked", on_start_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Stop", margin_left=10)
|
||||
button.connect("clicked", on_stop_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Backup", margin_left=10)
|
||||
button.connect("clicked", on_backup_clicked)
|
||||
self.add(button)
|
||||
|
||||
|
||||
class ClanSelectList(Gtk.Box):
|
||||
def __init__(self, vms):
|
||||
super().__init__(expand=True)
|
||||
self.vms = vms
|
||||
|
||||
self.list_store = Gtk.ListStore(str, bool, str)
|
||||
for vm in vms:
|
||||
items = list(vm.__dict__.values())
|
||||
print(f"Table: {items}")
|
||||
self.list_store.append(items)
|
||||
|
||||
self.tree_view = Gtk.TreeView(self.list_store, expand=True)
|
||||
for (idx, (key, value)) in enumerate(vm.__dict__.items()):
|
||||
if isinstance(value, str):
|
||||
renderer = Gtk.CellRendererText()
|
||||
#renderer.set_property("xalign", 0.5)
|
||||
col = Gtk.TreeViewColumn(key.capitalize(), renderer, text=idx)
|
||||
col.set_property("alignment", 0.5)
|
||||
col.set_sort_column_id(idx)
|
||||
self.tree_view.append_column(col)
|
||||
if isinstance(value, bool):
|
||||
renderer = Gtk.CellRendererToggle()
|
||||
renderer.set_property("activatable", True)
|
||||
renderer.connect("toggled", self.on_cell_toggled)
|
||||
col = Gtk.TreeViewColumn(key.capitalize(), renderer, active=idx)
|
||||
col.set_property("alignment", 0.5)
|
||||
col.set_sort_column_id(idx)
|
||||
self.tree_view.append_column(col)
|
||||
|
||||
selection = self.tree_view.get_selection()
|
||||
selection.connect("changed", self.on_select_row)
|
||||
|
||||
|
||||
self.set_border_width(10)
|
||||
self.add(self.tree_view)
|
||||
|
||||
def on_cell_toggled(self, widget, path):
|
||||
print(f"on_cell_toggled: {path}")
|
||||
# Get the current value from the model
|
||||
current_value = self.list_store[path][1]
|
||||
|
||||
print(f"current_value: {current_value}")
|
||||
# Toggle the value
|
||||
self.list_store[path][1] = not current_value
|
||||
# Print the updated value
|
||||
print("Switched", path, "to", self.list_store[path][1])
|
||||
|
||||
|
||||
def on_select_row(self, selection):
|
||||
model, row = selection.get_selected()
|
||||
if row is not None:
|
||||
print(f"Selected {model[row][0]}")
|
Loading…
Reference in New Issue
Block a user