1
$\begingroup$

I am finalizing a Blender add-on and I have an issue on the modal part with 2 events triggered by TAB or TABSHIFT.

Here is the actual code:

# TAB event
elif event.type == "TAB" and event.value == "PRESS":
    ...
    return {'RUNNING_MODAL'}

# TAB + SHIFT event
elif event.type == "TAB" and event.shift and event.value == "PRESS":
    ...
    return {'RUNNING_MODAL'}

The first event TAB works perfectly but the second event TAB + SHIFT does not work at all (never triggered).

So, without any success, I tried to:

  1. group the event condition such as: ( event.type == "TAB" and event.shift ) and event.value == "PRESS"
  2. replace event.shift by event.type == "LEFT_SHIFT"
  3. remove event.value == "PRESS"

Any idea?

$\endgroup$
1
$\begingroup$

I finally found a correct solution using a better code semantic.

The code should be done in 2 nested conditions; the main TAB event and the SHIFT event as in the following code:

elif event.type == "TAB" and event.value == "PRESS":

    if event.shift:
        # ... (code for TAB + SHIFT)
    else:
        # ... (code for TAB)

    return {'RUNNING_MODAL'}

A second good solution, closer to the initial code, consists to put the TAB + SHIFT condition first (thanks to batFINGER).

# TAB + SHIFT event -FIRST-
elif event.type == "TAB" and event.shift and event.value == "PRESS":
    ...
    return {'RUNNING_MODAL'}

# TAB event
elif event.type == "TAB" and event.value == "PRESS":
    ...
    return {'RUNNING_MODAL'}

Hope that could help someone else!

$\endgroup$
  • 1
    $\begingroup$ The logic was wrong. Your answer has the logic right. (Not sure re the correct, better or way it should be done), Could have simply changed the order of your elifs in "actual" question code, or nest the other way ie have shift in outside if. $\endgroup$ – batFINGER Oct 4 '18 at 1:52
  • $\begingroup$ Yes, changing the order of the 2 elifs is a good way too. First "TAB + SHIFT" and second "TAB" - in my initial code, the first "TAB" condition was always triggered and was blocking the second condition. Let me edit the answer to add you solution! $\endgroup$ – Yann Masoch Oct 4 '18 at 4:02

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.