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

Gtk4 migration #1978

Draft
wants to merge 131 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
37c0546
Setup the the baiscs of migration
Jun 10, 2023
ac3ae7e
[detailedlist] migrate detailedlist and its dependencies
Jun 11, 2023
4ec985b
[label] migratet label widget
Jun 11, 2023
18b87f8
[divider] migrate divider widget
Jun 11, 2023
10dfb76
[imageview] migrate imageview widget
Jun 11, 2023
839bd45
[basics] fix the style implementation
Jun 11, 2023
ac75996
[multilinetextinput] migrate the multilinetextiput widget
Jun 11, 2023
5c6c92f
[basics] fix the style implementation
Jun 11, 2023
bd24cbf
[error] remove unintended commits
Jun 11, 2023
9e5d27c
[numberinput] migrate the numberinput widget
Jun 11, 2023
1f91dde
[textinput] migrate the textinput widget
Jun 11, 2023
10e5162
[textinput] migrate the textinput widget
Jun 11, 2023
6b06b72
[progressbar] migrate the progressbar widget
Jun 11, 2023
5141fe3
[scrollcontainer] migrate the scrollcontainer widget
Jun 11, 2023
19c564f
[detailedlist] fix minimum width
Jun 11, 2023
afde981
[selection] migrate the selection widget
Jun 11, 2023
680f738
[slider] migrate slider widget
Jun 11, 2023
eb7db21
[detailedlist] some widget access attributes cleaning
Jun 11, 2023
b40c338
[activityindicator] migrate activityindicator widget
Jun 11, 2023
1d3a74e
[splitcontainer] migrate splitcontainer widget
Jun 11, 2023
ede61d6
[switch] migrate switch widget
Jun 11, 2023
3cdce3e
[slider] some tweak cleaning
Jun 11, 2023
471087d
[selection] some tweak cleaning
Jun 11, 2023
82c9c29
[detailedlist] some tweak cleaning
Jun 11, 2023
e9334ff
[scrollcontainer] fix unmigrated method
Jun 12, 2023
9579bc9
[optioncontainer] fix unmigrated details
Jun 12, 2023
742aa86
[pre-commit] Fix flake3 formating
Jun 12, 2023
58b6a08
[towncrier] add changenete
Jun 12, 2023
9d3646b
[pre-commit] Fix import sorting using isort
Jun 12, 2023
2e050db
[pre-commit] Fix black formating
Jun 12, 2023
7886861
[basics] Fix backward compitability of different gtkr versions in app…
Jun 13, 2023
b6d928e
Merge branch 'main' into gtk4-migration
MuhammadMuradG Jul 7, 2023
ba8206b
[pre-commit] Fix black formating
Jul 7, 2023
c546dd4
[selection] Fix item insertion
Jul 7, 2023
fb412dc
[selection] Remove search bar
Jul 7, 2023
651c401
Update ci.yml
MuhammadMuradG Jul 7, 2023
f5a23af
Update ci.yml
MuhammadMuradG Jul 7, 2023
a7743d8
[CI] Add Gtk4 system package
MuhammadMuradG Jul 7, 2023
cac5a34
[GTK backend] Fix texts
Jul 7, 2023
28de4e3
[testbed] Fix display retrieving
Jul 7, 2023
7810109
Update ci.yml
MuhammadMuradG Jul 7, 2023
5d4ca07
Update ci.yml
MuhammadMuradG Jul 7, 2023
7f12030
[CI] Add Gtk4 system package
MuhammadMuradG Jul 7, 2023
bc54771
Merge branch 'gtk4-migration' of https://github.com/MuhammadMouradG/t…
Jul 7, 2023
0797051
[backend test] Fix setting window child
Jul 7, 2023
a4d60a9
[selection] Fix styles
Jul 8, 2023
dd4fcb8
[docstring] Keep docstring consistency through project
Jul 8, 2023
963bd4d
[selection] Fix reduce minimum size
Jul 8, 2023
f575dd3
[testbed] Remove 'shrink_on_rsize' property from selection test
Jul 8, 2023
fba26cf
[testbed] Fix backend redrawing request
Jul 9, 2023
69e4234
Resolve conflicts in splitcontatiner
Aug 5, 2023
80dc33a
Merge branch 'main' into gtk4-migration
MuhammadMuradG Aug 5, 2023
f85b545
[docstring] Keep docstring consistency through project
Aug 6, 2023
ea7f98f
Fix the resolved conflicts in container
Aug 6, 2023
e9305c2
Resolve merging conflicts.
MuhammadMuradG Nov 6, 2023
4c3083e
Fix resolved merged confilicts.
MuhammadMuradG Nov 6, 2023
09983db
Fix unresolved CI confilicts.
MuhammadMuradG Nov 6, 2023
19f0bad
Fix flake8 formating
MuhammadMuradG Nov 6, 2023
c7b7b2b
[Basics] Fix toga container Layout and widgets visiblity.
MuhammadMuradG Nov 9, 2023
88c6ec1
[testbed] Passing base testbed.
MuhammadMuradG Nov 9, 2023
9ad1a70
[Cleanup] Some comments and docstring enhancing.
MuhammadMuradG Nov 9, 2023
a9e4e9a
[testbed] Await time fraction on next iter of the main loop; This is …
MuhammadMuradG Nov 10, 2023
e8dd20f
[basics] Resolve merging conflicts.
MuhammadMuradG Nov 10, 2023
2450f9b
[testbed] Fix box properties tests.
MuhammadMuradG Nov 10, 2023
94323db
[Cleanup] Fix flake8 formating.
MuhammadMuradG Nov 10, 2023
cc6dfab
[testbed] Fix redrawing conditions with some performance.
MuhammadMuradG Nov 17, 2023
35b3e25
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Nov 17, 2023
2d26ac3
[Selection] Replace the using of deprecated method.
MuhammadMuradG Nov 17, 2023
69731a4
[Selection] Fix widget size after change the selected item.
MuhammadMuradG Nov 17, 2023
04ad8b1
[Testbed] Doesn't wait for resources on each iteration.
MuhammadMuradG Nov 17, 2023
028693e
[Widget] Fix focus checking.
MuhammadMuradG Nov 19, 2023
80f45cf
[Testbed] Fix box focus tests.
MuhammadMuradG Nov 19, 2023
50d32a6
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Nov 19, 2023
6062d99
[Testbed] Fix background color reset test.
MuhammadMuradG Nov 19, 2023
0dc1a3f
[Testbed] Handling edge cases in layout tests.
MuhammadMuradG Nov 19, 2023
6b7d7a1
[Testbed] Fix content size and fullscreen tests.
MuhammadMuradG Nov 21, 2023
a8356b5
[Window] Some code cleaning.
MuhammadMuradG Nov 21, 2023
21cdc50
[Widget] Fix focus checking.
MuhammadMuradG Dec 3, 2023
6be6f95
[Testbed] Fix widget focus test.
MuhammadMuradG Dec 3, 2023
b5bc802
[Testbed] Fix app tests.
MuhammadMuradG Dec 4, 2023
4b92256
Resolve merging conflicts.
MuhammadMuradG Dec 4, 2023
18227a8
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Dec 8, 2023
e4c59d9
[Testbed] Fix font attributes tests.
MuhammadMuradG Dec 9, 2023
9480052
[Testbed] Fix font attributes edge cases tests.
MuhammadMuradG Dec 9, 2023
4d53250
[Testbed] Fix icons tests.
MuhammadMuradG Dec 9, 2023
d44de50
Resolve merging conflicts.
MuhammadMuradG Dec 18, 2023
93442ca
[Testbed] Fix platform path icons tests.
MuhammadMuradG Dec 19, 2023
fdeb37e
[Cleanup] Fix black formating.
MuhammadMuradG Dec 19, 2023
9af8cc3
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Dec 20, 2023
99fdb3b
[Testbed] Fix window position tests.
MuhammadMuradG Dec 21, 2023
02dcef5
[Docs] Update notes on window positioning.
MuhammadMuradG Dec 21, 2023
e191ebe
[Docs] Fix typos.
MuhammadMuradG Dec 21, 2023
4820df8
[Cleanup] Fix docs formating.
MuhammadMuradG Dec 21, 2023
a7d8ec1
[Testbed] Fix unintended changes window configs.
MuhammadMuradG Dec 21, 2023
15bbf29
[Docs] Fix word spilling typo.
MuhammadMuradG Dec 21, 2023
375af80
[Docs] Add positioning to spelling wordlist.
MuhammadMuradG Dec 21, 2023
d86a10a
[Docs] Fix the positioning note in window doc.
MuhammadMuradG Dec 21, 2023
a57d881
[Testbed] Fix key tests.
MuhammadMuradG Dec 28, 2023
6a75cb7
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Dec 28, 2023
ffc792b
[Testbed] Fix unintended commit in window config test.
MuhammadMuradG Dec 28, 2023
b27e095
[Dialogs] Migrate dialogs.
MuhammadMuradG Jan 3, 2024
d7e472c
[Testbed] Fix message dialog tests.
MuhammadMuradG Jan 3, 2024
c5d8c1f
[Dialog] Migrate and fix file dialogs.
MuhammadMuradG Jan 3, 2024
712b12e
[Testbed] Fix file dialog tests.
MuhammadMuradG Jan 3, 2024
47646e9
[Widget] Fix memory leaks on window ref.
MuhammadMuradG Jan 3, 2024
d319479
[Cleanup] Fix black formating.
MuhammadMuradG Jan 3, 2024
4ca83be
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Jan 3, 2024
9310555
[Cleanup] Imports cleanup.
MuhammadMuradG Jan 4, 2024
d0d7d7c
[Testbed] Fix window positioning and screenshot tests.
MuhammadMuradG Jan 4, 2024
952b002
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Jan 5, 2024
3fcd351
[Testbed] Passing window image test.
MuhammadMuradG Jan 5, 2024
13f2982
[Testbed] Fix window image test.
MuhammadMuradG Jan 6, 2024
a90541d
[Cleanup] Some comments cleaning.
MuhammadMuradG Jan 6, 2024
b4f31ca
Resolve merging conflicts.
MuhammadMuradG Jan 11, 2024
62ae5e0
[Coverage] Fix window caverage tests.
MuhammadMuradG Jan 17, 2024
2d6e631
[Base] Fix widget size on css changing.
MuhammadMuradG Jan 24, 2024
de38ac4
[Icons] Migrating the used extensible icon sizes.
MuhammadMuradG Jan 24, 2024
7ccd780
[Testbed] Fix icons tests.
MuhammadMuradG Jan 24, 2024
7fd4872
[Button] Fix button icon tests.
MuhammadMuradG Jan 24, 2024
6041617
[Button] Fix button text tests.
MuhammadMuradG Jan 24, 2024
330d45f
[Button] Passing button tests.
MuhammadMuradG Jan 24, 2024
bafd283
Merge branch 'main' into gtk4-migration
MuhammadMuradG Jan 24, 2024
8a289c4
[Cleanup] Fix black formating.
MuhammadMuradG Jan 24, 2024
8e78c4e
[Cleanup] Fix black formating.
MuhammadMuradG Jan 24, 2024
fb1c27d
[Button] Complete passing button tests.
MuhammadMuradG Jan 24, 2024
ea6f986
[Docs] Update icon implementation docs.
MuhammadMuradG Jan 25, 2024
0bf0e25
[Cleanup] Fix docs formating.
MuhammadMuradG Jan 25, 2024
06b9a8f
Merge branch 'beeware:main' into gtk4-migration
MuhammadMuradG Jan 25, 2024
0eff81a
[imageview] Fix backend implementation.
MuhammadMuradG Jan 26, 2024
874f99f
[Testbed] Passing imageview tests.
MuhammadMuradG Jan 26, 2024
96554f1
[Cleanup] Add native widget str representation and add some comments.
MuhammadMuradG Jan 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
# work either. Blackbox is the lightest WM we've found that works.
pre-command: |
sudo apt update -y
sudo apt install -y blackbox pkg-config python3-dev libgirepository1.0-dev libcairo2-dev gir1.2-webkit2-4.0
sudo apt install -y blackbox pkg-config python3-dev libgirepository1.0-dev libcairo2-dev gir1.2-webkit2-4.0 libgtk-4-dev

