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 45 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
- backend: gtk
pre-command: |
sudo apt update -y
sudo apt install -y pkg-config python3-dev libgirepository1.0-dev libcairo2-dev gir1.2-gtk-3.0
sudo apt install -y pkg-config python3-dev libgirepository1.0-dev libcairo2-dev gir1.2-gtk-3.0 libgtk-4-dev

- backend: iOS
runs-on: macos-latest
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
# tutorial, plus flwm to provide a window manager
pre-command: |
sudo apt update -y
sudo apt install -y flwm pkg-config python3-dev libgirepository1.0-dev libcairo2-dev gir1.2-webkit2-4.0
sudo apt install -y flwm 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
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.
144 changes: 41 additions & 103 deletions gtk/src/toga_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import toga
from toga import App as toga_App
from toga.command import GROUP_BREAK, SECTION_BREAK, Command
from toga.command import Command

from .keys import gtk_accel
from .libs import TOGA_DEFAULT_STYLES, Gdk, Gio, GLib, Gtk
from .libs import TOGA_DEFAULT_STYLES, Gdk, Gio, Gtk
from .window import Window


Expand All @@ -28,13 +27,12 @@ def _handler(action, data):
class MainWindow(Window):
_IMPL_CLASS = Gtk.ApplicationWindow

def create(self):
super().create()
self.native.set_role("MainWindow")
def __init__(self, interface, title, position, size):
super().__init__(interface, title, position, size)
icon_impl = toga_App.app.icon._impl
self.native.set_icon(icon_impl.native_72.get_pixbuf())
self.native.set_icon_name(icon_impl.native_72.get_icon_name())

def gtk_delete_event(self, *args):
def gtk_close_request(self, *args):
# Return value of the GTK on_close handler indicates
# whether the event has been fully handled. Returning
# False indicates the event handling is *not* complete,
Expand All @@ -47,10 +45,8 @@ def gtk_delete_event(self, *args):

class App:
"""
Todo:
* Creation of Menus is not working.
* Disabling of menu items is not working.
* App Icon is not showing up
This is the Gtk-backed implementation of the App interface class. It is
the manager of all the other bits of the GUI app in Gtk-backend.
"""

def __init__(self, interface):
Expand All @@ -77,6 +73,31 @@ def create(self):

def gtk_startup(self, data=None):
# Set up the default commands for the interface.
self._create_app_commands()

self.interface.startup()

# Create the lookup table of menu items,
# then force the creation of the menus.
self.create_menus()

# Set the default Toga styles
css_provider = Gtk.CssProvider()

# Backward compatibility fix for different gtk versions ===============
if Gtk.get_major_version() >= 4 and Gtk.get_minor_version() >= 12:
css_provider.load_from_string(TOGA_DEFAULT_STYLES)
elif Gtk.get_major_version() >= 4 and Gtk.get_minor_version() > 8:
css_provider.load_from_data(TOGA_DEFAULT_STYLES, len(TOGA_DEFAULT_STYLES))
else:
css_provider.load_from_data(TOGA_DEFAULT_STYLES.encode("utf-8"))
# =====================================================================

Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER
)

def _create_app_commands(self):
self.interface.commands.add(
Command(
lambda _: self.interface.about(),
Expand All @@ -93,101 +114,17 @@ def gtk_startup(self, data=None):
section=sys.maxsize,
),
)
self._create_app_commands()

self.interface.startup()

# Create the lookup table of menu items,
# then force the creation of the menus.
self.create_menus()

# Now that we have menus, make the app take responsibility for
# showing the menubar.
# This is required because of inconsistencies in how the Gnome
# shell operates on different windowing environments;
# see #872 for details.
settings = Gtk.Settings.get_default()
settings.set_property("gtk-shell-shows-menubar", False)

# Set any custom styles
css_provider = Gtk.CssProvider()
css_provider.load_from_data(TOGA_DEFAULT_STYLES)

context = Gtk.StyleContext()
context.add_provider_for_screen(
Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER
)

def _create_app_commands(self):
# No extra menus
pass

def gtk_activate(self, data=None):
pass

def create_menus(self):
# Only create the menu if the menu item index has been created.
self._menu_items = {}
self._menu_groups = {}

# Create the menu for the top level menubar.
menubar = Gio.Menu()
section = None
for cmd in self.interface.commands:
if cmd == GROUP_BREAK:
section = None
elif cmd == SECTION_BREAK:
section = None
else:
submenu = self._submenu(cmd.group, menubar)

if section is None:
section = Gio.Menu()
submenu.append_section(None, section)

cmd_id = "command-%s" % id(cmd)
action = Gio.SimpleAction.new(cmd_id, None)
if cmd.action:
action.connect("activate", gtk_menu_item_activate(cmd))

cmd._impl.native.append(action)
cmd._impl.set_enabled(cmd.enabled)
self._menu_items[action] = cmd
self.native.add_action(action)

item = Gio.MenuItem.new(cmd.text, "app." + cmd_id)
if cmd.shortcut:
item.set_attribute_value(
"accel", GLib.Variant("s", gtk_accel(cmd.shortcut))
)

section.append_item(item)

# Set the menu for the app.
self.native.set_menubar(menubar)
# TODO: Implementing menus in HeaderBar; See #1931.
self.interface.factory.not_implemented("Window.create_menus()")
pass

def _submenu(self, group, menubar):
try:
return self._menu_groups[group]
except KeyError:
if group is None:
submenu = menubar
else:
parent_menu = self._submenu(group.parent, menubar)

submenu = Gio.Menu()
self._menu_groups[group] = submenu

text = group.text
if text == "*":
text = self.interface.name

parent_menu.append_submenu(text, submenu)

# Install the item in the group cache.
self._menu_groups[group] = submenu

return submenu
pass

def main_loop(self):
# Modify signal handlers to make sure Ctrl-C is caught and handled.
Expand All @@ -202,7 +139,7 @@ def show_about_dialog(self):
about = Gtk.AboutDialog()

icon_impl = toga_App.app.icon._impl
about.set_logo(icon_impl.native_72.get_pixbuf())
about.set_logo(icon_impl.native_72.get_paintable())

if self.interface.name is not None:
about.set_program_name(self.interface.name)
Expand All @@ -215,8 +152,9 @@ def show_about_dialog(self):
if self.interface.home_page is not None:
about.set_website(self.interface.home_page)

about.run()
about.destroy()
about.set_modal(True)
about.set_transient_for(self.get_current_window().native)
about.present()

def beep(self):
Gdk.gdk_beep()
Expand Down
Loading
Loading