3

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?

Arcturus B
  • 5,181
  • 4
  • 31
  • 51

1 Answers1

1

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.

ebassi
  • 8,648
  • 27
  • 29
  • 2
    This is would enforce the image which is not what I want. The button should display the stock icon depending on the user’s preference, like the `Gtk.STOCK_OK` did. As for the use of generic labels, I don’t agree: I can hardly imaging using something else than “add”, “cancel”, “help”, “delete” or a bunch of other stock buttons in tons of cases. (And that’s why they were created in the first time…) – Arcturus B Jun 23 '15 at 07:47
  • The whole approach of stock icons, of user preferences toggling the icons, and stock labels with fixed mnemonics has been deprecated because it demonstrably does not work as expected, and does not fit in into the interface guidelines of various OSes. Either you always show an icon because your app is designed to do so, or you display a label. – ebassi Jun 23 '15 at 17:19
  • 1
    Well, this is a real loss. Letting the user choose how interfaces should look allowed for a strong session-wide consistency and was a great strength of Gtk, at least on GNU/Linux-based environments. Anyway, thanks for this precision; you should consider adding it to your answer, I think it is at at least as relevant as your first answer, if not more. – Arcturus B Jun 23 '15 at 18:00
  • Letting the user choose breaks the assumptions that app developers may make; if I want an icon on a button in my application, it's my choice as the application developer and designer, not the user's. GTK still allows you to show icons and/or labels in buttons, but it does not let the user override your choice at a session level. – ebassi Jun 24 '15 at 18:25
  • 1
    This is why the *final* choice has always been left to the developer; for instance you could always enforce an icon. And by the way, I make the choice of letting the user choose whether some icons should or shouldn’t be displayed, in no way can he override my choice. Anyway, I think this difference between our personal preferences is not relevant any more with the topic. I still think you should add your 1st comment to your post, though. – Arcturus B Jun 24 '15 at 18:37