wiki:AvangoMenuModule

Module: avango-menu

The module "avango-menu" provides a sophisticated set of Python classes to construct 3D-menus in AVANGO. A menu is composed of widgets and can be placed freely in a 3d scene. There is a set of standard widgets which provide the functionality to build menus consisting of common 2D-GUI items like buttons, check boxes, radio buttons and images.

Widgets

Widgets are the fundamental items of avango-menu. A widget is the logical representation of a menu element. It can be added to a Panel or a Container which both act as container objects. To get the visual representation of a menu the Panel object can be asked for a scene graph node which is represented by the member variable "root".

There are several predefined widget types which can be used to construct a menu.

button = avango.menu.widget.PushButton(Title = "Push Button")
checkbox = avango.menu.widget.CheckBox(Title = "Check Box")
slider = avango.menu.widget.Slider(Title = "Slider")
divider = avango.menu.widget.Divider()
image = avango.menu.widget.Image(ImageFilename="avangong.png", ImageWidth=0.8, ImageAspectRatio=308.0/59.0)

radio_button_group = avango.menu.RadioButtonGroup()

radio1 = avango.menu.widget.RadioButton(Title = "Radio Button 1", Group = radio_button_group)
radio2 = avango.menu.widget.RadioButton(Title = "Radio Button 2", Group = radio_button_group)

container = avango.menu.widget.Container(Orientation = 2)  # 1=vertical, 2=horizontal
container.add_widget(radio1)
container.add_widget(radio2)

Panels

The main item to construct a menu is a panel, which is the logical representation of a flat menu frame containing other widgets. This panel can be asked for a visual representation which can be added to the scene graph. A panel itself is also a widget which can be put into another panel to serve as a sub-menu. In this case, not the whole panel is placed inside the other panel, but a link to it will be displayed. If the user clicks on that item, avango-menu takes care of the transition to show the new panel. For the transition to work correctly, all panels belonging to the same menu structure must be added to a panel group, which provides a switch node for the scene graph.

sub_menu = avango.menu.Panel(Title = "Sub Menu")
sub_menu.add_widgets([button])

main_menu = avango.menu.Panel(Title = "Main Menu")
main_menu.add_widgets([button, checkbox, divider, container, divider, slider, divider, sub_menu, divider, image])

Panel Groups

If a panel has one or more sub-panels, all involved panels including the main panel must be collected into a panel group. A panel group provides a scene graph node which acts like a switch node to show only one panel of the set at a time. In a multi user environment, every user could get her own panel group to have a separate interaction context.

panel_group = avango.menu.PanelGroup()
panel_group.add_panels([main_menu, sub_menu])
panel_group.show_panel(main_menu)

Tool

To interact with a menu, a Tool must be created for each user.

tool = avango.menu.Tool(Enable=True)
tool.PickTrigger.connect_from(window.MouseButtons_OnlyLeft)
tool.Transform.connect_from(camera.MouseNearTransform)
tool.MenuRootNode.value = scene_root

Preferences

The Preferences sub-module is a central place to store the settings for avango-menu. This provides the possibility to change parameters like colors or padding between menu items.

avango.menu.Preferences.container.WidgetHorizontalPadding.value = 0.1