gtk.Menu — a drop down menu widget.
class gtk.Menu(gtk.MenuShell): |
+--gobject.GObject +-- gtk.Object +-- gtk.Widget +-- gtk.Container +-- gtk.MenuShell +-- gtk.Menu
|
These properties are available in GTK+ 2.4 and above.
|
These properties are available in GTK+ 2.4 and above.
|
gtk.Container Signal Prototypes
gtk.MenuShell Signal Prototypes
def callback( |
A gtk.Menu
is a gtk.MenuShell
that implements a drop down menu consisting of a list of gtk.MenuItem
objects which can be navigated and activated by the user to perform
application functions. A gtk.Menu
is most
commonly dropped down by activating a gtk.MenuItem
in a
gtk.MenuBar
or popped up by activating a gtk.MenuItem
in
another gtk.Menu
. A gtk.Menu
can also be
popped up by activating a gtk.OptionMenu
.
Other composite widgets such as the gtk.Notebook
can
pop up a gtk.Menu
as well.
Applications can display a gtk.Menu
as a popup
menu by calling the popup
()
method.
def popup(parent_menu_shell
, parent_menu_item
, func
, button
, activate_time
, data
=None)
| the menu shell containing the triggering menu
item or None . |
| the menu item whose activation triggered the
popup or None . |
| a user supplied function used to position the
menu or None . |
| the mouse button which was pressed to initiate the event. |
| the time at which the activation event occurred. |
| optional data to be passed to
func |
The popup
() method displays a menu and
makes it available for selection. Applications can use this function
to display context-sensitive menus, and will typically supply
None
for the
parent_menu_shell
,
parent_menu_item
and
func
parameters. The default menu positioning
function will position the menu at the current pointer position. The
button
and activate_time
values should be the mouse button that was pressed to trigger the menu
popup and the time the button was pressed. These values can usually
be retrieved from the "button_press_event".
The signature of func
is:
def func(menu, user_data):
where user_data
is
data
if not
None
. func
should return a
3-tuple containing the x and y coordinates of the position to draw the
menu and a boolean that, if True
, indicates that
the menu should be pushed in to be completely inside the screen
instead of just clamped to the size of the screen.
Prior to PyGTK 2.10 this method did not accept the
data
parameter and the signature of
func
was:
def func(menu, user_data):
def reposition()
The reposition
() method repositions the
menu on the screen according to the internal position function.
def get_active()
Returns : | the gtk.MenuItem that
was last selected in the menu. If a selection has not yet been made, the
first menu item is selected. |
The get_active
() method returns the
selected menu item from the menu. This is used by the gtk.OptionMenu
.
def set_active(index
)
| the index of the menu item to select. Index values start from 0. |
The set_active
() method selects the
menu item within the menu at the location specified by
index
. This is used by the gtk.OptionMenu
and is not useful for applications.
def set_accel_group(accel_group
)
| a gtk.AccelGroup |
The set_accel_group
() method associates
the gtk.AccelGroup
specified by accel_group
with the menu. The
accelerator group should also be added to all windows using this menu by
calling the gtk.Window.add_accel_group
()
method.
def get_accel_group()
Returns : | the gtk.AccelGroup
associated with the menu. |
The get_accel_group
() method returns
the gtk.AccelGroup
that holds the global accelerators for the menu.
def set_accel_path(accel_path
)
| a valid accelerator path |
The set_accel_path
() method sets an
accelerator path (specified by accel_path
) for this
menu to be used to construct accelerator paths for its menu items. This is a
convenience method used to avoid calling the gtk.MenuItem.set_accel_path
()
method on each menu item that should support runtime user changeable
accelerators. Instead, by just calling set_accel_path
()
on their parent, each menu item of this menu, that contains a label
describing its purpose, automatically gets an accel path assigned. For
example, calling:
menu.set_accel_path("<main>/File")
for a menu containing menu items "New" and "Exit", will assign
its items the accel paths: "<main>/File/New"
and
"<main>/File/Exit"
. Assigning accel paths to menu
items enables the user to change their accelerators at runtime.
def get_accel_path()
Returns : | the accelerator path set on the menu. |
This method is available in PyGTK 2.14 and above.
The get_accel_path
() method returns
the accelerator path set on the menu.
def attach_to_widget(attach_widget
, detach_func
)
| the widget that the menu will be attached to. |
| the user supplied callback function that will
be called when the menu calls the detach ()
method. |
The attach_to_widget
() method attaches
the menu to the widget specified by attach_widget
and
provides a callback function specified by detach_func
that will be invoked when the menu calls the detach
()
method during its destruction. Attaching a menu to a widget associates the
menu with a widget similar to setting a parent. This is mainly used for
associating popup menus with a widget and a submenu with a menuitem.
The signature of detach
is:
def detach_cb(menu, widget):
where menu
is the
menu being detached and widget
is the
attach_widget
.
For historical reasons, arguments for detach
callback are swapped compared to GTK+ C API.
def detach()
The detach
() method detaches the menu
from the widget to which it had been attached. See attach_to_widget
().
def get_attach_widget()
Returns : | the widget that the menu is attached to. |
The get_attach_widget
() method returns
the gtk.Widget
that the menu is attached to.
def set_tearoff_state(torn_off
)
| If True , the menu is
displayed as a tearoff menu. |
The set_tearoff_state
() method sets the
tearoff state of the menu to the value of torn_off
.
If torn_off
is True
the menu is
displayed as a tearoff menu; if torn_off
is
False
the menu is displayed as a drop down menu which
persists as long as the menu is active.
def get_tearoff_state()
Returns : | True if the menu is
currently torn off. |
The get_tearoff_state
() method returns
whether the menu is torn off. See set_tearoff_state
().
def set_title(title
)
| a string containing the title for the menu. |
The set_title
() method sets the title
text (from the value of title
) to be used for the
menu when it is shown as a tearoff menu.
def get_title()
Returns : | the title of the menu, or
None if the menu has no title set on
it. |
The get_title
() method returns the
title of the menu or None
of no title is set. See set_title
().
def reorder_child(child
, position
)
| the gtk.MenuItem to
move. |
| the new position to place child. Positions are numbered starting from 0 |
The reorder_child
() method moves the
menuitem specified by child
to a new position within
the menu specified by position
.
def set_screen(screen
)
| a gtk.gdk.Screen ,
or None if the screen should be determined by
the widget the menu is attached to. |
This method is available in PyGTK 2.2 and above.
The set_screen
() method sets the gtk.gdk.Screen
specified by screen
on which the menu will be
displayed. If screen
is None
the
screen is determined by the widget that the menu is attached to.
def attach(child
, left_attach
, right_attach
, top_attach
, bottom_attach
)
| a gtk.MenuItem . |
| The column number to attach the left side of the item to. |
| The column number to attach the right side of the item to. |
| The row number to attach the top of the item to. |
| The row number to attach the bottom of the item to. |
This method is available in PyGTK 2.4 and above.
The attach
() method adds a new gtk.MenuItem
specified by child
to a (table) menu. The number of
'cells' that an item will occupy is specified by
left_attach
, right_attach
,
top_attach
and
bottom_attach
. These each represent the leftmost,
rightmost, uppermost and lower column and row numbers of the table.
(Columns and rows are indexed from zero).
Note that this function is not related to the detach()
method.
def set_monitor(monitor_num
)
| the number of the monitor on which the menu should be popped up |
This method is available in PyGTK 2.4 and above.
The set_monitor
() method informs
GTK
+ on which monitor a menu should be popped up. See
the gtk.gdk.Screen.get_monitor_geometry()
method for more information.
This method should be called from a menu positioning function if the menu should not appear on the same monitor as the pointer. This information can't be reliably inferred from the coordinates returned by a menu positioning function, since, for very long menus, these coordinates may extend beyond the monitor boundaries or even the screen boundaries.
def get_monitor()
Returns : | the number of the monitor on which the menu should be popped up or -1, if no monitor has been set |
This method is available in PyGTK 2.14 and above.
The get_monitor
() method returns
the number of the monitor on which to show the menu.
def set_reserve_toggle_size(reserve_toggle_size
)
| True to reserve size for toggles. |
This method is available in PyGTK 2.22 and above.
The set_reserve_toggle_size
() method sets whether the menu
should reserve space for drawing toggles or icons, regardless of their actual presence.
def callback(menu
, type
, user_param1
, ...
)
| the menu that received the signal |
| the type of scroll that is requested |
| the first user parameter (if any) specified
with the connect () |
| additional user parameters (if any) |
This signal is available in GTK+ 2.2 and above.
The "move_scroll" signal is emitted when the user attempts to
scroll the menu. type
should be one of the GTK Scroll Step Constants.