2011-02-18 09:47:37 +01:00
|
|
|
"""
|
|
|
|
Basic Menu Example
|
|
|
|
++++++++++++++++++
|
2015-09-08 06:30:05 +02:00
|
|
|
|
2015-04-24 15:08:31 +02:00
|
|
|
Here is an example of a simple menu. Menus differ from panels in that they must
|
2011-02-18 09:47:37 +01:00
|
|
|
reference from a header, panel or another menu.
|
|
|
|
|
2015-04-24 15:08:31 +02:00
|
|
|
Notice the 'CATEGORY_MT_name' in :class:`Menu.bl_idname`, this is a naming
|
2011-02-18 09:47:37 +01:00
|
|
|
convention for menus.
|
|
|
|
|
|
|
|
.. note::
|
2016-02-15 09:37:37 +01:00
|
|
|
|
2011-02-18 09:47:37 +01:00
|
|
|
Menu subclasses must be registered before referencing them from blender.
|
2011-03-17 23:49:46 +01:00
|
|
|
|
|
|
|
.. note::
|
2016-02-15 09:37:37 +01:00
|
|
|
|
2015-04-24 15:08:31 +02:00
|
|
|
Menus have their :class:`Layout.operator_context` initialized as
|
|
|
|
'EXEC_REGION_WIN' rather than 'INVOKE_DEFAULT' (see :ref:`Execution Context <operator-execution_context>`).
|
|
|
|
If the operator context needs to initialize inputs from the
|
|
|
|
:class:`Operator.invoke` function, then this needs to be explicitly set.
|
2011-02-18 09:47:37 +01:00
|
|
|
"""
|
|
|
|
import bpy
|
|
|
|
|
|
|
|
|
|
|
|
class BasicMenu(bpy.types.Menu):
|
|
|
|
bl_idname = "OBJECT_MT_select_test"
|
|
|
|
bl_label = "Select"
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
2011-02-25 17:19:50 +01:00
|
|
|
|
2012-01-14 07:58:03 +01:00
|
|
|
layout.operator("object.select_all", text="Select/Deselect All").action = 'TOGGLE'
|
|
|
|
layout.operator("object.select_all", text="Inverse").action = 'INVERT'
|
2011-02-18 09:47:37 +01:00
|
|
|
layout.operator("object.select_random", text="Random")
|
|
|
|
|
|
|
|
|
|
|
|
bpy.utils.register_class(BasicMenu)
|
|
|
|
|
|
|
|
# test call to display immediately.
|
|
|
|
bpy.ops.wm.call_menu(name="OBJECT_MT_select_test")
|