EventController in python gtk4

Hi all! I have run into the following bug in pygobjet (gtk4): EventController.get_current_event(). For me it does not produce SEGFAULT anymore, but instead raises an error TypeError: No means to translate argument or return value for 'GdkScrollEvent' (see MR180). My question is: is there any way around this problem? I.e. can I still get somehow the current event (actually I only need its position)?

What I try to achieve: I want to build a pdf viewer, and I want my widget (that will eventually be inside a scrolled window) to zoom on CTRL+scroll. That works just fine using EventControllerScroll, but I also want the zoom to be centered around the mouse, and thus I need to retrieve the position where the scroll happened.

Not really: pygobject does not support typed instances that aren’t GObject or GParamSpec.

You could use an EventMotionController to store the position of the pointer when it moves, and then scroll using those coordinates.

Thanks a lot! This solution sounds pretty good. I am a bit worried, however, that I will run into another similar issue with python. Would you recommend changing the language or do you think python will work well? The alternative for me, I think, would be vala (gnome-latex is written in vala, so I could re-use part of the code base. Also, vala seems rather easy to learn, rust and C are too scary).

The only two types in GTK that are typed instances but not GObject are GdkEvent and GskRenderNode. You can mostly avoid having to deal with either of them in a regular application, but you might encounter cases in which you will need to access an event or store a render node for caching complex drawing. In those cases, pygobject will have issues.

GJS (JavaScript) supports typed instances, so you can use JavaScript, if you want to stay on a dynamically typed language. On the compiled, statically typed side, the choices are Vala, Rust, and C. Rust is not at all scary, and there are lots of applications using GTK4 and libadwaita, these days; Vala is also an option, if you already have an existing code base you can study.

Thanks! I will keep experimenting then with python for now and in parallel play around with the other languages to see what is the best fit.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.