Implementing Replace Label to Devalue Gtk 3.10+ Buttons in PyGObject 3.16

I'm using Glade 3.18 to develop frontends, which I later download with PyGObject from the module gi

to build a Gtk 3.16 UI.

To have an example, you can use the OK button. Reference guides (for Gtk 3 and GI ) specify that:

GTK_STOCK_OK

deprecated as of version 3.10 and should not be used in newly written code.

Don't use the icon. Use the "_OK" label.

However, setting the label to '_OK'

, either programmatically using button.set_label('_OK')

, or in Glade (on the General tab under the Extra Image Label section) will show a button displaying "_OK" and the not expected "OK" and icon.

So my question is, what's the correct way to implement the proposed replacement for Gtk.STOCK_OK

using PyGObject 3.16?

+3


source to share


1 answer


You have to pack Gtk.Image

both Gtk.Label

inside Gtk.Box

and pack the box inside Gtk.Button

. You must also use and Gtk.Button.set_always_show_image()

on your button Gtk.Button.use_underline()

to enable mnemonics for the label _OK

.

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 are strongly advised not to use an image or a generic "OK" shortcut. Use appropriate labels to describe the action and avoid meaningless icons.



Stock icons and labels are deprecated because they are not flexible enough for app developers. Stock icons do not cover the entire set of available named icons from the icon theme; stock tags are usually not expressive enough for users to understand, and they also have fixed mnemonics that can interfere with complex user interfaces (eg "_Open" and "_OK"), especially when it comes to translations.

Likewise, GTK does not provide a customization for better displaying the visibility of icons in menus and buttons; application developers and designers are responsible for deciding whether a menu item or button should have an icon or not, as they are responsible for how the GUI should look and behave.

Application developers are strongly encouraged to use expressive labels in their user interfaces and use icons from themes where it has the most impact.

+1


source







All Articles