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

Update windowing.py to GTK 3.24 #1212

Closed
wants to merge 5 commits into from

Conversation

AesaraB
Copy link
Contributor

@AesaraB AesaraB commented Jan 16, 2024

Part of #1211

Depreciated GDK references:

./windowing.py:222:	self._align = Gtk.Alignment.new(0.5, 0.5, 1.0, 1.0)
./windowing.py:266:	grab_status = device.grab(
./windowing.py:284:	device.ungrab(time_=time)
./windowing.py:291:	screen = event.get_screen()
./windowing.py:292:	mon = screen.get_monitor_at_point(event.x, event.y)
./windowing.py:293:	mon_geom = screen.get_monitor_geometry(mon)
./windowing.py:326:	w = win.get_width()
./windowing.py:327:	h = win.get_height()
./windowing.py:724:	screen = win.get_screen()
./windowing.py:726:	devmgr = display and display.get_device_manager() or None
./windowing.py:727:	ptrdev = devmgr and devmgr.get_client_pointer() or None
./windowing.py:741:	screen_w = screen.get_width()
./windowing.py:742:	screen_h = screen.get_height()
./windowing.py:747:	targ_mon_num = screen.get_monitor_at_point(ptr_x, ptr_y)
./windowing.py:759:	for mon_num in xrange(screen.get_n_monitors()):
./windowing.py:801:	This function operates like gdk_screen_get_monitor_geometry(), but
./windowing.py:812:	geom = screen.get_monitor_geometry(mon_num)
./windowing.py:817:	"gdk_screen_get_monitor_geometry() returned NULL: "
./windowing.py:820:	geom = Rect(0, 0, screen.get_width(), screen.get_height())

I haven't checked GTK API references, though.

@AesaraB
Copy link
Contributor Author

AesaraB commented Jan 17, 2024

#1161 Replaced Gdk.Device.grab() (deprecated) with Gdk.Seat.grab().

New problem is line 238, inside = (x <= event.x_root < x+w) and (y <= event.y_root < y+h) only seems to report False.

@odysseywestra odysseywestra marked this pull request as ready for review January 17, 2024 05:07
@AesaraB AesaraB added this to the GTK4 milestone Jan 17, 2024
@AesaraB AesaraB marked this pull request as draft January 17, 2024 08:44
@AesaraB AesaraB linked an issue Jan 17, 2024 that may be closed by this pull request
3 tasks
@odysseywestra odysseywestra changed the base branch from master to feature-gtk_3.24 January 18, 2024 04:29
@AesaraB AesaraB modified the milestones: v2.0.4, v3.0.0 Jan 18, 2024
@odysseywestra
Copy link
Member

Okay, do you want me to merge this PR into gtk-4.0 branch?

@AesaraB
Copy link
Contributor Author

AesaraB commented Feb 6, 2024

This is still a draft. It partially fixes the relevant issues, but I'd like to focus on other issues (new directory structure, upgrading build system, upgrading unit tests) before merging this one in, as those issues will help me better understand the project as a whole.

The lack of this fix breaks MyPaint on Wayland compositors, so it is important to finish this draft before v2.1.0

@jtojnar
Copy link
Contributor

jtojnar commented Feb 6, 2024

Okay, do you want me to merge this PR into gtk-4.0 branch?

In other projects that were migrated to GTK 4, we often incrementally update the deprecations for minor GTK version upgrades in small, self-contained, easy-to-review PRs and target them directly to the development branch once they are ready. As they are self-contained, they should not affect the functionality of the rest of the app (at most we will need to bump minimal GTK version, which should be fine for development branch) so this will reduce divergence between GTK 4 branch and develoment branch, making it in turn easier to review and rebase onto master.

@AesaraB
Copy link
Contributor Author

AesaraB commented Feb 6, 2024

@jtojnar I will ask, thanks to PyGI's (and Python's) fun way of calling methods I have trouble finding all the depreciated calls to begin with (this is why I was considering going straight into gtk4 and patching warnings and errors as they appear in the interpreter). Do you know of a way to find them quickly?

@jtojnar
Copy link
Contributor

jtojnar commented Feb 6, 2024

Yeah, this is much easier with compiled languages. Here we can only see the deprecations through at runtime.

But you should not need to switch to GTK 4, you should be able to enable the deprecation warnings (silenced by default) with the following patch:

--- a/mypaint.py
+++ b/mypaint.py
@@ -26,6 +26,9 @@ import os.path
 from os.path import join, isdir, dirname, abspath
 import re
 import logging
+import warnings
+import gi
+warnings.simplefilter('default', gi.PyGIDeprecationWarning)
 
 logger = logging.getLogger('mypaint')
 if sys.version_info >= (3,):

There are also some deprecations which need to be enabled with G_ENABLE_DIAGNOSTIC=1 as per the migration guide.

(Though for some reason I am not getting all the warnings I would expect. Edit: asked on pygobject chat.)


There was a feature request for mypy to find deprecations using static analysis but it fizzled out due to a lack of standard deprecation markings. Looks like those has been accepted since in PEP-0702 but it will take time until they are recognized by tooling. And since we do not do static analysis currently, we would need to start first. Also since the bindings are generated at runtime, we would need to employ pygobject/pygobject-stubs#165.

@jtojnar
Copy link
Contributor

jtojnar commented Feb 6, 2024

Quoting Neui from the GNOME Python chat:

Use Python Development mode which shows DeprecationWarning globally (default is to hide them except __main__). PyGObject uses the Python DeprecationWarning for deprecated library stuff instead of the PyGObject-specific PyGIDeprecationWarning used by PyGObject specific overrides and stuff (it seems, from reading the code). This is what it looks like with Gtk.Alignment.new for example:

test-deprecation.py:7: DeprecationWarning: Gtk.Alignment.new is deprecated
  alignment = Gtk.Alignment.new(1, 1, 1, 1)

@AesaraB
Copy link
Contributor Author

AesaraB commented Feb 6, 2024

@jtojnar Could you copy your previous messages to #1211? It's really good information to have on hand, but the scope of this draft is just to update windowing.py (or more realistically, fix it just enough to get wayland compositors working for popup windows)

@AesaraB
Copy link
Contributor Author

AesaraB commented Feb 6, 2024

wait, I have fingers don't I? I'll do it

@AesaraB AesaraB mentioned this pull request Feb 6, 2024
3 tasks
@AesaraB AesaraB deleted the branch mypaint:feature-gtk-4.0 February 21, 2024 10:58
@AesaraB AesaraB closed this Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

GTK: Migrate to GTK4
3 participants