Made TreeView resizable
This commit is contained in:
parent
2fa124f274
commit
9c20c5b25b
@ -5,7 +5,7 @@ class ClanSelectPage(Gtk.Box):
|
||||
def __init__(self, vms):
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||
|
||||
self.add(ClanSelectList(vms))
|
||||
self.add(ClanSelectList(vms, self.on_cell_toggled, self.on_select_row))
|
||||
self.add(
|
||||
ClanSelectButtons(
|
||||
self.on_start_clicked, self.on_stop_clicked, self.on_backup_clicked
|
||||
@ -22,56 +22,6 @@ class ClanSelectPage(Gtk.Box):
|
||||
print("Backup clicked")
|
||||
|
||||
|
||||
class ClanSelectButtons(Gtk.Box):
|
||||
def __init__(self, on_start_clicked, on_stop_clicked, on_backup_clicked):
|
||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
button = Gtk.Button(label="Start", margin_left=10)
|
||||
button.connect("clicked", on_start_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Stop", margin_left=10)
|
||||
button.connect("clicked", on_stop_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Backup", margin_left=10)
|
||||
button.connect("clicked", on_backup_clicked)
|
||||
self.add(button)
|
||||
|
||||
|
||||
class ClanSelectList(Gtk.Box):
|
||||
def __init__(self, vms):
|
||||
super().__init__(expand=True)
|
||||
self.vms = vms
|
||||
|
||||
self.list_store = Gtk.ListStore(str, bool, str)
|
||||
for vm in vms:
|
||||
items = list(vm.__dict__.values())
|
||||
print(f"Table: {items}")
|
||||
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_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", self.on_cell_toggled)
|
||||
col = Gtk.TreeViewColumn(key.capitalize(), renderer, active=idx)
|
||||
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", self.on_select_row)
|
||||
|
||||
self.set_border_width(10)
|
||||
self.add(self.tree_view)
|
||||
|
||||
def on_cell_toggled(self, widget, path):
|
||||
print(f"on_cell_toggled: {path}")
|
||||
# Get the current value from the model
|
||||
@ -87,3 +37,60 @@ class ClanSelectList(Gtk.Box):
|
||||
model, row = selection.get_selected()
|
||||
if row is not None:
|
||||
print(f"Selected {model[row][0]}")
|
||||
|
||||
class ClanSelectButtons(Gtk.Box):
|
||||
def __init__(self, on_start_clicked, on_stop_clicked, on_backup_clicked):
|
||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL, margin_bottom=10, margin_top=10)
|
||||
|
||||
button = Gtk.Button(label="Start", margin_left=10)
|
||||
button.connect("clicked", on_start_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Stop", margin_left=10)
|
||||
button.connect("clicked", on_stop_clicked)
|
||||
self.add(button)
|
||||
button = Gtk.Button(label="Backup", margin_left=10)
|
||||
button.connect("clicked", on_backup_clicked)
|
||||
self.add(button)
|
||||
|
||||
|
||||
class ClanSelectList(Gtk.Box):
|
||||
def __init__(self, vms, on_cell_toggled, on_select_row):
|
||||
super().__init__(expand=True)
|
||||
self.vms = vms
|
||||
|
||||
self.list_store = Gtk.ListStore(str, bool, str)
|
||||
for vm in vms:
|
||||
items = list(vm.__dict__.values())
|
||||
print(f"Table: {items}")
|
||||
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)
|
||||
|
||||
selection = self.tree_view.get_selection()
|
||||
selection.connect("changed", on_select_row)
|
||||
|
||||
self.set_border_width(10)
|
||||
self.add(self.tree_view)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user