VMBase dataclass added
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"folders": [
|
"folders": [
|
||||||
{
|
{
|
||||||
"path": ".."
|
"path": "."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "../clan-cli"
|
"path": "../clan-cli/clan_cli"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {}
|
"settings": {}
|
||||||
|
|||||||
@@ -1,35 +1,31 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import clan_cli
|
import clan_cli
|
||||||
|
from gi.repository import GdkPixbuf
|
||||||
|
|
||||||
|
|
||||||
class VM:
|
@dataclass(frozen=True)
|
||||||
def __init__(
|
class VMBase:
|
||||||
self,
|
icon: Path | GdkPixbuf.Pixbuf
|
||||||
*,
|
name: str
|
||||||
icon: Path,
|
url: str
|
||||||
name: str,
|
running: bool
|
||||||
url: str,
|
|
||||||
path: Path,
|
|
||||||
running: bool = False,
|
|
||||||
autostart: bool = False,
|
|
||||||
) -> None:
|
|
||||||
self.icon = icon.resolve()
|
|
||||||
assert self.icon.exists()
|
|
||||||
assert self.icon.is_file()
|
|
||||||
self.url = url
|
|
||||||
self.autostart = autostart
|
|
||||||
self.running = running
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
self.path = path.resolve()
|
@staticmethod
|
||||||
print(self.path)
|
def name_to_type_map() -> OrderedDict[str, type]:
|
||||||
assert self.path.exists()
|
return OrderedDict(
|
||||||
assert self.path.is_dir()
|
{
|
||||||
|
"Icon": GdkPixbuf.Pixbuf,
|
||||||
|
"Name": str,
|
||||||
|
"URL": str,
|
||||||
|
"Running": bool,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def list_display(self) -> OrderedDict[str, Any]:
|
def list_data(self) -> OrderedDict[str, Any]:
|
||||||
return OrderedDict(
|
return OrderedDict(
|
||||||
{
|
{
|
||||||
"Icon": str(self.icon),
|
"Icon": str(self.icon),
|
||||||
@@ -40,6 +36,12 @@ class VM:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class VM(VMBase):
|
||||||
|
path: Path
|
||||||
|
autostart: bool = False
|
||||||
|
|
||||||
|
|
||||||
def list_vms() -> list[VM]:
|
def list_vms() -> list[VM]:
|
||||||
assets = Path(__file__).parent / "assets"
|
assets = Path(__file__).parent / "assets"
|
||||||
|
|
||||||
@@ -56,23 +58,23 @@ def list_vms() -> list[VM]:
|
|||||||
name="Zenith Clan",
|
name="Zenith Clan",
|
||||||
url="clan://zenith.lol",
|
url="clan://zenith.lol",
|
||||||
path=Path(__file__).parent.parent / "test_democlan",
|
path=Path(__file__).parent.parent / "test_democlan",
|
||||||
|
running=False,
|
||||||
),
|
),
|
||||||
VM(
|
VM(
|
||||||
icon=assets / "firestorm.jpeg",
|
icon=assets / "firestorm.jpeg",
|
||||||
name="Firestorm Clan",
|
name="Firestorm Clan",
|
||||||
url="clan://firestorm.lol",
|
url="clan://firestorm.lol",
|
||||||
path=Path(__file__).parent.parent / "test_democlan",
|
path=Path(__file__).parent.parent / "test_democlan",
|
||||||
|
running=False,
|
||||||
),
|
),
|
||||||
VM(
|
VM(
|
||||||
icon=assets / "placeholder.jpeg",
|
icon=assets / "placeholder.jpeg",
|
||||||
name="Demo Clan",
|
name="Demo Clan",
|
||||||
url="clan://demo.lol",
|
url="clan://demo.lol",
|
||||||
path=Path(__file__).parent.parent / "test_democlan",
|
path=Path(__file__).parent.parent / "test_democlan",
|
||||||
|
running=False,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
# vms.extend(vms)
|
|
||||||
# vms.extend(vms)
|
|
||||||
# vms.extend(vms)
|
|
||||||
|
|
||||||
for path in clan_cli.flakes.history.list_history():
|
for path in clan_cli.flakes.history.list_history():
|
||||||
new_vm = {
|
new_vm = {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from collections.abc import Callable
|
|||||||
|
|
||||||
from gi.repository import GdkPixbuf, Gtk
|
from gi.repository import GdkPixbuf, Gtk
|
||||||
|
|
||||||
from ..models import VM, list_vms
|
from ..models import VM, VMBase, list_vms
|
||||||
|
|
||||||
|
|
||||||
class ClanSelectPage(Gtk.Box):
|
class ClanSelectPage(Gtk.Box):
|
||||||
@@ -34,16 +34,16 @@ class ClanSelectPage(Gtk.Box):
|
|||||||
def on_backup_clicked(self, widget: Gtk.Widget) -> None:
|
def on_backup_clicked(self, widget: Gtk.Widget) -> None:
|
||||||
print("Backup clicked")
|
print("Backup clicked")
|
||||||
|
|
||||||
def on_cell_toggled(self, widget: Gtk.Widget, path: str) -> None:
|
def on_cell_toggled(self, vm: VMBase) -> None:
|
||||||
print(f"on_cell_toggled: {path}")
|
print(f"on_cell_toggled: {vm}")
|
||||||
# Get the current value from the model
|
# # Get the current value from the model
|
||||||
current_value = self.list_store[path][1]
|
# current_value = self.list_store[path][1]
|
||||||
|
|
||||||
print(f"current_value: {current_value}")
|
# print(f"current_value: {current_value}")
|
||||||
# Toggle the value
|
# # Toggle the value
|
||||||
self.list_store[path][1] = not current_value
|
# self.list_store[path][1] = not current_value
|
||||||
# Print the updated value
|
# # Print the updated value
|
||||||
print("Switched", path, "to", self.list_store[path][1])
|
# print("Switched", path, "to", self.list_store[path][1])
|
||||||
|
|
||||||
def on_select_row(self, selection: Gtk.TreeSelection) -> None:
|
def on_select_row(self, selection: Gtk.TreeSelection) -> None:
|
||||||
model, row = selection.get_selected()
|
model, row = selection.get_selected()
|
||||||
@@ -94,16 +94,17 @@ class ClanSelectList(Gtk.Box):
|
|||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(expand=True)
|
super().__init__(expand=True)
|
||||||
self.vms = vms
|
self.vms = vms
|
||||||
|
self.on_cell_toggled = on_cell_toggled
|
||||||
self.list_store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, bool)
|
self.list_store = Gtk.ListStore(*VM.name_to_type_map().values())
|
||||||
for vm in vms:
|
for vm in vms:
|
||||||
items = list(vm.list_display().values())
|
items = list(vm.list_data().values())
|
||||||
items[0] = GdkPixbuf.Pixbuf.new_from_file_at_size(items[0], 64, 64)
|
items[0] = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||||
assert len(items) == 4
|
filename=items[0], width=64, height=64, preserve_aspect_ratio=True
|
||||||
|
)
|
||||||
self.list_store.append(items)
|
self.list_store.append(items)
|
||||||
|
|
||||||
self.tree_view = Gtk.TreeView(self.list_store, expand=True)
|
self.tree_view = Gtk.TreeView(self.list_store, expand=True)
|
||||||
for idx, (key, value) in enumerate(vm.list_display().items()):
|
for idx, (key, value) in enumerate(vm.list_data().items()):
|
||||||
match key:
|
match key:
|
||||||
case "Icon":
|
case "Icon":
|
||||||
renderer = Gtk.CellRendererPixbuf()
|
renderer = Gtk.CellRendererPixbuf()
|
||||||
@@ -128,7 +129,7 @@ class ClanSelectList(Gtk.Box):
|
|||||||
case "Running":
|
case "Running":
|
||||||
renderer = Gtk.CellRendererToggle()
|
renderer = Gtk.CellRendererToggle()
|
||||||
renderer.set_property("activatable", True)
|
renderer.set_property("activatable", True)
|
||||||
renderer.connect("toggled", on_cell_toggled)
|
renderer.connect("toggled", self._on_cell_toggled)
|
||||||
col = Gtk.TreeViewColumn(key, renderer, active=idx)
|
col = Gtk.TreeViewColumn(key, renderer, active=idx)
|
||||||
col.set_resizable(True)
|
col.set_resizable(True)
|
||||||
col.set_expand(True)
|
col.set_expand(True)
|
||||||
@@ -143,3 +144,8 @@ class ClanSelectList(Gtk.Box):
|
|||||||
|
|
||||||
self.set_border_width(10)
|
self.set_border_width(10)
|
||||||
self.add(self.tree_view)
|
self.add(self.tree_view)
|
||||||
|
|
||||||
|
def _on_cell_toggled(self, widget: Gtk.CellRendererToggle, path: str) -> None:
|
||||||
|
row = self.list_store[path]
|
||||||
|
vm = VMBase(*row)
|
||||||
|
self.on_cell_toggled(vm)
|
||||||
|
|||||||
Submodule pkgs/clan-vm-manager/test_democlan updated: 99f20170a9...6287f4e191
Reference in New Issue
Block a user