3
votes

I’m using Glade 3.18 to design interfaces that I later load with PyGObject from the gi module to create a Gtk 3.16 user interface.

To have an example, let’s use the “OK” button. The reference manuals (for both Gtk 3 and GI) state that:

GTK_STOCK_OK has been deprecated since version 3.10 and should not be used in newly-written code.

Do not use an icon. Use label "_OK".

However, setting the label to '_OK', either programmatically using button.set_label('_OK') or in Glade (under the “General” tab, in the “Label with optional image” section), produces a button that displays “_OK” and not the expected “OK” and icon.

So my question is: what is the correct way to implement the proposed replacement for Gtk.STOCK_OK with PyGObject 3.16?

1

1 Answers

1
votes

You should pack a Gtk.Image and a Gtk.Label inside a Gtk.Box, and pack the box inside the Gtk.Button. You should also use Gtk.Button.set_always_show_image() on your button, and Gtk.Button.use_underline() to enable the mnemonic for the _OK label.

box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
# image and label are defined elsewhere
box.add(image)
box.add(label)
button = Gtk.Button(use_underline=True, always_show_image=True)
button.add(box)
button.show_all()

In any case, you're strongly encouraged not to use an image or a generic label like 'OK'. Use a proper label describing the action, and avoid a pointless icon.

Stock icons and labels have been deprecated because they are not flexible enough for application developers. Stock icons do not cover the whole set of available named icons from the icon theme; stock labels are usually not expressive enough for users to understand, and they also have fixed mnemonics, which may collide in complex UIs (e.g. "_Open" and "_OK"), especially when it comes to translations.

Similarly, GTK does not provide a user setting to toggle the visibility of icons in menus and buttons any more; application developers and designers are responsible for deciding whether a menu item or a button should have an icon or not, as they are the ones responsible for deciding how the GUI should look and behave.

Application developers are strongly encouraged to use expressive labels in their UIs, and use icons from themes wherever that makes most impact.