4
$\begingroup$

I am developping a modal operator. How can I determine if the cursor is over the Tools shelf or Properties shelf or pure 3D content (don't know how to call the last one correctly)?

My idea is to block an event in modal(self, context, event) from passing it back to Blender if the cursor is over pure 3D content. In that case modal(..) returns {'RUNNING_MODAL'}. However if the cursor is over the Tools shelf or Properties shelf the event is passed back to Blender, so the user can change some parameters in GUI panels located in the Tools shelf or Properties shelf. In the latter case modal(..) returns {'PASS_THROUGH'}.

$\endgroup$
6
$\begingroup$

There is a context.region.type variable which can have the following values:

  • WINDOW - 3D View
  • UI - Properties Panel
  • TOOLS - Tool Panel
  • values for the other possible regions (see the documentation)

However context.region.type seems to be determined once on operator invokation. So it will always have the same value while a modal operator is running. The only way seems to be to find out manually:

for region in context.area.regions:
    if(region.x <= event.mouse_x < region.x + region.width  and
       region.y <= event.mouse_y < region.y + region.height and
       region.type in ("TOOLS", "UI")):
        #
        return {'PASS_THROUGH'}

Perhaps a more appropriate way would be to check if the cursor is over the 3D View:

for region in context.area.regions:
    if(region.type == "WINDOW" and
       region.x <= event.mouse_x < region.x + region.width and
       region.y <= event.mouse_y < region.y + region.height):
        break
else:
    return {'PASS_THROUGH'}
$\endgroup$
  • $\begingroup$ Unfortunately context.region.type is always equal to "WINDOW" in my addon. Actual cursor position doesn't influence. $\endgroup$ – vvoovv May 29 '15 at 14:45
  • $\begingroup$ I also checked context.region.type with a simple addon from Blender Code Snippets. It's always equal to "WINDOW" $\endgroup$ – vvoovv May 29 '15 at 15:03
  • $\begingroup$ Ok, tested it for the modal operator template and it seems you are correct and the region.type is determined once on operator invokation. If you invoke it from the tools panel it prints "TOOLS". So you will have to find out manually. Added a section. $\endgroup$ – pink vertex May 30 '15 at 14:25
  • $\begingroup$ Yes, it works. Please check my edits $\endgroup$ – vvoovv May 31 '15 at 11:59

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.