Replaced Status with checkbox
This commit is contained in:
@@ -94,3 +94,6 @@ class ClanURI:
|
|||||||
urlparams = urllib.parse.urlencode(params.__dict__)
|
urlparams = urllib.parse.urlencode(params.__dict__)
|
||||||
|
|
||||||
return cls(f"clan://file://{path}?{urlparams}")
|
return cls(f"clan://file://{path}?{urlparams}")
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"ClanURI({self._components.geturl()})"
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -13,22 +12,12 @@ from gi.repository import GdkPixbuf
|
|||||||
from clan_vm_manager import assets
|
from clan_vm_manager import assets
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
OFF = "Off"
|
|
||||||
RUNNING = "Running"
|
|
||||||
# SUSPENDED = "Suspended"
|
|
||||||
# UNKNOWN = "Unknown"
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return self.value
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class VMBase:
|
class VMBase:
|
||||||
icon: Path | GdkPixbuf.Pixbuf
|
icon: Path | GdkPixbuf.Pixbuf
|
||||||
name: str
|
name: str
|
||||||
url: str
|
url: str
|
||||||
status: Status
|
status: bool
|
||||||
_path: Path
|
_path: Path
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -38,7 +27,7 @@ class VMBase:
|
|||||||
"Icon": GdkPixbuf.Pixbuf,
|
"Icon": GdkPixbuf.Pixbuf,
|
||||||
"Name": str,
|
"Name": str,
|
||||||
"URL": str,
|
"URL": str,
|
||||||
"Status": str,
|
"Online": bool,
|
||||||
"_Path": str,
|
"_Path": str,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -53,7 +42,7 @@ class VMBase:
|
|||||||
"Icon": str(self.icon),
|
"Icon": str(self.icon),
|
||||||
"Name": self.name,
|
"Name": self.name,
|
||||||
"URL": self.url,
|
"URL": self.url,
|
||||||
"Status": str(self.status),
|
"Online": self.status,
|
||||||
"_Path": str(self._path),
|
"_Path": str(self._path),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -92,7 +81,7 @@ def get_initial_vms(start: int = 0, end: int | None = None) -> list[VM]:
|
|||||||
name="Cybernet Clan",
|
name="Cybernet Clan",
|
||||||
url="clan://cybernet.lol",
|
url="clan://cybernet.lol",
|
||||||
_path=Path(__file__).parent.parent / "test_democlan",
|
_path=Path(__file__).parent.parent / "test_democlan",
|
||||||
status=Status.RUNNING,
|
status=False,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
VM(
|
VM(
|
||||||
@@ -101,7 +90,7 @@ def get_initial_vms(start: int = 0, end: int | None = None) -> 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",
|
||||||
status=Status.OFF,
|
status=False,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
VM(
|
VM(
|
||||||
@@ -110,7 +99,7 @@ def get_initial_vms(start: int = 0, end: int | None = None) -> list[VM]:
|
|||||||
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",
|
||||||
status=Status.OFF,
|
status=False,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
VM(
|
VM(
|
||||||
@@ -119,7 +108,7 @@ def get_initial_vms(start: int = 0, end: int | None = None) -> list[VM]:
|
|||||||
name="Placeholder Clan",
|
name="Placeholder Clan",
|
||||||
url="clan://demo.lol",
|
url="clan://demo.lol",
|
||||||
_path=Path(__file__).parent.parent / "test_democlan",
|
_path=Path(__file__).parent.parent / "test_democlan",
|
||||||
status=Status.OFF,
|
status=True,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
@@ -132,7 +121,7 @@ def get_initial_vms(start: int = 0, end: int | None = None) -> list[VM]:
|
|||||||
"name": "Demo Clan",
|
"name": "Demo Clan",
|
||||||
"url": "clan://demo.lol",
|
"url": "clan://demo.lol",
|
||||||
"_path": entry.path,
|
"_path": entry.path,
|
||||||
"status": Status.OFF,
|
"status": False,
|
||||||
}
|
}
|
||||||
vms.append(VM(base=VMBase(**new_vm)))
|
vms.append(VM(base=VMBase(**new_vm)))
|
||||||
|
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ class ClanList(Gtk.Box):
|
|||||||
Is the composition of
|
Is the composition of
|
||||||
the ClanListToolbar
|
the ClanListToolbar
|
||||||
the clanListView
|
the clanListView
|
||||||
# ------------------------#
|
# ------------------------ #
|
||||||
# - Tools <Join> < Edit> #
|
# - Tools <Start> <Stop> < Edit> #
|
||||||
# ------------------------#
|
# ------------------------ #
|
||||||
# - List Items
|
# - List Items
|
||||||
# - <...>
|
# - <...>
|
||||||
# ------------------------#
|
# ------------------------#
|
||||||
@@ -153,10 +153,14 @@ class ClanListToolbar(Gtk.Toolbar):
|
|||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
||||||
|
|
||||||
self.start_button = Gtk.ToolButton(label="Join")
|
self.start_button = Gtk.ToolButton(label="Start")
|
||||||
self.start_button.connect("clicked", on_start_clicked)
|
self.start_button.connect("clicked", on_start_clicked)
|
||||||
self.add(self.start_button)
|
self.add(self.start_button)
|
||||||
|
|
||||||
|
self.stop_button = Gtk.ToolButton(label="Stop")
|
||||||
|
self.stop_button.connect("clicked", on_stop_clicked)
|
||||||
|
self.add(self.stop_button)
|
||||||
|
|
||||||
self.edit_button = Gtk.ToolButton(label="Edit")
|
self.edit_button = Gtk.ToolButton(label="Edit")
|
||||||
self.edit_button.connect("clicked", on_edit_clicked)
|
self.edit_button.connect("clicked", on_edit_clicked)
|
||||||
self.add(self.edit_button)
|
self.add(self.edit_button)
|
||||||
@@ -165,9 +169,11 @@ class ClanListToolbar(Gtk.Toolbar):
|
|||||||
if s:
|
if s:
|
||||||
self.edit_button.set_sensitive(True)
|
self.edit_button.set_sensitive(True)
|
||||||
self.start_button.set_sensitive(True)
|
self.start_button.set_sensitive(True)
|
||||||
|
self.stop_button.set_sensitive(True)
|
||||||
else:
|
else:
|
||||||
self.edit_button.set_sensitive(False)
|
self.edit_button.set_sensitive(False)
|
||||||
self.start_button.set_sensitive(False)
|
self.start_button.set_sensitive(False)
|
||||||
|
self.stop_button.set_sensitive(False)
|
||||||
|
|
||||||
|
|
||||||
class ClanEditToolbar(Gtk.Toolbar):
|
class ClanEditToolbar(Gtk.Toolbar):
|
||||||
@@ -224,7 +230,6 @@ class ClanListView(Gtk.Box):
|
|||||||
return
|
return
|
||||||
selection = self.tree_view.get_selection()
|
selection = self.tree_view.get_selection()
|
||||||
idx = self.find_vm(vm)
|
idx = self.find_vm(vm)
|
||||||
print(f"Set selected vm: {vm.name} at {idx}")
|
|
||||||
selection.select_path(idx)
|
selection.select_path(idx)
|
||||||
|
|
||||||
def insertVM(self, vm: VMBase) -> None:
|
def insertVM(self, vm: VMBase) -> None:
|
||||||
@@ -239,7 +244,6 @@ class ClanListView(Gtk.Box):
|
|||||||
model, row = selection.get_selected()
|
model, row = selection.get_selected()
|
||||||
if row is not None:
|
if row is not None:
|
||||||
vm = VMBase(*model[row])
|
vm = VMBase(*model[row])
|
||||||
print(f"Selected {vm.name}")
|
|
||||||
self.on_select_row(vm)
|
self.on_select_row(vm)
|
||||||
|
|
||||||
def _on_double_click(
|
def _on_double_click(
|
||||||
@@ -259,13 +263,18 @@ def setColRenderers(tree_view: Gtk.TreeView) -> None:
|
|||||||
|
|
||||||
if key.startswith("_"):
|
if key.startswith("_"):
|
||||||
continue
|
continue
|
||||||
match gtype:
|
|
||||||
case GdkPixbuf.Pixbuf:
|
if issubclass(gtype, GdkPixbuf.Pixbuf):
|
||||||
renderer = Gtk.CellRendererPixbuf()
|
renderer = Gtk.CellRendererPixbuf()
|
||||||
col = Gtk.TreeViewColumn(key, renderer, pixbuf=idx)
|
col = Gtk.TreeViewColumn(key, renderer, pixbuf=idx)
|
||||||
case str: # noqa
|
elif issubclass(gtype, bool):
|
||||||
renderer = Gtk.CellRendererText()
|
renderer = Gtk.CellRendererToggle()
|
||||||
col = Gtk.TreeViewColumn(key, renderer, text=idx)
|
col = Gtk.TreeViewColumn(key, renderer, active=idx)
|
||||||
|
elif issubclass(gtype, str):
|
||||||
|
renderer = Gtk.CellRendererText()
|
||||||
|
col = Gtk.TreeViewColumn(key, renderer, text=idx)
|
||||||
|
else:
|
||||||
|
raise Exception(f"Unknown type: {gtype}")
|
||||||
|
|
||||||
# CommonSetup for all columns
|
# CommonSetup for all columns
|
||||||
if col:
|
if col:
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ class JoinWindow(Gtk.ApplicationWindow):
|
|||||||
self.notebook = Gtk.Notebook()
|
self.notebook = Gtk.Notebook()
|
||||||
self.stack = Gtk.Stack()
|
self.stack = Gtk.Stack()
|
||||||
|
|
||||||
|
self.stack.add_titled(Gtk.Label("Join cLan"), "join", "Join")
|
||||||
|
|
||||||
vbox.add(self.stack)
|
vbox.add(self.stack)
|
||||||
|
|
||||||
# Must be called AFTER all components were added
|
# Must be called AFTER all components were added
|
||||||
|
|||||||
Reference in New Issue
Block a user