0

I am trying to build a virtualized grid container to display 100k+ files in PyGTK 4 on Fedora 35. I succeeded in creating the layout and scrolling support which works beautifully.

In order to support resizing of my application window, I need to react to changes its size. I already connected to the notify signal of the window and handle the default-width, default-height, maximized and unmaximized events to update the geometry of my layout. However, everytime I invoke get_width() of my widget/app window after the maximized event I only get the width before the window was maximized! Is this by design?

I've been trying pretty hard but I fail to come to a working solution for this simple problem. Can anyone help me?

Edit

Here is some code to outline how I am trying to measure the window size. I modified the code to use connect_after instead of connectas proposed by @GüntherWagner. However, the behavior is the same for both methods:

class TestLayout(Gtk.ScrolledWindow):
  def on_realize(self, widget):
    ...
    self.get_root().connect_after('notify', self.on_notify)

  def on_notify(self, widget, param):
     if param.name in [..., 'maximized', 'unmaximized']:
        self.draw()

  def draw(self):
      self.width = self.get_width()
      self.height = self.get_height()
faubulous
  • 1
  • 2
  • It sounds like you need a [tag:threading] timer. – Sylvester Kruin Dec 07 '21 at 21:58
  • I'll try that! I already tried this but I probably used the wrong method.. – faubulous Dec 08 '21 at 08:10
  • @sylvester-kruin It works! Thank you for your help. However, occasionally the application crashes because of a 'parent != null' assertion. That's the kind of race conditions to be expected with using timers since they do not integrate into the GTK update cycle. I played around with the timing and now it seems to be stable. I'd still appreciante if anyone could enlighten me on how this is supposed to be done in GTK4.. – faubulous Dec 08 '21 at 08:47
  • Sorry, I don't know anything about Gtk4; I've never used it before. But I'm sure there's lots of information here and/or elsewhere on the web. – Sylvester Kruin Dec 08 '21 at 21:21
  • Don't worry. You already helped me a lot. Regarding GTK4 there is not a lot of information on the web. Unfortunately the bindings are generated through introspection so there is no code-completion or any other IDE assistance. Most of the available documention is auto-generated from the C documentation. Only a few examples in this [tutorial](https://python-gtk-3-tutorial.readthedocs.io/en/latest/index.html), but only for GTK3 which is considerably different. – faubulous Dec 10 '21 at 08:27
  • I guess that's why I'm still using Gtk3. It has more documentation :-). Maybe I'll switch to Gtk4 when Gtk3 becomes deprecated... Anyway, good luck on your project and happy coding! – Sylvester Kruin Dec 10 '21 at 13:47
  • i think you have to connect the notify signal differently. If you connect_after it will have the new values. Basically how this works is: [notify] -> [default-handler] -> [notify_after] so you tried to access the values before the default-handler updated them. – Günther Wagner Jan 12 '22 at 09:07
  • @GüntherWagner Thank you for the tip! This sounds interesting and I will try it as soon as I find the time. However, I am curious because I cannot find any documentation about it? https://docs.gtk.org/gtk4/?q=connect_after – faubulous Jan 13 '22 at 10:26
  • Just search for g_signal_connect_after - https://docs.gtk.org/gobject/func.signal_connect_after.html – Günther Wagner Jan 14 '22 at 14:20

0 Answers0