# Start Virtual X server
echo "Start X server..."
Expand Down
7 changes: 5 additions & 2 deletions android/tests_backend/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ def assert_default_icon_content(self):
== Path(toga_android.__file__).parent / "resources/toga.png"
)

def assert_platform_icon_content(self):
assert self.icon._impl.path == self.app.paths.app / "resources/logo-android.png"
def assert_platform_icon_content(self, platform):
assert (
self.icon._impl.path
== self.app.paths.app / f"resources/logo-{platform}.png"
)
3 changes: 3 additions & 0 deletions android/tests_backend/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def content_size(self):
self.root_view.getHeight() / self.scale_factor,
)

def assert_as_image(self, screenshot, window_content_size):
self.assert_image_size(screenshot.size, window_content_size)

async def close_info_dialog(self, dialog):
dialog_view = self.get_dialog_view()
self.assert_dialog_buttons(dialog_view, ["OK"])
Expand Down
1 change: 1 addition & 0 deletions changes/1978.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Now, Toga is using ``Gtk4`` instead of ``Gtk3`` as the native GUI backend for Linux.
7 changes: 5 additions & 2 deletions cocoa/tests_backend/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ def assert_default_icon_content(self):
== Path(toga_cocoa.__file__).parent / "resources/toga.icns"
)

