Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK DetailedList bug fix #1924

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1924.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug causing detailedlist to not show when put in a box without a specified width on GTK
18 changes: 16 additions & 2 deletions gtk/src/toga_gtk/widgets/detailedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def create(self):

self.scrolled_window = Gtk.ScrolledWindow()

self.scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.scrolled_window.set_policy(
Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC
)
self.scrolled_window.set_min_content_width(self.interface._MIN_WIDTH)
self.scrolled_window.set_min_content_height(self.interface._MIN_HEIGHT)

Expand All @@ -43,7 +45,7 @@ def create(self):
self.scroll_button.set_scroll(lambda: self.scroll_to_row(-1))

self.native = Gtk.Overlay()
self.native.add_overlay(self.scrolled_window)
self.native.add(self.scrolled_window)

self.refresh_button.overlay_over(self.native)
self.scroll_button.overlay_over(self.native)
Expand All @@ -57,6 +59,8 @@ def create(self):
self.right_click_gesture.set_propagation_phase(Gtk.PropagationPhase.BUBBLE)
self.right_click_gesture.connect("pressed", self.gtk_on_right_click)

# print(self.scrolled_window.get_children()[0].get_children()[0].get_children())

def row_factory(self, item):
"""
Args:
Expand Down Expand Up @@ -210,6 +214,16 @@ def _list_items_changed(self):
If either of those things changes the buttons need to be notified to recalculate
their positions.
"""
self._update_scrolled_window_width()
self.refresh_button.list_changed()
self.scroll_button.list_changed()
return True

def _update_scrolled_window_width(self):
# Checks if the widest child of the list_box is wider than the min_width.
# If so, changes the width of the interface.
new_width = self.interface._MIN_WIDTH
for child in self.list_box.get_children():
if child.get_preferred_width().natural_width > new_width:
new_width = child.get_preferred_width().natural_width
self.interface.intrinsic.width = new_width