feat: shrink to fit WIP

This commit is contained in:
aclist 2026-01-15 00:49:12 +09:00
parent 2ef51698bd
commit e49f452ba5
3 changed files with 55 additions and 26 deletions

View File

@ -398,13 +398,20 @@ class Grid(Gtk.Grid):
self.breadcrumbs = Gtk.Label(halign=Gtk.Align.START)
self.set_breadcrumbs(strings.label_main_menu)
self.bu = Gtk.Button(label="Shrink to fit", halign=Gtk.Align.END)
self.crumb_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.crumb_box.add(self.breadcrumbs)
self.crumb_box.add(self.bu)
self.bu.connect("clicked", self._shrink)
self.notebook = Notebook()
self.conpan = ConnectPanel(MainController)
self.attach(self.notebook, 0, 0, MAX_COLS, SINGLE_ROW)
els = (
(self.breadcrumbs, self.notebook, Gtk.PositionType.TOP, MAX_COLS, SINGLE_ROW),
(self.crumb_box, self.notebook, Gtk.PositionType.TOP, MAX_COLS, SINGLE_ROW),
(self.conpan, self.notebook, Gtk.PositionType.BOTTOM, MAX_COLS, SINGLE_ROW),
(self.statusbar, self.conpan, Gtk.PositionType.BOTTOM, MAX_COLS, SINGLE_ROW),
(self.right_panel, self.notebook, Gtk.PositionType.RIGHT, SINGLE_COL, MAX_ROWS),
@ -414,6 +421,10 @@ class Grid(Gtk.Grid):
self.show_all()
def _shrink(self, button: Gtk.Button) -> None:
tv = MainController.get_active_treeview()
tv.shrink_to_fit()
def toggle_filter_panel(self, state: bool) -> None:
self.right_panel.filters_vbox.set_visible(state)

View File

@ -31,15 +31,13 @@ class ServerNotebook(Gtk.ScrolledWindow):
self.browser.set_query_func(self.query_test2)
self.lan.set_query_func(self.query_test)
# TODO: set context menu on init
# TODO: set context menu on init of ServerTreeView?
self.browser.set_context_menu(ContextMenuGroup.SERVER_BROWSER)
self.saved.set_context_menu(ContextMenuGroup.SAVED)
self.recent.set_context_menu(ContextMenuGroup.RECENT)
self.lan.set_context_menu(ContextMenuGroup.SCAN_LAN)
# TODO: set model manager for each tab on init
# TODO: add set_ and get_model_manager() methods
tabs = [
(self.browser, server_labels.browser, self.controller.get_server_store),
(self.saved, server_labels.saved, self.controller.get_saved_store),
@ -53,24 +51,9 @@ class ServerNotebook(Gtk.ScrolledWindow):
pass
else:
pass
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#store.append(["BAR", "a", "a", "a", 0, 0, 0, "189.127.165.207:2302", 0, 0, "a", False])
#tree.loaded = True
# TODO: set model on init of servertreeview
# TODO: set model manager for each tab on init
# TODO: add set_ and get_model_manager() methods
tree.set_model(store)
scrolled = Gtk.ScrolledWindow()
@ -83,6 +66,8 @@ class ServerNotebook(Gtk.ScrolledWindow):
self.connect("map", self._on_map)
self.connect("unmap", self._on_unmap)
self.set_crumbs("Server browser")
def _on_map(self, widget: Self) -> None:
self.controller.toggle_server_panels(True)
@ -100,21 +85,24 @@ class ServerNotebook(Gtk.ScrolledWindow):
return
self.get_active_treeview().grab_focus()
def set_crumbs(self, text: str) -> None:
string = f"Servers > {text}"
self.controller.set_crumbs(string)
self.set_cached_label(string)
def _on_page_changed(self, notebook: Gtk.Notebook, child: Gtk.Widget, index: int) -> None:
if self.controller.loaded is False:
return
# TODO: abstract
label = self.notebook.get_tab_label_text(child)
if label is None:
return
# TODO: strings
text = label.strip("*")
self.notebook.set_tab_label_text(child, text)
# TODO: strings
string = f"Servers > {text}"
self.controller.set_crumbs(string)
self.set_cached_label(string)
self.set_crumbs(text)
self.controller.present_servers()
self.controller.populate_model()

View File

@ -88,6 +88,14 @@ class ServerTreeView(TreeView):
column.set_fixed_width(800)
if column_title == "Map":
column.set_fixed_width(300)
# TODO: standardize widths based on column title and longest content
# TODO: resize col width func causes snapping behavior
if column_title == "Name":
column.set_fixed_width(500)
if column_title == "Map":
column.set_fixed_width(200)
if column_title == "IP":
column.set_fixed_width(240)
column.connect("notify::fixed-width", self._on_col_width_changed)
self.append_column(column)
@ -104,6 +112,28 @@ class ServerTreeView(TreeView):
GLib.timeout_add(QUEUE_CHECK_DELAY, self._check_result_queue)
def shrink_to_fit(self) -> None:
cols = self.get_columns()
# TODO: run on only one treeview and propagate results
# TODO: does not shrink name, map, ip fields to fit
# TODO: col width changed signal is buggy on current treeview
for col in cols:
title = col.get_title()
if title == "Name":
continue
if title == "Map":
continue
if title == "IP":
continue
label = Gtk.Label(title)
pango = label.get_layout()
size = pango.get_pixel_size()
if size.width > 50:
width = size.width * 1.30
else:
width = size.width * 1.65
col.set_fixed_width(width)
def _on_kb_focus(self, a, b) -> None:
self.emit("on_distcalc_started")