forked from clan/clan-core
Improved Table with feedback from W
This commit is contained in:
parent
c88e9d93a2
commit
a931d73e4f
@ -73,3 +73,4 @@ import the glade file through GTK template
|
||||
- [GTK3 Python] https://github.com/sam-m888/python-gtk3-tutorial/tree/master
|
||||
- https://gnome.pages.gitlab.gnome.org/libhandy/doc/1.8/index.html
|
||||
- https://github.com/geigi/cozy
|
||||
- https://github.com/lutris/lutris/blob/2e9bd115febe08694f5d42dabcf9da36a1065f1d/lutris/gui/widgets/cellrenderers.py#L92
|
@ -3,8 +3,8 @@
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
from collections import OrderedDict
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
@ -15,19 +15,34 @@ from .ui.clan_select_list import ClanSelectPage
|
||||
|
||||
|
||||
class VM:
|
||||
def __init__(self, url: str, autostart: bool, path: Path) -> None:
|
||||
def __init__(self, icon: Path, name: str, 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
|
||||
|
||||
def list_display(self) -> OrderedDict[str, Any]:
|
||||
return OrderedDict({
|
||||
"Icon": str(self.icon),
|
||||
"Name": self.name,
|
||||
"URL": self.url,
|
||||
"Running": self.running,
|
||||
})
|
||||
|
||||
|
||||
assets = Path(__file__).parent / "assets"
|
||||
assert(assets.is_dir())
|
||||
|
||||
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"),
|
||||
VM(assets / "cybernet.jpeg", "Cybernet Clan", "clan://cybernet.lol", "/home/user/w-clan", True),
|
||||
VM(assets / "zenith.jpeg","Zenith Clan", "clan://zenith.lol", "/home/user/lassulus-clan"),
|
||||
VM(assets / "firestorm.jpeg" ,"Firestorm Clan","clan://firestorm.lol", "/home/user/mic-clan"),
|
||||
]
|
||||
vms.extend(vms)
|
||||
#vms.extend(vms)
|
||||
# vms.extend(vms)
|
||||
# vms.extend(vms)
|
||||
|
||||
@ -37,15 +52,16 @@ class ClanJoinPage(Gtk.Box):
|
||||
super().__init__()
|
||||
self.page = Gtk.Box()
|
||||
self.set_border_width(10)
|
||||
self.add(Gtk.Label(label="Add/Join another clan"))
|
||||
self.add(Gtk.Label(label="Join"))
|
||||
|
||||
|
||||
class MainWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self, application: Gtk.Application) -> None:
|
||||
super().__init__(application=application)
|
||||
# Initialize the main window
|
||||
self.set_title("Clan VM Manager")
|
||||
self.set_title("cLAN Manager")
|
||||
self.connect("delete-event", self.on_quit)
|
||||
self.set_default_size(800, 600)
|
||||
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
|
||||
self.add(vbox)
|
||||
@ -56,7 +72,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
vbox.add(self.notebook)
|
||||
|
||||
self.notebook.append_page(ClanSelectPage(vms), Gtk.Label(label="Overview"))
|
||||
self.notebook.append_page(ClanJoinPage(), Gtk.Label(label="Add/Join"))
|
||||
self.notebook.append_page(ClanJoinPage(), Gtk.Label(label="Join"))
|
||||
|
||||
# Must be called AFTER all components were added
|
||||
self.show_all()
|
||||
|
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/cybernet.jpeg
Normal file
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/cybernet.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 104 KiB |
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/firestorm.jpeg
Normal file
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/firestorm.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 155 KiB |
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/penguin.jpeg
Normal file
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/penguin.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 86 KiB |
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/zenith.jpeg
Normal file
BIN
pkgs/clan-vm-manager/clan_vm_manager/assets/zenith.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 152 KiB |
@ -1,12 +1,13 @@
|
||||
from collections.abc import Callable
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gtk, GdkPixbuf
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..app import VM
|
||||
|
||||
|
||||
|
||||
class ClanSelectPage(Gtk.Box):
|
||||
def __init__(self, vms: list["VM"]) -> None:
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||
@ -55,13 +56,13 @@ class ClanSelectButtons(Gtk.Box):
|
||||
orientation=Gtk.Orientation.HORIZONTAL, margin_bottom=10, margin_top=10
|
||||
)
|
||||
|
||||
button = Gtk.Button(label="Start", margin_left=10)
|
||||
button = Gtk.Button(label="Join", margin_left=10)
|
||||
button.connect("clicked", on_start_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Stop", margin_left=10)
|
||||
button = Gtk.Button(label="Leave", margin_left=10)
|
||||
button.connect("clicked", on_stop_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Backup", margin_left=10)
|
||||
button = Gtk.Button(label="Edit", margin_left=10)
|
||||
button.connect("clicked", on_backup_clicked)
|
||||
self.add(button)
|
||||
|
||||
@ -76,35 +77,47 @@ class ClanSelectList(Gtk.Box):
|
||||
super().__init__(expand=True)
|
||||
self.vms = vms
|
||||
|
||||
self.list_store = Gtk.ListStore(str, bool, str)
|
||||
self.list_store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, bool)
|
||||
for vm in vms:
|
||||
items = list(vm.__dict__.values())
|
||||
print(f"Table: {items}")
|
||||
items = list(vm.list_display().values())
|
||||
items[0] = GdkPixbuf.Pixbuf.new_from_file_at_size(items[0], 64, 64)
|
||||
assert(len(items) == 4)
|
||||
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_resizable(True)
|
||||
col.set_expand(True)
|
||||
col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||
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", on_cell_toggled)
|
||||
col = Gtk.TreeViewColumn(key.capitalize(), renderer, active=idx)
|
||||
col.set_resizable(True)
|
||||
col.set_expand(True)
|
||||
col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||
col.set_property("alignment", 0.5)
|
||||
col.set_sort_column_id(idx)
|
||||
self.tree_view.append_column(col)
|
||||
for idx, (key, value) in enumerate(vm.list_display().items()):
|
||||
match key:
|
||||
case "Icon":
|
||||
renderer = Gtk.CellRendererPixbuf()
|
||||
col = Gtk.TreeViewColumn(key, renderer, pixbuf=idx)
|
||||
#col.add_attribute(renderer, "pixbuf", idx)
|
||||
col.set_resizable(True)
|
||||
col.set_expand(True)
|
||||
col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||
col.set_property("alignment", 0.5)
|
||||
col.set_sort_column_id(idx)
|
||||
self.tree_view.append_column(col)
|
||||
case "Name" | "URL":
|
||||
renderer = Gtk.CellRendererText()
|
||||
# renderer.set_property("xalign", 0.5)
|
||||
col = Gtk.TreeViewColumn(key, renderer, text=idx)
|
||||
col.set_resizable(True)
|
||||
col.set_expand(True)
|
||||
col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||
col.set_property("alignment", 0.5)
|
||||
col.set_sort_column_id(idx)
|
||||
self.tree_view.append_column(col)
|
||||
case "Running":
|
||||
renderer = Gtk.CellRendererToggle()
|
||||
renderer.set_property("activatable", True)
|
||||
renderer.connect("toggled", on_cell_toggled)
|
||||
col = Gtk.TreeViewColumn(key, renderer, active=idx)
|
||||
col.set_resizable(True)
|
||||
col.set_expand(True)
|
||||
col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||
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", on_select_row)
|
||||
|
Loading…
Reference in New Issue
Block a user