7
$\begingroup$

can someone help me to understand the function of the parameters event and full_event of UILayout, please? The only description i can find ist this from the documentation (https://www.blender.org/api/blender_python_api_2_77_release/bpy.types.UILayout.html#bpy.types.UILayout.prop):

event (boolean, (optional)) – Use button to input key events
full_event (boolean, (optional)) – Use button to input full events including modifiers

But what buttons can/should be used to input key events? I can't find an difference to the version without event=True. And i can't find an example, too.

Thanks

$\endgroup$
2
  • $\begingroup$ just guessing, but 'modifiers' in this case could be keys like Ctrl, Shift, Space $\endgroup$ – aliasguru Jan 17 '17 at 8:52
  • $\begingroup$ I think that could be right - this is my assumption, too. But that's not my main question. $\endgroup$ – thz Jan 17 '17 at 9:46
4
$\begingroup$

'event' and 'full_event' parameters allow to get a keystroke value.

  • 'event': a key with no modifier
  • 'full_event': a key with modifiers

enter image description here

Here is a sample code:

import bpy

class HelloWorldPanel(bpy.types.Panel):
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    keymaps = []
    keymapitem = None

    def draw(self, context):
        layout = self.layout

        obj = context.object

        #Allow to get a key on a locally defined property
        layout.row().prop( obj, "myProperty", event = True )
        #Allow to get a key: no, does not work
        layout.row().prop( obj, "myProperty", full_event=True )

        #Allow to get a key on an existing property
        layout.row().prop( context.scene.game_settings, "exit_key", event=True )

        #Allow to get a full event key on a keymap item
        layout.row().prop( HelloWorldPanel.keymapitem, "type", full_event=True )

def register():
    #Enum property to define the allowed keys for this property
    bpy.types.Object.myProperty = bpy.props.EnumProperty( items=[('A','A',''),('LEFT_CTRL','LEFT_CTRL',''),('LEFT_ALT','LEFT_ALT','')] )
    bpy.utils.register_class(HelloWorldPanel)

    #Create a keymap and a key
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name='Test', space_type='EMPTY')
    kmi = km.keymap_items.new(HelloWorldPanel.bl_idname, 'LEFT_SHIFT', 'PRESS')
    #Store them here
    HelloWorldPanel.keymaps.append(km)
    HelloWorldPanel.keymapitem = kmi

def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)
    del bpy.types.Object.myProperty
    wm = bpy.context.window_manager
    for km in HelloWorldPanel.keymaps:
        wm.keyconfigs.addon.keymaps.remove(km)
    del HelloWorldPanel.keymaps[:]

if __name__ == "__main__":
    register()

Some explanations and remarks:

  • For a locally defined property (myProperty in the code above): the property is an enum which defines the scope of the possible values. But it seems that the user will not be warned if she/he choose a not wanted value.

  • You can use it for built in properties, like 'context.scene.game_settings' above.

But in both previous cases, I've found no solution to use 'full_event'.

  • Last example using a keymap item. Here choosing its type as attribute allows the usage of 'full_event'.

I don't know why some are working with 'full_event' and not others, as the enum described in the documentation seems to be the same. See the documentation here.

$\endgroup$
1
  • $\begingroup$ i've tried out your example. But unfortunately your answer is/was too late for me because i've already finished my master thesis. So I'll not search for further information. Nevertheless thanks for your answer. $\endgroup$ – thz Jul 14 '17 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.