GLib.Actionwhich can be used to define the primary actions of your app, assign them keyboard shortcuts, and tie them to
Actionablewidgets in your app like Buttons and Menu Items. In this section, we're going to create a Quit action for your app with an assigned keyboard shortcut and a Button that shows that shortcut in a tooltip.
Gtk.ApplicationWindowas you've done in previous examples. Once you have that set up, let's create a new
Gtk.HeaderBar. Typically your app will have a HeaderBar, at the top of the window, which will contain tool items that users will interact with to trigger your app's actions.
trueso that GTK knows to include window controls. We can then override our Window's built-in titlebar with the
Gtk.Buttonwith a big colorful icon and add it to our headerbar:
<Control>w". Notice that the action name is prefixed with
app; this refers to the
ActionMapbuilt in to
activatesignal of our
main_window. This must be at the end of
activate ()because of that reference to
action_nameproperty of our Button:
tooltip_markupproperty of your HeaderBar Button:
activate (): before we can get a list of the accelerators associated with the action, we have to define those accelerations and add them to the Application.