forked from clan/clan-core
clan-vm-manager: Fixed assets folder not included
This commit is contained in:
parent
82fb1c36fe
commit
d7b1a9f959
@ -35,8 +35,9 @@ def list_history() -> list[HistoryEntry]:
|
||||
content: str = f.read()
|
||||
parsed: list[dict] = json.loads(content)
|
||||
logs = [HistoryEntry(**p) for p in parsed]
|
||||
except json.JSONDecodeError:
|
||||
print("Failed to load history")
|
||||
except json.JSONDecodeError as ex:
|
||||
print("Failed to load history. Invalid JSON.")
|
||||
print(f"{user_history_file()}: {ex}")
|
||||
|
||||
return logs
|
||||
|
||||
|
@ -75,7 +75,9 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
|
||||
def set_selected(self, sel: VMBase | None) -> None:
|
||||
self.selected_vm = sel
|
||||
print(f"APP selected + {self.selected_vm}")
|
||||
|
||||
if self.selected_vm:
|
||||
print(f"APP selected + {self.selected_vm.name}")
|
||||
|
||||
def remount_list_view(self) -> None:
|
||||
widget = self.stack.get_child_by_name("list")
|
||||
@ -135,5 +137,6 @@ class Application(Gtk.Application):
|
||||
|
||||
|
||||
def start_app(args: argparse.Namespace) -> None:
|
||||
print(sys.argv)
|
||||
app = Application()
|
||||
return app.run(sys.argv)
|
||||
|
@ -5,6 +5,8 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import clan_cli
|
||||
import gi
|
||||
gi.require_version("GdkPixbuf", "2.0")
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
from clan_vm_manager import assets
|
||||
@ -40,6 +42,10 @@ class VMBase:
|
||||
}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_idx(name: str) -> int:
|
||||
return list(VMBase.name_to_type_map().keys()).index(name)
|
||||
|
||||
def list_data(self) -> OrderedDict[str, Any]:
|
||||
return OrderedDict(
|
||||
{
|
||||
|
@ -133,7 +133,7 @@ class ClanList(Gtk.Box):
|
||||
self.remount_edit_view()
|
||||
|
||||
def on_select_vm(self, vm: VMBase) -> None:
|
||||
print(f"on_select_vm: {vm}")
|
||||
print(f"on_select_vm: {vm.name}")
|
||||
if vm is None:
|
||||
self.toolbar.set_is_selected(False)
|
||||
else:
|
||||
@ -215,7 +215,7 @@ class ClanListView(Gtk.Box):
|
||||
|
||||
def find_vm(self, vm: VMBase) -> int:
|
||||
for idx, row in enumerate(self.list_store):
|
||||
if row[1] == vm.name: # TODO: Change to path
|
||||
if row[VMBase.to_idx("Name")] == vm.name: # TODO: Change to path
|
||||
return idx
|
||||
return -1
|
||||
|
||||
@ -229,16 +229,18 @@ class ClanListView(Gtk.Box):
|
||||
|
||||
def insertVM(self, vm: VMBase) -> None:
|
||||
values = list(vm.list_data().values())
|
||||
values[0] = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename=values[0], width=64, height=64, preserve_aspect_ratio=True
|
||||
icon_idx = VMBase.to_idx("Icon")
|
||||
values[icon_idx] = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename=values[icon_idx], width=64, height=64, preserve_aspect_ratio=True
|
||||
)
|
||||
self.list_store.append(values)
|
||||
|
||||
def _on_select_row(self, selection: Gtk.TreeSelection) -> None:
|
||||
model, row = selection.get_selected()
|
||||
if row is not None:
|
||||
print(f"Selected {model[row][1]}")
|
||||
self.on_select_row(VMBase(*model[row]))
|
||||
vm = VMBase(*model[row])
|
||||
print(f"Selected {vm.name}")
|
||||
self.on_select_row(vm)
|
||||
|
||||
def _on_double_click(
|
||||
self, tree_view: Gtk.TreeView, path: Gtk.TreePath, column: Gtk.TreeViewColumn
|
||||
@ -247,24 +249,24 @@ class ClanListView(Gtk.Box):
|
||||
selection = tree_view.get_selection()
|
||||
model, row = selection.get_selected()
|
||||
if row is not None:
|
||||
VMBase(*model[row]).run()
|
||||
|
||||
vm = VMBase(*model[row])
|
||||
vm.run()
|
||||
|
||||
|
||||
def setColRenderers(tree_view: Gtk.TreeView) -> None:
|
||||
for idx, (key, _) in enumerate(VMBase.name_to_type_map().items()):
|
||||
for idx, (key, gtype) in enumerate(VMBase.name_to_type_map().items()):
|
||||
col: Gtk.TreeViewColumn = None
|
||||
match key:
|
||||
case "Icon":
|
||||
|
||||
if key.startswith("_"):
|
||||
continue
|
||||
match gtype:
|
||||
case GdkPixbuf.Pixbuf:
|
||||
renderer = Gtk.CellRendererPixbuf()
|
||||
col = Gtk.TreeViewColumn(key, renderer, pixbuf=idx)
|
||||
case "Name" | "URL":
|
||||
case str:
|
||||
renderer = Gtk.CellRendererText()
|
||||
col = Gtk.TreeViewColumn(key, renderer, text=idx)
|
||||
case "Status":
|
||||
renderer = Gtk.CellRendererText()
|
||||
col = Gtk.TreeViewColumn(key, renderer, text=idx)
|
||||
case _:
|
||||
continue
|
||||
|
||||
|
||||
# CommonSetup for all columns
|
||||
if col:
|
||||
|
@ -2,13 +2,15 @@
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
|
||||
|
||||
[project]
|
||||
name = "clan-vm-manager"
|
||||
dynamic = ["version"]
|
||||
scripts = { clan-vm-manager = "clan_vm_manager:main" }
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
clan_vm_manager = ["*.glade"]
|
||||
clan_vm_manager = ["**/assets/*"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.11"
|
||||
|
@ -10,6 +10,7 @@ mkShell {
|
||||
shellHook = ''
|
||||
ln -sfT ${clan-cli.nixpkgs} ../clan-cli/clan_cli/nixpkgs
|
||||
|
||||
ln -sf ${clan-vm-manager} ./result
|
||||
# prepend clan-cli for development
|
||||
export PYTHONPATH=../clan-cli:$PYTHONPATH
|
||||
'';
|
||||
|
Loading…
Reference in New Issue
Block a user