def assert_platform_icon_content(self):
assert self.icon._impl.path == self.app.paths.app / "resources/logo-macOS.icns"
def assert_platform_icon_content(self, platform):
assert (
self.icon._impl.path
== self.app.paths.app / f"resources/logo-{platform}.icns"
)
4 changes: 4 additions & 0 deletions cocoa/tests_backend/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class WindowProbe(BaseProbe):
supports_move_while_hidden = True
supports_multiple_select_folder = True
supports_unminimize = True
supports_positioning = True

def __init__(self, app, window):
super().__init__()
Expand Down Expand Up @@ -75,6 +76,9 @@ def minimize(self):
def unminimize(self):
self.native.deminiaturize(None)

def assert_as_image(self, screenshot, window_content_size):
self.assert_image_size(screenshot.size, window_content_size)

async def close_info_dialog(self, dialog):
self.native.endSheet(
self.native.attachedSheet,
Expand Down
5 changes: 3 additions & 2 deletions core/src/toga/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from builtins import id as identifier
from typing import TYPE_CHECKING
from weakref import ref

from travertino.node import Node

Expand Down Expand Up @@ -214,7 +215,7 @@ def window(self) -> Window | None:
If the widget has a value for :any:`window`, it *must* also have a value for
:any:`app`.
"""
return self._window
return self._window() if self._window else self._window

@window.setter
def window(self, window: Window | None) -> None:
Expand All @@ -226,7 +227,7 @@ def window(self, window: Window | None) -> None:
# If the widget is being assigned to a window for the first time, add it to the widget registry
window.app.widgets._add(self)

self._window = window
self._window = ref(window) if window else window
self._impl.set_window(window)

for child in self.children:
Expand Down
17 changes: 10 additions & 7 deletions core/src/toga/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,17 @@ def close(self) -> None:
self._impl.close()
self._closed = True

def as_image(self, format: type[ImageT] = Image) -> ImageT:
"""Render the current contents of the window as an image.

:param format: Format to provide. Defaults to :class:`~toga.images.Image`; also
supports :any:`PIL.Image.Image` if Pillow is installed
:returns: An image containing the window content, in the format requested.
def as_image(self, format: type[ImageT] = Image) -> ImageT | None:
"""Render the current contents of the window as an image if it's possible
otherwise nothing will be rendered.

:param format: Format to provide. Defaults to :class:`~toga.images.Image`;
also supports :any:`PIL.Image.Image` if Pillow is installed.
:returns: An image containing the window content, in the format requested
if possible otherwise return None.
"""
return Image(self._impl.get_image_data()).as_format(format)
image_data = self._impl.get_image_data()
return Image(image_data).as_format(format) if image_data else None

############################################################
# Dialogs
Expand Down
10 changes: 5 additions & 5 deletions docs/how-to/contribute-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ the Toga public API doesn't provide a way to determine the physical size of a
widget, or interrogate the font being used to render a widget; the probe
implementation does. This allows a testbed test case to verify that a widget has
been laid out correctly inside the Toga window, is drawn using the right font,
and has any other other appropriate physical properties or internal state.
and has any other appropriate physical properties or internal state.

The probe also provides a programmatic interface for interacting *with* a
widget. For example, in order to test a button, you need to be able to press
Expand All @@ -762,10 +762,10 @@ test case can call ``await probe.redraw()``. This guarantees that any
outstanding redraw events have been processed. These ``redraw()`` requests are
also used to implement slow mode - each redraw is turned into a 1 second sleep.

If a widget doesn't have a probe for a given widget, the testbed should call
``pytest.skip()`` for that platform when constructing the widget fixture (there
is a ``skip_on_platforms()`` helper method in the testbed method to do this).
If a widget hasn't implemented a specific probe method that the testbed
If a Toga widget doesn't have a probe for a given widget, the testbed should
call ``pytest.skip()`` for that platform when constructing the widget fixture
(there is a ``skip_on_platforms()`` helper method in the testbed method to do
this). If a widget hasn't implemented a specific probe method that the testbed
required, it should call ``pytest.skip()`` so that the backend knows to skip the
test.

Expand Down
14 changes: 6 additions & 8 deletions docs/reference/api/resources/icons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following formats are supported (in order of preference):
* **Android** - PNG
* **iOS** - ICNS, PNG, BMP, ICO
* **macOS** - ICNS, PNG, PDF
* **GTK** - PNG, ICO, ICNS. 32px and 72px variants of each icon can be provided;
* **GTK** - PNG, ICO, ICNS
* **Windows** - ICO, PNG, BMP

The first matching icon of the most specific platform, with the most specific
Expand All @@ -54,15 +54,13 @@ will cause Toga to look for (in order):

On GTK, Toga will look for (in order):

* ``myicon-linux-72.png``
* ``myicon-72.png``
* ``myicon-linux-32.png``
* ``myicon-32.png``
* ``myicon-linux.png``
* ``myicon-freebsd.png``
* ``myicon.png``
* ``myicon-linux-72.ico``
* ``myicon-72.ico``
* ``myicon-linux-32.ico``, and so on.
* ``myicon-linux.ico``
* ``myicon-freebsd.ico``
* ``myicon.ico``
* ``myicon-linux.ico``, and so on.

An icon is **guaranteed** to have an implementation, regardless of the path
specified. If you specify a path and no matching icon can be found, Toga will
Expand Down
10 changes: 7 additions & 3 deletions docs/reference/api/window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ Notes
these are ultimately at the discretion of the OS (or window manager). For
example, on macOS, depending on a user's OS-level settings, new windows may
open as tabs on the main window; on Linux, some window managers (e.g., tiling
window managers) may not honor an app's size and position requests. You should
avoid making UI design decisions that are dependent on specific size and
placement of windows.
window managers) may not honor an app's size request. You should avoid making
UI design decisions that are dependent on specific size of windows.

* GTK doesn't allow window positioning and it suggests leaving the positioning task
to the window managers. See `this discussion`_ for details.

* A mobile application can only have a single window (the :class:`~toga.MainWindow`),
and that window cannot be moved, resized, hidden, or made full screen. Toga will raise
an exception if you attempt to create a secondary window on a mobile platform. If you
try to modify the size, position, or visibility of the main window, the request will
be ignored.

.. _this discussion: https://discourse.gnome.org/t/how-to-center-gtkwindows-in-gtk4/3112/4

Reference
---------

Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ OTF
Pango
parameterization
platformer
positioning
pre
prepending
programmatically
Expand Down
Loading
Loading