From 143e8f1c8b0816dd75f2f72c1df67700536cbef2 Mon Sep 17 00:00:00 2001 From: Gregor Niehl Date: Sun, 29 Oct 2023 16:10:56 +0100 Subject: [PATCH 1/8] Library: Port 'Color Dialog' to Python --- src/Library/demos/Color Dialog/main.py | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Library/demos/Color Dialog/main.py diff --git a/src/Library/demos/Color Dialog/main.py b/src/Library/demos/Color Dialog/main.py new file mode 100644 index 000000000..9700ec7f0 --- /dev/null +++ b/src/Library/demos/Color Dialog/main.py @@ -0,0 +1,42 @@ +import gi + +gi.require_version("Gtk", "4.0") +from gi.repository import Gdk, Gio, Gtk +import workbench + + +color_dialog_button = workbench.builder.get_object("color_dialog_button") +custom_button = workbench.builder.get_object("custom_button") + +color = Gdk.RGBA() +color.parse("red") + +dialog_standard = Gtk.ColorDialog( + title="Select a color", + modal=True, + with_alpha=True, +) + +color_dialog_button.set_dialog(dialog_standard) +color_dialog_button.set_rgba(color) + +color_dialog_button.connect("notify::rgba", + lambda *_: print( + f"Color Dialog Button: The color selected is {color_dialog_button.get_rgba().to_string()}", + ) +) + +dialog_custom = Gtk.ColorDialog( + title="Select a color", + modal=True, + with_alpha=False, +) + +def on_color_selected(_dialog, _result): + color = _dialog.choose_rgba_finish(_result) + print(f"Custom Button: The color selected is {color.to_string()}") + +def on_clicked(_button): + dialog_custom.choose_rgba(workbench.window, None, None, on_color_selected) + +custom_button.connect("clicked", on_clicked) From bb5a020e727bda6d3ebe57d609f0fe5fd3ab08e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=B6pcke?= Date: Sun, 29 Oct 2023 18:42:26 +0100 Subject: [PATCH 2/8] Implement Python formatting with black (#720) --- Makefile | 2 + black.sh | 20 +++++ build-aux/README.md | 27 ++++++ build-aux/modules/python-black.json | 104 ++++++++++++++++++++++++ build-aux/re.sonny.Workbench.Devel.json | 1 + build-aux/re.sonny.Workbench.json | 1 + package.json | 1 + src/Library/demos/Welcome/main.py | 11 +-- src/langs/python/python-previewer.py | 2 +- src/window.js | 23 ++++++ 10 files changed, 182 insertions(+), 10 deletions(-) create mode 100755 black.sh create mode 100644 build-aux/README.md create mode 100644 build-aux/modules/python-black.json diff --git a/Makefile b/Makefile index b0f96812e..b9b9722b6 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,8 @@ lint: flatpak run --user --command=/usr/lib/sdk/node18/bin/node --filesystem=host:ro org.gnome.Sdk//45 node_modules/.bin/eslint --max-warnings=0 src # rustfmt flatpak run --user --command=/usr/lib/sdk/rust-stable/bin/rustfmt --filesystem=host:ro org.gnome.Sdk//45 --check --edition 2021 src/**/*.rs +# black + ./black.sh --check src/**/*.py # gettext find po/ -type f -name "*po" -print0 | xargs -0 -n1 msgfmt -o /dev/null --check # Flatpak manifests diff --git a/black.sh b/black.sh new file mode 100755 index 000000000..f621c1538 --- /dev/null +++ b/black.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# This is a small wrapper around black - the Python code formatter. +# The script will setup and activate a virtual env in .venv if black is not +# found in PATH. +# +# Still requires Python 3. +set -e + +if ! which black &>/dev/null; then + if [ ! -d ".venv" ]; then + echo "Note: black was not found on your system. A virtualenv is created in .venv." + python3 -m venv .venv + fi + source .venv/bin/activate + if ! which black &>/dev/null; then + pip3 install black + fi +fi + +exec black "$@" diff --git a/build-aux/README.md b/build-aux/README.md new file mode 100644 index 000000000..daf99b70e --- /dev/null +++ b/build-aux/README.md @@ -0,0 +1,27 @@ +# Build Utilities + +This directory contains the Flatpak Manifest and other build utilities. + +## Workbench Flatpak Manifests + +### Python Black Dependency + +`modules/python-black.json` contains the Flatpak modules to install [https://github.com/psf/black](black), the +uncompromising Python code formatter. + +This file is partially auto-generated. Here is how to generate it: + +1. Obtain an up-to-date copy of [flatpak-builder-tools](https://github.com/flatpak/flatpak-builder-tools). +2. Make sure you have a Python virtualenv activated with the dependencies for the `pip` generator from the repo above. +3. Run `python3 <...>/flatpak-builder-tools/pip/flatpak-pip-generator black -o modules/python-black --build-isolation` + +You will notice that Workbench will now not build. This is due to these issues: + +- https://github.com/flatpak/flatpak-builder-tools/issues/380 +- https://github.com/pypa/pip/issues/7863 + +This means that the generated JSON file now needs its build dependencies manually added. Check the build dependencies +of black and their dependencies and add them to the JSON as well. Brute-forcing the build to obtain missing packages +may help as does referencing old commits of the file. You can also use the generator command to generate dependencies +for them and then merge it into the file by hand, but note that you will also need to manually collect their build +dependencies too. diff --git a/build-aux/modules/python-black.json b/build-aux/modules/python-black.json new file mode 100644 index 000000000..1611d749f --- /dev/null +++ b/build-aux/modules/python-black.json @@ -0,0 +1,104 @@ +{ + "name": "python3-black", + "buildsystem": "simple", + "build-commands": [ + "pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"black\"" + ], + "sources": [ + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/36/bf/a462f36723824c60dc3db10528c95656755964279a6a5c287b4f9fd0fa84/black-23.10.1.tar.gz", + "sha256": "1f8ce316753428ff68749c65a5f7844631aa18c8679dfd3ca9dc1a289979c258" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl", + "sha256": "ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/2a/e2/5d3f6ada4297caebe1a2add3b126fe800c96f56dbe5d1988a2cbe0b267aa/mypy_extensions-1.0.0-py3-none-any.whl", + "sha256": "4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl", + "sha256": "8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/b4/2a/9b1be29146139ef459188f5e420a66e835dda921208db600b7037093891f/pathspec-0.11.2-py3-none-any.whl", + "sha256": "1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/56/29/3ec311dc18804409ecf0d2b09caa976f3ae6215559306b5b530004e11156/platformdirs-3.11.0-py3-none-any.whl", + "sha256": "e9d171d00af68be50e9202731309c4e658fd8bc76f55c11c7dd760d023bda68e" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/6b/be/0f2f4a5e8adc114a02b63d92bf8edbfa24db6fc602fca83c885af2479e0e/editables-0.5-py3-none-any.whl", + "sha256": "61e5ffa82629e0d8bfe09bc44a07db3c1ab8ed1ce78a6980732870f19b5e7d4c" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/76/56/8ccca673e2c896931722f876bf040c0b6a7d8c1a128be60516a8a55bb27a/hatchling-1.18.0-py3-none-any.whl", + "sha256": "b66dc254931ec42aa68b5febd1d342c58142cc5267b7ff3b12ba3fa5b4900c93" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl", + "sha256": "8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/b4/2a/9b1be29146139ef459188f5e420a66e835dda921208db600b7037093891f/pathspec-0.11.2-py3-none-any.whl", + "sha256": "1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/05/b8/42ed91898d4784546c5f06c60506400548db3f7a4b3fb441cba4e5c17952/pluggy-1.3.0-py3-none-any.whl", + "sha256": "d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/ec/40/05cb2725ca7e6c844c66af626c5749efd254ec4506f17a1d01ba79ae9da6/trove_classifiers-2023.10.18-py3-none-any.whl", + "sha256": "20a3da8e3cb65587cc9f5d5b837bf74edeb480bba9bd8cd4f03ab056d6b06c4c" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/00/b1/90cc7881c2e870333eeafa6afb7b27de53418aad1ba5409ad331c96608a1/hatch_vcs-0.3.0-py3-none-any.whl", + "sha256": "60ce59a3fa4664057e4a858b6a96ab0b9dec21bf8f562f836139315bb361be8c" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/0e/a3/b9a8b0adfe672bf0df5901707aa929d30a97ee390ba651910186776746d2/setuptools_scm-8.0.4-py3-none-any.whl", + "sha256": "b47844cd2a84b83b3187a5782c71128c28b4c94cad8bfb871da2784a5cb54c4f" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/24/21/7d397a4b7934ff4028987914ac1044d3b7d52712f30e2ac7a2ae5bc86dd0/typing_extensions-4.8.0-py3-none-any.whl", + "sha256": "8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/6b/74/74a15619861065fa75f6170c649cd2fd5467726bb407ec2017d4a3f92d28/hatch_fancy_pypi_readme-23.1.0-py3-none-any.whl", + "sha256": "9a2c0e5d527611701858083bfb355876f26e04a075342b7d4da725ba5a6dd6ea" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/ef/cc/93f7213b2ab5ed383f98ce8020e632ef256b406b8569606c3f160ed8e1c9/setuptools-68.2.2.tar.gz", + "sha256": "4ac1475276d2f1c48684874089fefcd83bd7162ddaafb81fac866ba0db282a87" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/a4/99/78c4f3bd50619d772168bec6a0f34379b02c19c9cced0ed833ecd021fd0d/wheel-0.41.2.tar.gz", + "sha256": "0c5ac5ff2afb79ac23ab82bab027a0be7b5dbcf2e54dc50efe4bf507de1f7985" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/c4/e6/c1ac50fe3eebb38a155155711e6e864e254ce4b6e17fe2429b4c4d5b9e80/flit_core-3.9.0.tar.gz", + "sha256": "72ad266176c4a3fcfab5f2930d76896059851240570ce9a98733b658cb786eba" + } + ] +} diff --git a/build-aux/re.sonny.Workbench.Devel.json b/build-aux/re.sonny.Workbench.Devel.json index efc52fce0..3a942f9d7 100644 --- a/build-aux/re.sonny.Workbench.Devel.json +++ b/build-aux/re.sonny.Workbench.Devel.json @@ -45,6 +45,7 @@ "modules/blueprint-compiler.json", "modules/biome.json", "modules/icon-development-kit.json", + "modules/python-black.json", { "name": "Workbench", "buildsystem": "meson", diff --git a/build-aux/re.sonny.Workbench.json b/build-aux/re.sonny.Workbench.json index 55e5fea8d..2f272e78c 100644 --- a/build-aux/re.sonny.Workbench.json +++ b/build-aux/re.sonny.Workbench.json @@ -45,6 +45,7 @@ "modules/blueprint-compiler.json", "modules/biome.json", "modules/icon-development-kit.json", + "modules/python-black.json", { "name": "Workbench", "buildsystem": "meson", diff --git a/package.json b/package.json index a1fe8e148..d5ebd6d6d 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "lint-staged": { "*.{css,json,md,yaml,yml}": "prettier --write", "*.{js,cjs,mjs}": "eslint --fix", + "*.py": "./black.sh", "*.rs": "flatpak run --user --command=/usr/lib/sdk/rust-stable/bin/rustfmt --filesystem=host org.gnome.Sdk//45 --edition 2021" } } diff --git a/src/Library/demos/Welcome/main.py b/src/Library/demos/Welcome/main.py index 6daa21fc7..222b6e62e 100644 --- a/src/Library/demos/Welcome/main.py +++ b/src/Library/demos/Welcome/main.py @@ -7,10 +7,7 @@ def greet(_widget): - dialog = Adw.MessageDialog( - body="Hello World!", - transient_for=workbench.window - ) + dialog = Adw.MessageDialog(body="Hello World!", transient_for=workbench.window) dialog.add_response("ok", "Ok") dialog.connect("response", dialog_response) @@ -24,11 +21,7 @@ def dialog_response(dialog: Adw.MessageDialog, response: str): subtitle_box: Gtk.Box = workbench.builder.get_object("subtitle") -button = Gtk.Button( - label="Press me", - margin_top=6, - css_classes=["suggested-action"] -) +button = Gtk.Button(label="Press me", margin_top=6, css_classes=["suggested-action"]) button.connect("clicked", greet) subtitle_box.append(button) diff --git a/src/langs/python/python-previewer.py b/src/langs/python/python-previewer.py index 0475f7a57..70a732de6 100644 --- a/src/langs/python/python-previewer.py +++ b/src/langs/python/python-previewer.py @@ -22,7 +22,7 @@ gi.require_version("Gtk", "4.0") gi.require_version("Adw", "1") gi.require_version("Graphene", "1.0") -gi.require_version('Gsk', '4.0') +gi.require_version("Gsk", "4.0") from gi.repository import GLib, Gdk, Gtk, Adw, Graphene, Gio, Gsk from gi.repository.Gio import DBusConnection, DBusConnectionFlags diff --git a/src/window.js b/src/window.js index ccd64b514..ea3b0d7ca 100644 --- a/src/window.js +++ b/src/window.js @@ -242,6 +242,25 @@ export default function Window({ application, session }) { return stdout; } + function formatPythonCode(text) { + const blackLauncher = Gio.SubprocessLauncher.new( + Gio.SubprocessFlags.STDIN_PIPE | + Gio.SubprocessFlags.STDOUT_PIPE | + Gio.SubprocessFlags.STDERR_PIPE, + ); + + const blackProcess = blackLauncher.spawnv(["black", "--quiet", "-"]); + + const [success, stdout, stderr] = blackProcess.communicate_utf8(text, null); + + if (!success || stderr !== "") { + console.error(`Error running black: ${stderr}`); + return text; + } + + return stdout; + } + async function formatCode() { if (panel_code.panel.visible) { if (panel_code.language === "JavaScript") { @@ -255,6 +274,10 @@ export default function Window({ application, session }) { await format(langs.rust.document.code_view, (text) => { return formatRustCode(text); }); + } else if (panel_code.language === "Python") { + await format(langs.python.document.code_view, (text) => { + return formatPythonCode(text); + }); } } From a22b8b1bb4ac506f3d3287acc254ad685ebbeee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20L=C3=B6tscher?= <40485433+rolandlo@users.noreply.github.com> Date: Sun, 29 Oct 2023 19:34:04 +0100 Subject: [PATCH 3/8] library: Port Actions demo to Python (#717) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Marco Capypara Köpcke --- src/Library/demos/Actions/main.blp | 5 ++ src/Library/demos/Actions/main.py | 78 ++++++++++++++++++++++++++++++ src/about.js | 1 + 3 files changed, 84 insertions(+) create mode 100644 src/Library/demos/Actions/main.py diff --git a/src/Library/demos/Actions/main.blp b/src/Library/demos/Actions/main.blp index 7bb594353..1846acc3d 100644 --- a/src/Library/demos/Actions/main.blp +++ b/src/Library/demos/Actions/main.blp @@ -162,6 +162,11 @@ Adw.StatusPage demo { uri: "https://gjs.guide/guides/gio/actions-and-menus.html"; } + LinkButton { + label: _("PyGObjects Documentation"); + uri: "https://pygobject.readthedocs.io"; + } + LinkButton { label: _("GTK Documentation"); uri: "https://docs.gtk.org/gtk4/actions.html"; diff --git a/src/Library/demos/Actions/main.py b/src/Library/demos/Actions/main.py new file mode 100644 index 000000000..2faf6997d --- /dev/null +++ b/src/Library/demos/Actions/main.py @@ -0,0 +1,78 @@ +import gi + +gi.require_version("Gtk", "4.0") +gi.require_version("Adw", "1") +from gi.repository import Gtk, Adw, GLib, Gio +import workbench + +demo: Adw.StatusPage = workbench.builder.get_object("demo") + +demo_group = Gio.SimpleActionGroup() +demo.insert_action_group("demo", demo_group) + +# Action with no state or parameters +simple_action = Gio.SimpleAction(name="simple") + +simple_action.connect( + "activate", + lambda action, _: print(f"{action.get_name()} action activated"), +) + +demo_group.add_action(simple_action) + +# Action with parameter +bookmarks_action = Gio.SimpleAction( + name="open-bookmarks", + parameter_type=GLib.VariantType("s"), +) + +bookmarks_action.connect( + "activate", + lambda action, parameter: print( + f"{action.get_name()} activated with {parameter.unpack()}" + ), +) + +demo_group.add_action(bookmarks_action) + +# Action with state +toggle_action = Gio.SimpleAction( + name="toggle", + # Boolean actions dont need parameters for activation + state=GLib.Variant.new_boolean(False), +) + +toggle_action.connect( + "notify::state", + lambda action, _: print( + f"{action.get_name()} action set to {action.get_state().unpack()}" + ), +) + +demo_group.add_action(toggle_action) + +# Action with state and parameter +scale_action = Gio.SimpleAction( + name="scale", + state=GLib.Variant.new_string("100%"), + parameter_type=GLib.VariantType("s"), +) + +scale_action.connect( + "notify::state", + lambda action, _: print( + f"{action.get_name()} action set to {action.get_state().unpack()}" + ), +) + +demo_group.add_action(scale_action) + +text: Gtk.Label = workbench.builder.get_object("text") + +alignment_action = Gio.PropertyAction( + name="text-align", + object=text, + property_name="halign", +) + +demo_group.add_action(alignment_action) diff --git a/src/about.js b/src/about.js index ee49c15fa..d73403c59 100644 --- a/src/about.js +++ b/src/about.js @@ -82,6 +82,7 @@ ${getBlueprintVersion()} "Onkar https://github.com/onkarrai06", "Sabrina Meindlhumer https://github.com/m-sabrina", "Urtsi Santsi ", + "Roland Lötscher https://github.com/rolandlo", // Add yourself as // "John Doe", // or From 843b34f4dc276315d4f452d23d5f7a9368d6eb96 Mon Sep 17 00:00:00 2001 From: UrtsiSantsi <142679804+UrtsiSantsi@users.noreply.github.com> Date: Sun, 29 Oct 2023 20:37:42 +0200 Subject: [PATCH 4/8] Library: Port 'Spinner' demo to Python (#712) --- src/Library/demos/Spinner/main.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/Library/demos/Spinner/main.py diff --git a/src/Library/demos/Spinner/main.py b/src/Library/demos/Spinner/main.py new file mode 100644 index 000000000..df2648efb --- /dev/null +++ b/src/Library/demos/Spinner/main.py @@ -0,0 +1,20 @@ +import gi + +gi.require_version("Gtk", "4.0") +from gi.repository import Gtk +import workbench + +button: Gtk.Button = workbench.builder.get_object("button") +spinner: Gtk.Spinner = workbench.builder.get_object("spinner") + + +def button_clicked(_widget): + if spinner.get_spinning(): + button.set_icon_name("media-playback-start") + spinner.set_spinning(False) + else: + button.set_icon_name("media-playback-pause") + spinner.set_spinning(True) + + +button.connect("clicked", button_clicked) From 4487186982ab1d9a3768cec2408cc81b937deaa0 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Sun, 29 Oct 2023 19:56:07 +0100 Subject: [PATCH 5/8] Do not exit if Library is the only window open (#721) --- .vscode/extensions.json | 3 ++- src/IconLibrary/main.js | 15 +++++---------- src/Library/Library.blp | 2 +- src/Library/Library.js | 14 +++++++------- src/shortcutsWindow.blp | 2 +- src/shortcutsWindow.js | 18 +++++++++--------- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d4c5c72dc..e72a3d0b8 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -8,6 +8,7 @@ "mesonbuild.mesonbuild", "prince781.vala", "bodil.blueprint-gtk", - "dbaeumer.vscode-eslint" + "dbaeumer.vscode-eslint", + "ms-python.black-formatter" ] } diff --git a/src/IconLibrary/main.js b/src/IconLibrary/main.js index 60e7c7198..77f1e3899 100644 --- a/src/IconLibrary/main.js +++ b/src/IconLibrary/main.js @@ -1,11 +1,12 @@ import Gtk from "gi://Gtk?version=4.0"; import Gdk from "gi://Gdk"; - import Adw from "gi://Adw"; import Gio from "gi://Gio"; +import { build } from "../../troll/src/builder.js"; + import IconWidget from "./IconWidget.js"; -import resource from "./main.blp"; +import resource from "./main.blp" with { type: "uri" }; const toasts = new Set(); @@ -21,10 +22,8 @@ export default function IconLibrary() { dev_kit_icons, ); - const builder = Gtk.Builder.new_from_resource(resource); - - const overlay = builder.get_object("overlay"); - const search_entry = builder.get_object("search_entry"); + const { window, overlay, search_entry, flow_box_devkit, flow_box_platform } = + build(resource); function selectIcon(icon_name) { clipboard.set(icon_name); @@ -41,9 +40,6 @@ export default function IconLibrary() { overlay.add_toast(toast); } - const flow_box_devkit = builder.get_object("flow_box_devkit"); - const flow_box_platform = builder.get_object("flow_box_platform"); - function filter_func({ icon_name }) { return icons[icon_name]?.some((tag) => tag.includes(search_entry.text)); } @@ -84,7 +80,6 @@ export default function IconLibrary() { populateIconDevKit(); populatePlatformIcons(); - const window = builder.get_object("window"); return window; } diff --git a/src/Library/Library.blp b/src/Library/Library.blp index 9c49fb4ae..d4de01568 100644 --- a/src/Library/Library.blp +++ b/src/Library/Library.blp @@ -1,7 +1,7 @@ using Gtk 4.0; using Adw 1; -Adw.PreferencesWindow library { +Adw.PreferencesWindow window { hide-on-close: true; modal: false; title: _("Library"); diff --git a/src/Library/Library.js b/src/Library/Library.js index 9bcdd34b1..0afe752e4 100644 --- a/src/Library/Library.js +++ b/src/Library/Library.js @@ -1,5 +1,4 @@ import Gio from "gi://Gio"; -import Gtk from "gi://Gtk"; import { decode, @@ -9,17 +8,18 @@ import { } from "../util.js"; import Window from "../window.js"; -import resource from "./Library.blp"; +import resource from "./Library.blp" with { type: "uri" }; import { createSessionFromDemo } from "../sessions.js"; import EntryRow from "./EntryRow.js"; import illustration from "./library.svg"; -export default function Library({ application }) { - const builder = Gtk.Builder.new_from_resource(resource); - const window = builder.get_object("library"); +import { build } from "../../troll/src/builder.js"; - const picture_illustration = builder.get_object("picture_illustration"); +export default function Library({ application }) { + const objects = build(resource); + const { window, picture_illustration } = objects; + window.application = application; picture_illustration.set_resource(illustration); let last_selected; @@ -39,7 +39,7 @@ export default function Library({ application }) { }).catch(console.error); }); - builder.get_object(`library_${demo.category}`).add(widget); + objects[`library_${demo.category}`].add(widget); }); const action_library = new Gio.SimpleAction({ diff --git a/src/shortcutsWindow.blp b/src/shortcutsWindow.blp index 67d4bb6d5..bd2bb387f 100644 --- a/src/shortcutsWindow.blp +++ b/src/shortcutsWindow.blp @@ -1,6 +1,6 @@ using Gtk 4.0; -ShortcutsWindow window_shortcuts { +ShortcutsWindow window { hide-on-close: true; ShortcutsSection { diff --git a/src/shortcutsWindow.js b/src/shortcutsWindow.js index d14a27d40..147b7b212 100644 --- a/src/shortcutsWindow.js +++ b/src/shortcutsWindow.js @@ -1,23 +1,23 @@ -import Gtk from "gi://Gtk"; import Gio from "gi://Gio"; -import resource from "./shortcutsWindow.blp"; +import resource from "./shortcutsWindow.blp" with { type: "uri" }; + +import { build } from "../troll/src/builder.js"; export default function ShortcutsWindow({ application }) { - let window_shortcuts; + let window; const action_shortcuts = new Gio.SimpleAction({ name: "shortcuts", parameter_type: null, }); action_shortcuts.connect("activate", () => { - if (!window_shortcuts) { - const builder = Gtk.Builder.new_from_resource(resource); - window_shortcuts = builder.get_object("window_shortcuts"); - window_shortcuts.set_transient_for(application.get_active_window()); - window_shortcuts.set_application(application); + if (!window) { + ({ window } = build(resource)); + window.set_transient_for(application.get_active_window()); + window.set_application(application); } - window_shortcuts.present(); + window.present(); }); application.add_action(action_shortcuts); application.set_accels_for_action("app.shortcuts", ["question"]); From 8a5cb7dfd54de39b844176bd957f7260602a052e Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Sun, 29 Oct 2023 20:20:11 +0100 Subject: [PATCH 6/8] Move PyGObject url to Bookmarks (#723) --- src/Library/demos/Actions/main.blp | 5 ----- src/window.blp | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Library/demos/Actions/main.blp b/src/Library/demos/Actions/main.blp index 1846acc3d..7bb594353 100644 --- a/src/Library/demos/Actions/main.blp +++ b/src/Library/demos/Actions/main.blp @@ -162,11 +162,6 @@ Adw.StatusPage demo { uri: "https://gjs.guide/guides/gio/actions-and-menus.html"; } - LinkButton { - label: _("PyGObjects Documentation"); - uri: "https://pygobject.readthedocs.io"; - } - LinkButton { label: _("GTK Documentation"); uri: "https://docs.gtk.org/gtk4/actions.html"; diff --git a/src/window.blp b/src/window.blp index b1d14d2e0..9c0a560b1 100644 --- a/src/window.blp +++ b/src/window.blp @@ -525,6 +525,12 @@ menu menu_app { target: "https://gtk-rs.org"; } + item { + label: _("Python"); + action: "app.open_uri"; + target: "https://pygobject.readthedocs.io"; + } + item { label: _("Blueprint"); action: "app.open_uri"; From 0bd119938369bbd042d6e75e75de918a6948e307 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Sun, 29 Oct 2023 20:22:15 +0100 Subject: [PATCH 7/8] Prepare release 45.3 --- README.md | 2 +- data/app.metainfo.xml | 21 ++++++++++++++++++++- meson.build | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 388151e56..071b23640 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Among other things, Workbench comes with - Live GTK/CSS preview - Library of 100+ examples -- JavaScript, Python, Rust and Vala support +- JavaScript, Rust, Python and Vala support - Declarative user interface syntax - Autosave, sessions and projects - Code linter and formatter diff --git a/data/app.metainfo.xml b/data/app.metainfo.xml index 800c3455f..688228694 100644 --- a/data/app.metainfo.xml +++ b/data/app.metainfo.xml @@ -15,7 +15,7 @@
  • Live GTK/CSS preview
  • Library of 100+ examples
  • -
  • JavaScript, Python, Rust and Vala support
  • +
  • JavaScript, Rust, Python and Vala support
  • Declarative user interface syntax
  • Autosave, sessions and projects
  • Code linter and formatter
  • @@ -48,6 +48,25 @@ + + +
      +
    • Add Python support
    • +
    • Show which languages are available for each Library entry
    • +
    • Make Library faster to launch
    • +
    • Documentation viewer now sync the sidebar selection with navigation
    • +
    • Add fuzzy search to documentation viewer
    • +
    • Add search result tags to documentation viewer
    • +
    • Do not exit if Library is the last window open
    • +
    • Library allows opening an entry in a specific language
    • +
    • Library: Port entries to libadwaita SpinRow
    • +
    • Library: Port "Welcome" entry to Python
    • +
    • Library: Port "Actions" entry to Python
    • +
    • Library: Port "Spinner" entry to Python
    • +
    • Library: Fix "Preferences Window" adaptiveness
    • +
    +
    +
      diff --git a/meson.build b/meson.build index c0a5f3058..5d9c2ae17 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('Workbench', ['vala', 'c', 'rust'], - version: '45.2', + version: '45.3', meson_version: '>= 0.59.0', license: 'GPL-3.0-only' ) From a9ac39a8ec9b60b16da4f545b2234007b2ac6e4f Mon Sep 17 00:00:00 2001 From: Gregor Niehl Date: Sun, 29 Oct 2023 23:22:11 +0100 Subject: [PATCH 8/8] Apply black code formatting --- src/Library/demos/Color Dialog/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Library/demos/Color Dialog/main.py b/src/Library/demos/Color Dialog/main.py index 9700ec7f0..7c36a27a6 100644 --- a/src/Library/demos/Color Dialog/main.py +++ b/src/Library/demos/Color Dialog/main.py @@ -20,10 +20,11 @@ color_dialog_button.set_dialog(dialog_standard) color_dialog_button.set_rgba(color) -color_dialog_button.connect("notify::rgba", +color_dialog_button.connect( + "notify::rgba", lambda *_: print( f"Color Dialog Button: The color selected is {color_dialog_button.get_rgba().to_string()}", - ) + ), ) dialog_custom = Gtk.ColorDialog( @@ -32,11 +33,14 @@ with_alpha=False, ) + def on_color_selected(_dialog, _result): color = _dialog.choose_rgba_finish(_result) print(f"Custom Button: The color selected is {color.to_string()}") + def on_clicked(_button): dialog_custom.choose_rgba(workbench.window, None, None, on_color_selected) + custom_button.connect("clicked", on_clicked)