Daniel Brötzmann pushed to branch gtk4 at gajim / gajim
Commits:
b5c968a6 by wurstsalat at 2024-11-02T23:43:00+01:00
refactor: Require Gsk and Graphene versions
- - - - -
b060a5f9 by wurstsalat at 2024-11-02T23:43:35+01:00
refactor: Add example test for Gsk texture painting
- - - - -
2 changed files:
- gajim/main.py
- + test/gtk/ui_test_snapshot.py
Changes:
=====================================
gajim/main.py
=====================================
@@ -40,9 +40,11 @@ def gi_require_versions() -> None:
'GLib': '2.0',
'Gio': '2.0',
'Gdk': '4.0',
+ 'Gsk': '4.0',
'Gtk': '4.0',
'GtkSource': '5',
'GObject': '2.0',
+ 'Graphene': '1.0',
'Pango': '1.0',
'PangoCairo': '1.0',
}
=====================================
test/gtk/ui_test_snapshot.py
=====================================
@@ -0,0 +1,74 @@
+# This file is part of Gajim.
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from gi.repository import Gdk
+from gi.repository import Graphene
+from gi.repository import Gsk
+from gi.repository import Gtk
+
+from gajim.gtk.widgets import GajimAppWindow
+
+from . import util
+
+DEFAULT_IMAGE_FILE_PATH = (
+ util.get_gajim_dir() / 'data/icons/hicolor/96x96/apps/gajim.png'
+)
+
+
+class TestSnapshot(GajimAppWindow):
+ def __init__(self):
+ GajimAppWindow.__init__(
+ self,
+ name='',
+ title=__class__.__name__,
+ default_width=600,
+ default_height=600,
+ )
+
+ box = Gtk.Box(
+ halign=Gtk.Align.CENTER,
+ valign=Gtk.Align.CENTER,
+ hexpand=True,
+ orientation=Gtk.Orientation.VERTICAL,
+ spacing=12,
+ )
+ self.set_child(box)
+
+ self._image = Gtk.Image()
+ self._image.set_pixel_size(100)
+ box.append(self._image)
+
+ self._paint()
+
+ def _paint(self) -> None:
+ texture = Gdk.Texture.new_from_filename(str(DEFAULT_IMAGE_FILE_PATH))
+
+ snapshot = Gtk.Snapshot.new()
+ rect = Graphene.Rect().init(0, 0, texture.get_width(),
texture.get_height())
+ snapshot.append_texture(texture, rect)
+
+ cutout_rect = Graphene.Rect().init(50, 50, 50, 50)
+
+ color = Gdk.RGBA()
+ color.parse('rgb(70, 0, 190)')
+
+ rounded_rect = Gsk.RoundedRect()
+ rounded_rect.init_from_rect(cutout_rect, radius=25)
+
+ snapshot.push_rounded_clip(rounded_rect)
+ snapshot.append_color(color, cutout_rect)
+ snapshot.pop()
+
+ overlay_rect = Graphene.Rect().init(55, 55, 40, 40)
+ snapshot.append_scaled_texture(
+ texture, Gsk.ScalingFilter.TRILINEAR, overlay_rect
+ )
+
+ self._image.set_from_paintable(snapshot.to_paintable())
+
+
+window = TestSnapshot()
+window.show()
+
+util.run_app()
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/3ff91d1c811a3d01ed53a751e90caa41b1c45aba...b060a5f9523cae4e7e90eb492e274964f65761bb
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/3ff91d1c811a3d01ed53a751e90caa41b1c45aba...b060a5f9523cae4e7e90eb492e274964f65761bb
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]