gtk.AccelLabel
gtk.AccelLabel — a label which displays accelerator info to the right of the text
Description
The gtk.AccelLabel
widget is a subclass of gtk.Label that
displays an accelerator string to the right of the label text, e.g.
Ctrl+S. It is commonly used in menus to show the keyboard
shortcuts for commands. The accelerator string to display is not set
explicitly; instead, the gtk.AccelLabel
displays the accelerators which have been added to the associated widget. A
widget is associated with the accelerator label by calling set_accel_widget().
For example, a gtk.MenuItem
widget may have an accelerator added to emit the "activate" signal when the
Ctrl+S key combination is pressed. A gtk.AccelLabel
is created and added to the gtk.MenuItem, and
set_accel_widget() is called with the gtk.MenuItem as
the first argument. The gtk.AccelLabel
will now display Ctrl+S after its label.
Creating a gtk.MenuItem with
the gtk.MenuItem()
function (or one of the similar functions gtk.CheckMenuItem()
and gtk.RadioMenuItem())
and specifying a label, automatically adds a gtk.AccelLabel
to the gtk.MenuItem and
calls set_accel_widget()
to set it up for you.
A gtk.AccelLabel
will only display accelerators which have
gtk.ACCEL_VISIBLE set. A gtk.AccelLabel
can display multiple accelerators and even signal names, though it is almost
always used to display just one accelerator.
The following code fragment creates a simple menu item with an
accelerator and enables the display of the accelerator key string in the
menu item label:
Example 1. Creating a simple menu item with an accelerator key.
# Create an accelgroup and add it to the window
accel_group = gtk.AccelGroup()
window.add_accel_group(accel_group)
# Create the menu item
save_item = gtk.MenuItem("Save")
save_item.show()
menu.add(save_item)
# Now add the accelerator to the menu item. Note that since we created
# the menu item with a label the AccelLabel is automatically setup to
# display the accelerators.
save_item.add_accelerator("activate", accel_group, ord("S"),
gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
|
Constructor
string : | the label string |
Returns : | a new gtk.AccelLabel
object |
gtk.AccelLabel() creates a new gtk.AccelLabel
object. The string parameter specifies the text to be
displayed by the label. The accelerator text is automatically added by the
associated widget.
Methods
gtk.AccelLabel.accelerator_width
Returns : | the width in pixels needed |
The accelerator_width() method returns
the width in pixels needed to display the accelerator(s). It is used by
menus to align all of the gtk.MenuItem
widgets, and isn't usually needed by applications.
gtk.AccelLabel.get_accel_widget
Returns : | the widget associated with the accelerator
label, or None. |
The get_accel_widget() method retrieves
the widget associated with this accelerator label. See gtk.AccelLabel.set_accel_widget().
gtk.AccelLabel.get_accel_width
Returns : | the width in pixels needed |
The get_accel_width() method returns
the width in pixels needed to display the accelerator(s). It is used by
menus to align all of the gtk.MenuItem
widgets, and isn't usually needed by applications.
gtk.AccelLabel.set_accel_widget
def set_accel_widget(accel_widget)
|
accel_widget : | the widget to be
associated. |
The set_accel_widget() method
associates the accelerator label with the widget specified by
accel_widget.
gtk.AccelLabel.refetch
The refetch() method recreates the
accelerator label string holding the accelerator information when the
accelerator is changed. The size of the string is also recalculated.
This method is not usually needed by applications since the
accelerator label string is automatically updated whenever accelerators are
added or removed from the associated widget.