I would like to disable right click on my UI, for example, I don't want the user to use right click on my Button UI.
How can I disable Right Click ?
Thanks
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityI would like to disable right click on my UI, for example, I don't want the user to use right click on my Button UI.
How can I disable Right Click ?
Thanks
Modal Timer Operator
In a not recommended by me, method, you can disable right click by capturing in a modal operator. A drawback is it will disable autosave while running.
Example based on modal timer script template (it still changes viewport colour). Disables right click in all but 3d view and text editor areas.
import bpy
class ModalTimerOperator(bpy.types.Operator):
"""Operator which runs its self from a timer"""
bl_idname = "wm.modal_timer_operator"
bl_label = "Modal Timer Operator"
_timer = None
def modal(self, context, event):
if event.type in {'RIGHTMOUSE'}:
screen = context.screen
x, y = event.mouse_x, event.mouse_y
areas = [a for a in screen.areas if a.x < x < a.x + a.width
and a.y < y < a.y + a.height]
if areas and areas[0].type not in {'VIEW_3D', 'TEXT_EDITOR'}:
print("Right Click Taken Out")
return {'RUNNING_MODAL'}
if event.type in {'ESC'}:
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
# change theme color, silly!
color = context.preferences.themes[0].view_3d.space.gradients.high_gradient
color.s = 1.0
color.h += 0.01
return {'PASS_THROUGH'}
def execute(self, context):
wm = context.window_manager
self._timer = wm.event_timer_add(0.1, window=context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
wm = context.window_manager
wm.event_timer_remove(self._timer)
def register():
bpy.utils.register_class(ModalTimerOperator)
def unregister():
bpy.utils.unregister_class(ModalTimerOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.wm.modal_timer_operator('INVOKE_DEFAULT')