Improved Table with feedback from W

This commit is contained in:
Qubasa
2023-12-01 13:14:38 +01:00
parent 5a82ff5759
commit d71ecc614b
8 changed files with 70 additions and 40 deletions

View File

@@ -73,3 +73,4 @@ import the glade file through GTK template
- [GTK3 Python] https://github.com/sam-m888/python-gtk3-tutorial/tree/master - [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://gnome.pages.gitlab.gnome.org/libhandy/doc/1.8/index.html
- https://github.com/geigi/cozy - https://github.com/geigi/cozy
- https://github.com/lutris/lutris/blob/2e9bd115febe08694f5d42dabcf9da36a1065f1d/lutris/gui/widgets/cellrenderers.py#L92

View File

@@ -3,8 +3,8 @@
import argparse import argparse
import sys import sys
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any, Dict, Optional
from collections import OrderedDict
import gi import gi
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
@@ -15,19 +15,34 @@ from .ui.clan_select_list import ClanSelectPage
class VM: 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.url = url
self.autostart = autostart self.autostart = autostart
self.running = running
self.name = name
self.path = path 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 = [ vms = [
VM("clan://clan.lol", True, "/home/user/my-clan"), VM(assets / "cybernet.jpeg", "Cybernet Clan", "clan://cybernet.lol", "/home/user/w-clan", True),
VM("clan://lassul.lol", False, "/home/user/my-clan"), VM(assets / "zenith.jpeg","Zenith Clan", "clan://zenith.lol", "/home/user/lassulus-clan"),
VM("clan://mic.lol", False, "/home/user/my-clan"), VM(assets / "firestorm.jpeg" ,"Firestorm Clan","clan://firestorm.lol", "/home/user/mic-clan"),
VM("clan://dan.lol", False, "/home/user/my-clan"),
] ]
vms.extend(vms) #vms.extend(vms)
# vms.extend(vms) # vms.extend(vms)
# vms.extend(vms) # vms.extend(vms)
@@ -37,15 +52,16 @@ class ClanJoinPage(Gtk.Box):
super().__init__() super().__init__()
self.page = Gtk.Box() self.page = Gtk.Box()
self.set_border_width(10) self.set_border_width(10)
self.add(Gtk.Label(label="Add/Join another clan")) self.add(Gtk.Label(label="Join"))
class MainWindow(Gtk.ApplicationWindow): class MainWindow(Gtk.ApplicationWindow):
def __init__(self, application: Gtk.Application) -> None: def __init__(self, application: Gtk.Application) -> None:
super().__init__(application=application) super().__init__(application=application)
# Initialize the main window # Initialize the main window
self.set_title("Clan VM Manager") self.set_title("cLAN Manager")
self.connect("delete-event", self.on_quit) self.connect("delete-event", self.on_quit)
self.set_default_size(800, 600)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
self.add(vbox) self.add(vbox)
@@ -56,7 +72,7 @@ class MainWindow(Gtk.ApplicationWindow):
vbox.add(self.notebook) vbox.add(self.notebook)
self.notebook.append_page(ClanSelectPage(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")) self.notebook.append_page(ClanJoinPage(), Gtk.Label(label="Join"))
# Must be called AFTER all components were added # Must be called AFTER all components were added
self.show_all() self.show_all()

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

View File

@@ -1,12 +1,13 @@
from collections.abc import Callable from collections.abc import Callable
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from gi.repository import Gtk from gi.repository import Gtk, GdkPixbuf
if TYPE_CHECKING: if TYPE_CHECKING:
from ..app import VM from ..app import VM
class ClanSelectPage(Gtk.Box): class ClanSelectPage(Gtk.Box):
def __init__(self, vms: list["VM"]) -> None: def __init__(self, vms: list["VM"]) -> None:
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True) 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 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) button.connect("clicked", on_start_clicked)
self.add(button) 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) button.connect("clicked", on_stop_clicked)
self.add(button) 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) button.connect("clicked", on_backup_clicked)
self.add(button) self.add(button)
@@ -76,35 +77,47 @@ class ClanSelectList(Gtk.Box):
super().__init__(expand=True) super().__init__(expand=True)
self.vms = vms 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: for vm in vms:
items = list(vm.__dict__.values()) items = list(vm.list_display().values())
print(f"Table: {items}") items[0] = GdkPixbuf.Pixbuf.new_from_file_at_size(items[0], 64, 64)
assert(len(items) == 4)
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.__dict__.items()): for idx, (key, value) in enumerate(vm.list_display().items()):
if isinstance(value, str): match key:
renderer = Gtk.CellRendererText() case "Icon":
# renderer.set_property("xalign", 0.5) renderer = Gtk.CellRendererPixbuf()
col = Gtk.TreeViewColumn(key.capitalize(), renderer, text=idx) col = Gtk.TreeViewColumn(key, renderer, pixbuf=idx)
col.set_resizable(True) #col.add_attribute(renderer, "pixbuf", idx)
col.set_expand(True) col.set_resizable(True)
col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE) col.set_expand(True)
col.set_property("alignment", 0.5) col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE)
col.set_sort_column_id(idx) col.set_property("alignment", 0.5)
self.tree_view.append_column(col) col.set_sort_column_id(idx)
if isinstance(value, bool): self.tree_view.append_column(col)
renderer = Gtk.CellRendererToggle() case "Name" | "URL":
renderer.set_property("activatable", True) renderer = Gtk.CellRendererText()
renderer.connect("toggled", on_cell_toggled) # renderer.set_property("xalign", 0.5)
col = Gtk.TreeViewColumn(key.capitalize(), renderer, active=idx) col = Gtk.TreeViewColumn(key, renderer, text=idx)
col.set_resizable(True) col.set_resizable(True)
col.set_expand(True) col.set_expand(True)
col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE) col.set_property("sizing", Gtk.TreeViewColumnSizing.AUTOSIZE)
col.set_property("alignment", 0.5) col.set_property("alignment", 0.5)
col.set_sort_column_id(idx) col.set_sort_column_id(idx)
self.tree_view.append_column(col) 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 = self.tree_view.get_selection()
selection.connect("changed", on_select_row) selection.connect("changed", on_select_row)