From 52ce44f58f201f95315980c16f9c528a87b9cb8e Mon Sep 17 00:00:00 2001 From: Gregor Niehl Date: Sun, 29 Oct 2023 15:22:42 +0100 Subject: [PATCH 1/4] Library: Port 'Carousel' to Python --- src/Library/demos/Carousel/main.py | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/Library/demos/Carousel/main.py diff --git a/src/Library/demos/Carousel/main.py b/src/Library/demos/Carousel/main.py new file mode 100644 index 000000000..f822f0be9 --- /dev/null +++ b/src/Library/demos/Carousel/main.py @@ -0,0 +1,66 @@ +import gi + +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") + +from gi.repository import Adw, Gtk +import workbench + +root_box = workbench.builder.get_object("root_box") +carousel = workbench.builder.get_object("carousel") +ls_switch = workbench.builder.get_object("ls_switch") +sw_switch = workbench.builder.get_object("sw_switch") +indicator_row = workbench.builder.get_object("indicator_row") +orientation_row = workbench.builder.get_object("orientation_row") +indicators = None + +carousel.connect("page-changed", lambda *_: print("Page Changed")) + +# Scroll Wheel Switch +sw_switch.set_active(carousel.get_allow_scroll_wheel()) + +sw_switch.connect("notify::active", + lambda *_: carousel.set_allow_scroll_wheel(sw_switch.get_active()) +) + +# Long Swipe Switch +ls_switch.set_active(carousel.get_allow_long_swipes()) + +ls_switch.connect("notify::active", + lambda *_: carousel.set_allow_long_swipes(ls_switch.get_active()) +) + +if indicator_row.get_selected() == 0: + indicators = Adw.CarouselIndicatorDots(carousel=carousel) +else: + indicators = Adw.CarouselIndicatorLines(carousel=carousel) + +indicators.set_orientation(carousel.get_orientation()) +root_box.append(indicators) + + +def on_indicator_selected(*args): + global indicators + root_box.remove(indicators) + + if indicator_row.get_selected() == 0: + indicators = Adw.CarouselIndicatorDots(carousel=carousel) + else: + indicators = Adw.CarouselIndicatorLines(carousel=carousel) + + indicators.set_orientation(carousel.get_orientation()) + root_box.append(indicators) + +def on_orientation_selected(*args): + if orientation_row.get_selected() == 0: + root_box.set_orientation(Gtk.Orientation.VERTICAL) + carousel.set_orientation(Gtk.Orientation.HORIZONTAL) + indicators.set_orientation(Gtk.Orientation.HORIZONTAL) + else: + root_box.set_orientation(Gtk.Orientation.HORIZONTAL) + carousel.set_orientation(Gtk.Orientation.VERTICAL) + indicators.set_orientation(Gtk.Orientation.VERTICAL) + + +indicator_row.connect("notify::selected-item", on_indicator_selected) +orientation_row.connect("notify::selected-item", on_orientation_selected) From 86bbdbf78f65500f2ed18a6e89ca936d66f45e52 Mon Sep 17 00:00:00 2001 From: Gregor Niehl Date: Sun, 29 Oct 2023 15:31:21 +0100 Subject: [PATCH 2/4] Improve a demo --- src/Library/demos/Carousel/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Library/demos/Carousel/main.py b/src/Library/demos/Carousel/main.py index f822f0be9..11037c54d 100644 --- a/src/Library/demos/Carousel/main.py +++ b/src/Library/demos/Carousel/main.py @@ -39,7 +39,7 @@ root_box.append(indicators) -def on_indicator_selected(*args): +def on_indicator_selected(_widget, _item): global indicators root_box.remove(indicators) @@ -51,7 +51,7 @@ def on_indicator_selected(*args): indicators.set_orientation(carousel.get_orientation()) root_box.append(indicators) -def on_orientation_selected(*args): +def on_orientation_selected(_widget, _item): if orientation_row.get_selected() == 0: root_box.set_orientation(Gtk.Orientation.VERTICAL) carousel.set_orientation(Gtk.Orientation.HORIZONTAL) From 242e70255c095f3532f0f3501aaad5b81ef24ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Capypara=20K=C3=B6pcke?= Date: Sun, 29 Oct 2023 19:38:41 +0100 Subject: [PATCH 3/4] Apply black formatting to Carousel Python demo --- src/Library/demos/Carousel/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Library/demos/Carousel/main.py b/src/Library/demos/Carousel/main.py index 11037c54d..042ab709d 100644 --- a/src/Library/demos/Carousel/main.py +++ b/src/Library/demos/Carousel/main.py @@ -19,15 +19,15 @@ # Scroll Wheel Switch sw_switch.set_active(carousel.get_allow_scroll_wheel()) -sw_switch.connect("notify::active", - lambda *_: carousel.set_allow_scroll_wheel(sw_switch.get_active()) +sw_switch.connect( + "notify::active", lambda *_: carousel.set_allow_scroll_wheel(sw_switch.get_active()) ) # Long Swipe Switch ls_switch.set_active(carousel.get_allow_long_swipes()) -ls_switch.connect("notify::active", - lambda *_: carousel.set_allow_long_swipes(ls_switch.get_active()) +ls_switch.connect( + "notify::active", lambda *_: carousel.set_allow_long_swipes(ls_switch.get_active()) ) if indicator_row.get_selected() == 0: @@ -51,6 +51,7 @@ def on_indicator_selected(_widget, _item): indicators.set_orientation(carousel.get_orientation()) root_box.append(indicators) + def on_orientation_selected(_widget, _item): if orientation_row.get_selected() == 0: root_box.set_orientation(Gtk.Orientation.VERTICAL) From 397f7960f874cc99d649e44161dd784a116cc335 Mon Sep 17 00:00:00 2001 From: Gregor Niehl Date: Mon, 30 Oct 2023 16:16:38 +0100 Subject: [PATCH 4/4] Python Carousel Demo: Remove a variable definition --- src/Library/demos/Carousel/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Library/demos/Carousel/main.py b/src/Library/demos/Carousel/main.py index 042ab709d..787f00f0d 100644 --- a/src/Library/demos/Carousel/main.py +++ b/src/Library/demos/Carousel/main.py @@ -12,7 +12,6 @@ sw_switch = workbench.builder.get_object("sw_switch") indicator_row = workbench.builder.get_object("indicator_row") orientation_row = workbench.builder.get_object("orientation_row") -indicators = None carousel.connect("page-changed", lambda *_: print("Page Changed"))