mirror of
https://github.com/aclist/dztui.git
synced 2026-10-25 12:12:31 +01:00
feat: add SimpleTree
This commit is contained in:
1 parent
d9d3f747bb
commit
67c19fb90d
1 file changed
+35
@@ -0,0 +1,35 @@
|
|||||||
|
from typing import TYPE_CHECKING, Union
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from dzgui.model.model_factory import FastInsertListStore
|
||||||
|
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
from gi.repository import Gtk # noqa
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleTree(Gtk.ScrolledWindow):
|
||||||
|
"""Simple scrollable 1-column tree"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, model: Union[Gtk.ListStore, "FastInsertListStore"], title: str
|
||||||
|
) -> None:
|
||||||
|
super().__init__(
|
||||||
|
overlay_scrolling=False,
|
||||||
|
propagate_natural_width=True,
|
||||||
|
propagate_natural_height=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.tree = Gtk.TreeView(model=model, enable_search=False)
|
||||||
|
renderer = Gtk.CellRendererText()
|
||||||
|
column = Gtk.TreeViewColumn(title, renderer, text=0)
|
||||||
|
column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
|
||||||
|
column.set_resizable(False)
|
||||||
|
column.set_sort_column_id(0)
|
||||||
|
self.tree.append_column(column)
|
||||||
|
|
||||||
|
self.add(self.tree)
|
||||||
|
|
||||||
|
def get_tree(self) -> Gtk.TreeView:
|
||||||
|
return self.tree
|
||||||
Reference in new issue
Block a user