-1

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

Republic
  • 11
  • 2
  • I have created Button UI and whenever user right click on the button UI, there is a small window like Change Shortcut, Remove Shortcut, Online Manual, Edit Source, edit Translation.

    I would like to disable the Right Click, whenever user Right Click, nothing happen. How can I do it ?

    Thanks

    – Republic Feb 27 '18 at 03:54

1 Answers1

2

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')

FkNWO
  • 74
  • 1
  • 7
batFINGER
  • 84,216
  • 10
  • 108
  • 233