This snapcraft.yaml part definition and corresponding changes enable the usage of Zenity, allowing packagers to present GUI dialogs to the users.
This is normally used in GTK application snaps to present a message or require user input in a relatively friendly user interface:
Also, see Inform users with custom dialogs for the generic usage of dialogs in snaps.
Prerequisites
This section documents the prerequisites for using this Snapcraft part:
- Your snap must be using one of the supported GNOME extensions.
Usage
Follow the following instructions to incorporate Zenity into your snaps:
-
Merge the following part definition into the
parts
stanza of your snapcraft.yaml file:parts: # Integrate custom dialogs in your snap - doc - snapcraft.io # https://forum.snapcraft.io/t/integrate-custom-dialogs-in-your-snap/10825 zenity: plugin: nil stage-packages: - zenity prime: - usr/bin/zenity - usr/share/zenity/* - usr/share/doc/*/copyright*
-
Merge the following layout definition into the
layout
stanza of your snapcraft.yaml file:layout: # Fix resource relocation problem of zenity part /usr/share/zenity: symlink: $SNAP/usr/share/zenity
-
In your launcher or application, invoke the
zenity
command as in the following example:zenity_opts=( # Specify to use the information dialog type --info # Specify the text of the dialog window's title bar --title='Example text dialog' # Specify the text of the dialog's body --text='This is an example text dialog.' ) if ! zenity "${zenity_opts[@]}"; then printf \ 'Error: Unable to present the security confinement warning(home).\n.' \ 1>&2 exit 1 fi
This example code snippet should present a dialog similar to the following screenshot:
Refer to the Zenity Manual for more info on how to invoke the zenity
command.
Limitations
This implementation uses whatever version of Zenity that’s distributed by the Ubuntu release on which your base is based. It may not provide all the features(including but not limited to, HTML support) you want.
Examples
This section enumerates snaps that make use of this part:
- XNote Stopwatch (UNOFFICIAL)
Uses the information dialog type, source code.
Reference
The following material is referenced during the writing of this article:
- Zenity Manual
Explain how to use the Zenity utility. - Zenity dialogs in a snap - snapcraft - snapcraft.io
Another way to incorporate Zenity by Olivier Tilloy - Pango – 1.0: Text Attributes and Markup
Explains the Pango markup used in the dialog text.