Class cerebro.menus.Menu

class cerebro.menus.Menu(type, name)[source]

Class providing inerface for adding user’s custom menus.

Methods

In order to implement custom items into such application menus as Task, Message and Attachment menus, as well as submenus of the main menu you need to get access to them throuth the following functions:

task_mn = cerebro.menus.task_menu() # task menu
message_mn = cerebro.menus.message_menu() # message menu
attach_mn = cerebro.menus.attachment_menu() # attachment menu

main_mn = cerebro.menus.main_menu()     # main menu
my_menu = main_mn.add_menu('My submenu')

Then you can add custom menu items there:

task_mn.add_item('my_package.my_module.my_action', 'My meny item')

task_mn.insert_item(0, 'my_package.my_module.my_action1', 'My meny item 1')

and custom submenus:

my_menu = message_mn.add_menu('My submenu')
my_menu.add_item('my_package.my_module.my_action2', 'My meny item 2')
SHORTCUT_ = ''

Hot keys scope

SHORTCUT_CONTEXT_APPLICATION = 2

The hot keys combination is active in any active application window.

SHORTCUT_CONTEXT_PANEL = 0

The hot keys combination is active only if the panel with the menu it belongs to is active.

E.g., a hot key combination for a Forum menu item can be activated only if Forum panel is active (is in focus).

SHORTCUT_CONTEXT_WINDOW = 1

The hot keys combination is active in the active window, the menu belongs to.

E.g., a hot keys combination for a task menu item as available only if the main window is active.

add_item(function, name, icon='', shortcut='', shortcut_context=0)[source]
Parameters:
  • function (string) –

    string locator of the function that is called by click on the menu item.

    If the function is missing, a warning is displayed in the console, and an error message appears on activation of the menu item.

    Argument format of the function:

    'module_name.function_name'
    

    If a module is contained in a package, the format must be the following:

    'package_name.module_name.function_name'
    

    Warning

    sys.path must contain the path to the module / package

  • name (string) – menu item name.
  • icon (string) – file path to submenu icon.
  • shortcut (string) – hot keys combination to activate the menu item with a keyboard. Is set from key strings. E.g., “Ctrl+L” gives combination of CTRL+’L’. To specify auxiliary keys, the “Ctrl”, “Shift”, “Alt” and “Meta” strings are used. To specify letter keys, Latin letters are used. You can specify up to 4 key combinations in a sequence, separated by commas, e.g., “Alt+X, Ctrl+S, Q”. A sequence of key combinations imply that the menu item is activated by sequenced input of all the combinations listed.
  • shortcut_context (int) –

    specifies hot keys combination scope.

    Warning

    Hot keys combinations for main menu items should be input with shortcut_context equal to cerebro.menus.Menu.SHORTCUT_CONTEXT_WINDOW or cerebro.menus.Menu.SHORTCUT_CONTEXT_APPLICATION, otherwise it can never be active.

Adds an item to a menu.

EXAMPLE

See also

insert_item().

add_menu(name, icon='')[source]
Parameters:
  • name (string) – submenu name.
  • icon (string) – file path to submenu icon.
Returns:

added submenu.

Return type:

cerebro.menus.Menu

Adds a submenu to a menu.

message_mn = cerebro.menus.message_menu()                               
my_menu = message_mn.add_menu('My Submenu')             

See also

insert_menu().

add_separator()[source]

Adds a separator to a menu.

See also

insert_separator().

insert_item(pos, function, name, icon='', shortcut='', shortcut_context=0)[source]
Parameters:pos (int) – item position in the menu.

Puts an item into a certain position.

Warning

Due to dynamic menu formation, custom menus may take other positions in the GUI, than you have set.

See also

add_item().

insert_menu(pos, name, icon='')[source]
Parameters:pos (int) – submenu position.
Returns:inserted submenu.
Return type:cerebro.menus.Menu

Inserts a submenu into a certain position.

Warning

Due to dynamic menu formation, custom menus may take other positions in the GUI, than you have set.

See also

add_menu().

insert_separator(pos)[source]
Parameters:pos (int) – separator position.

Puts a separator into a certain position in the menu.

See also

add_separator().

size()[source]
Returns:menu size (number of items).
Return type:int