I am experiencing a strange phenomenon with the Gtk.FileChooserDialogue
widget (Gtk3).
I can't get it to appear at the correct height. Output state height is 500px but its height is definitely much larger. Screen height is 1080px. This widget is almost reaching to the bottom of screen.
When manually resizing it with the mouse pointer, it uncontrollably shrunk to a very small size, get stuck to the top of the screen and I think it is just showing one of its child widget instead of the entire widget.
These issues are shown below. What am I doing wrong and how to fix them?
Running on Ubuntu 24.04.3. GNOME shell version is 46.
Video of Issues:
Sample Code:
import sys
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gtk # noqa: E402
class Chooser(Gtk.FileChooserDialog):
def __init__(self, title=None, parent=None):
super().__init__(
title=title,
parent=parent,
action=Gtk.FileChooserAction.OPEN,
default_height=500, # I tried initializing its height to 500px
)
self.set_default_size(-1, 500) # I tried setting automatic height to 500px
self.set_size_request(-1, 300) # I tried setting minimum height to 300px
self.add_buttons(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN,
Gtk.ResponseType.OK,
)
print(f"{self.props.resizable=}")
print(f"{self.props.resize_mode=}")
print(f"{self.props.default_height=}")
self.add_filters()
self.run_self()
def add_filters(self):
filter_txt = Gtk.FileFilter()
filter_txt.set_name(".txt files")
filter_txt.add_mime_type("text")
self.add_filter(filter_txt)
def run_self(self):
response = self.run()
self.destroy()
class App(Gtk.Application):
def __init__(self):
super().__init__(application_id="com.gnome.test")
GLib.set_application_name("test")
def do_activate(self):
self.window = Gtk.ApplicationWindow(application=self, title="App")
# Create a grid container
self.grid = Gtk.Grid()
self.window.add(self.grid)
# Create Buttons
self.btn = Gtk.Button(label="From")
# Display buttons
self.grid.attach(self.btn, 0, 0, 1, 1)
self.grid.set_row_homogeneous(True)
self.grid.set_column_homogeneous(True)
# Connect Button to handler
self.btn.connect("clicked", self.get_file)
# Set Size
self.window.set_default_size(width=500, height=34)
# Show all widgets
self.window.show_all()
def get_file(self, widget):
print("Chooser")
chooser = Chooser(title="Chooser", parent=self.window)
chooser.set_default_size(-1, 400)
app = App()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
VS Code Output:
Chooser
self.props.resizable=True
self.props.resize_mode=<enum GTK_RESIZE_QUEUE of type Gtk.ResizeMode>
self.props.default_height=500
GTK Info:
$ dpkg -l | grep GTK
ii apport-gtk 2.28.1-0ubuntu3.8 all GTK+ frontend for the apport crash report system
ii gir1.2-gnomebg-4.0:amd64 44.0-5build2 amd64 Introspection data for GnomeBG (GTK 4)
ii gir1.2-gnomedesktop-3.0:amd64 44.0-5build2 amd64 Introspection data for GnomeDesktop (GTK 3)
ii gir1.2-gnomedesktop-4.0:amd64 44.0-5build2 amd64 Introspection data for GnomeDesktop (GTK 4)
ii gir1.2-gtk-3.0:amd64 3.24.41-4ubuntu1.3 amd64 GTK graphical user interface library -- gir bindings
ii gir1.2-gtk-4.0:amd64 4.14.5+ds-0ubuntu0.4 amd64 GTK graphical user interface library -- gir bindings
ii gir1.2-gtksource-5:amd64 5.12.0-1build1 amd64 gir files for the GTK+ syntax highlighting widget
ii gir1.2-javascriptcoregtk-4.1:amd64 2.48.5-0ubuntu0.24.04.1 amd64 JavaScript engine library from WebKitGTK - GObject introspection data
ii gir1.2-javascriptcoregtk-6.0:amd64 2.48.5-0ubuntu0.24.04.1 amd64 JavaScript engine library from WebKitGTK - GObject introspection data
ii gir1.2-webkit-6.0:amd64 2.48.5-0ubuntu0.24.04.1 amd64 Web content engine library for GTK - GObject introspection data
ii gir1.2-webkit2-4.1:amd64 2.48.5-0ubuntu0.24.04.1 amd64 Web content engine library for GTK - GObject introspection data
ii gnome-accessibility-themes 3.28-2ubuntu5 all High Contrast GTK 2 theme and icons
ii gnome-themes-extra:amd64 3.28-2ubuntu5 amd64 Adwaita GTK 2 theme — engine
ii gnome-themes-extra-data 3.28-2ubuntu5 all Adwaita GTK 2 theme and Adwaita-dark GTK 3 theme — common files
ii gstreamer1.0-gtk3:amd64 1.24.2-1ubuntu1.1 amd64 GStreamer plugin for GTK+3
ii gtk2-engines-pixbuf:amd64 2.24.33-4ubuntu1.1 amd64 pixbuf-based theme for GTK 2
ii ibus-gtk:amd64 1.5.29-2 amd64 Intelligent Input Bus - GTK2 support
ii ibus-gtk3:amd64 1.5.29-2 amd64 Intelligent Input Bus - GTK3 support
ii ibus-gtk4:amd64 1.5.29-2 amd64 Intelligent Input Bus - GTK4 support
ii libadwaita-1-0:amd64 1.5.0-1ubuntu2 amd64 Library with GTK widgets for mobile phones
ii libavahi-ui-gtk3-0:amd64 0.8-13ubuntu6 amd64 Avahi GTK+ User interface library for GTK3
ii libayatana-appindicator3-1 0.5.93-1build3 amd64 Ayatana Application Indicators (GTK-3+ version)
ii libayatana-indicator3-7:amd64 0.9.4-1build1 amd64 panel indicator applet - shared library (GTK-3+ variant)
ii libcanberra-gtk-module:amd64 0.30-10ubuntu10 amd64 translates GTK+ widgets signals to event sounds
ii libcanberra-gtk0:amd64 0.30-10ubuntu10 amd64 GTK+ helper for playing widget event sounds with libcanberra
ii libcanberra-gtk3-0t64:amd64 0.30-10ubuntu10 amd64 GTK+ 3.0 helper for playing widget event sounds with libcanberra
ii libcanberra-gtk3-module:amd64 0.30-10ubuntu10 amd64 translates GTK3 widgets signals to event sounds
ii libcolord-gtk4-1t64:amd64 0.3.1-1build2 amd64 GTK4 convenience library for interacting with colord
ii libdbusmenu-gtk3-4:amd64 18.10.20180917~bzr492+repack1-3.1ubuntu5 amd64 library for passing menus over DBus - GTK-3+ version
ii libdecor-0-plugin-1-gtk:amd64 0.2.2-1build2 amd64 libdecor decoration plugin using GTK
ii libedataserverui4-1.0-0t64:amd64 3.52.3-0ubuntu1 amd64 GTK4 utility library for evolution data servers
ii libgnome-desktop-3-20t64:amd64 44.0-5build2 amd64 Utility library for the GNOME desktop - GTK 3 version
ii libgspell-1-2:amd64 1.12.2-1build4 amd64 spell-checking library for GTK+ applications
ii libgtk-3-0t64:amd64 3.24.41-4ubuntu1.3 amd64 GTK graphical user interface library
ii libgtk-3-bin 3.24.41-4ubuntu1.3 amd64 programs for the GTK graphical user interface library
ii libgtk-3-common 3.24.41-4ubuntu1.3 all common files for the GTK graphical user interface library
ii libgtk-4-1:amd64 4.14.5+ds-0ubuntu0.4 amd64 GTK graphical user interface library
ii libgtk-4-bin 4.14.5+ds-0ubuntu0.4 amd64 programs for the GTK graphical user interface library
ii libgtk-4-common 4.14.5+ds-0ubuntu0.4 all common files for the GTK graphical user interface library
ii libgtk-4-dev:amd64 4.14.5+ds-0ubuntu0.4 amd64 development files for the GTK library
ii libgtk-4-media-gstreamer 4.14.5+ds-0ubuntu0.4 amd64 GStreamer media backend for the GTK graphical user interface library
ii libgtk2.0-0t64:amd64 2.24.33-4ubuntu1.1 amd64 GTK graphical user interface library - old version
ii libgtk2.0-bin 2.24.33-4ubuntu1.1 amd64 programs for the GTK graphical user interface library
ii libgtk2.0-common 2.24.33-4ubuntu1.1 all common files for the GTK graphical user interface library
ii libgtk3-perl 0.038-3 all Perl bindings for the GTK+ graphical user interface library
ii libgtkmm-4.0-0:amd64 4.10.0-4build3 amd64 C++ wrappers for GTK4 (shared libraries)
ii libgtkmm-4.0-dev:amd64 4.10.0-4build3 amd64 C++ wrappers for GTK4 (development files)
ii libgtksourceview-5-0:amd64 5.12.0-1build1 amd64 shared libraries for the GTK 4 syntax highlighting widget
ii libgtksourceview-5-common 5.12.0-1build1 all common files for the GTK 4 syntax highlighting widget
ii libhandy-1-0:amd64 1.8.3-1build2 amd64 Library with GTK widgets for mobile phones
ii libjavascriptcoregtk-4.1-0:amd64 2.48.5-0ubuntu0.24.04.1 amd64 JavaScript engine library from WebKitGTK
ii libjavascriptcoregtk-6.0-1:amd64 2.48.5-0ubuntu0.24.04.1 amd64 JavaScript engine library from WebKitGTK
ii libnma-gtk4-0:amd64 1.10.6-3build2 amd64 NetworkManager GUI GTK4 library
ii libpanel-1-1:amd64 1.6.0-1build1 amd64 IDE paneling library for GTK
ii libpanel-common 1.6.0-1build1 all IDE paneling library for GTK - common files
ii libportal-gtk3-1:amd64 0.7.1-5build5 amd64 Flatpak portal library for GTK 3 GUIs
ii libportal-gtk4-1:amd64 0.7.1-5build5 amd64 Flatpak portal library for GTK 4 GUIs
ii libreoffice-gtk3 4:24.2.7-0ubuntu0.24.04.4 amd64 office productivity suite -- GTK+ 3 integration
ii libtext-engine-0.1-0 0.1.1-4build2 amd64 Rich-text editing framework for GTK 4
ii libvte-2.91-0:amd64 0.76.0-1ubuntu0.1 amd64 Terminal emulator widget for GTK+ 3.0 - runtime files
ii libvte-2.91-common 0.76.0-1ubuntu0.1 amd64 Terminal emulator widget for GTK+ 3.0 - common files
ii libvte-2.91-gtk4-0:amd64 0.76.0-1ubuntu0.1 amd64 Terminal emulator widget for GTK 4 - runtime files
ii libwebkit2gtk-4.1-0:amd64 2.48.5-0ubuntu0.24.04.1 amd64 Web content engine library for GTK
ii libwebkitgtk-6.0-4:amd64 2.48.5-0ubuntu0.24.04.1 amd64 Web content engine library for GTK
ii libwmf-0.2-7-gtk:amd64 0.2.13-1.1build3 amd64 Windows metafile conversion GTK pixbuf plugin
ii libwmf0.2-7-gtk:amd64 0.2.13-1.1build3 amd64 Windows metafile conversion GTK pixbuf plugin - transitional package
ii libwxgtk3.2-1t64:amd64 3.2.4+dfsg-4build1 amd64 wxWidgets Cross-platform C++ GUI toolkit (GTK 3 runtime)
ii python3-aptdaemon.gtk3widgets 1.1.1+bzr982-0ubuntu44 all Python 3 GTK+ 3 widgets to run an aptdaemon client
ii qt5-gtk-platformtheme:amd64 5.15.13+dfsg-1ubuntu1 amd64 Qt 5 GTK+ 3 platform theme
ii qt6-gtk-platformtheme:amd64 6.4.2+dfsg-21.1build5 amd64 Qt 6 GTK+ 3 platform theme
ii remmina 1.4.35+dfsg-0ubuntu5.1 amd64 GTK+ Remote Desktop Client
ii transmission-gtk 4.0.5-1build5 amd64 lightweight BitTorrent client (GTK+ interface)
ii xdg-desktop-portal-gtk 1.15.1-1build2 amd64 GTK+/GNOME portal backend for xdg-desktop-portal
ii yaru-theme-gtk 24.04.2-0ubuntu1 all Yaru GTK theme from the Ubuntu Community
On Linux Mint (based on Ubuntu 24.04) it remebers old size
and function run()
uses it to change size.
I can get expected size when I set set_resizable(False)
but later I can't resize it manually so it is not so good solution.
I found that I can set size later assigning function to show
def on_show(self, *_):
self.resize(800, 500)
def __init__(self, title=None, parent=None):
# ... code ...
self.connect("show", self.on_show)
Later I found that this works for me only when I set both values.
When I use -1
then it doesn't work. resize(-1, 500)
.
I didn't check if -1
makes problem in other functions.