Modal operator help needed

Hi, I’d like to have this modal operation work for scrolling between vertex group index while weight painting.

import bpy
from bpy.props import IntProperty, FloatProperty


class ModalOperator(bpy.types.Operator):
    """Move an object with the mouse, example"""
    bl_idname = "object.modal_operator"
    bl_label = "Simple Modal Operator"

    first_mouse_x = IntProperty()
    first_value = FloatProperty()

    def modal(self, context, event):
        if event.type == 'MOUSEMOVE':
            if self.lmb:
                delta = self.first_mouse_x - event.mouse_x
                context.object.location.x = self.first_value + delta * 0.01

        elif event.type == 'LEFTMOUSE':
            # we could handle PRESS and RELEASE individually if necessary
            self.lmb = event.value == 'PRESS'

        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            context.object.location.x = self.first_value
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        # variable to remember left mouse button state    
        self.lmb = False

        if context.object:
            self.first_mouse_x = event.mouse_x
            self.first_value = context.object.location.x

            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "No active object, could not finish")
            return {'CANCELLED'}


def register():
    bpy.utils.register_class(ModalOperator)


def unregister():
    bpy.utils.unregister_class(ModalOperator)


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.modal_operator('INVOKE_DEFAULT')

Thanks.

------bump-------

Any python genius out there that can make this possible?

Okay, I got scrolling through vertex group index using mouse movement to work, the only problem is, how do I get weight painting to work during the modal operation?

Here is the solution, only need to have weight painting work while vgroup index changes
Just add 5 vertex groups and run script, search up “Start vGroup scrolling” to run operation
Press ESC key when done:

import bpy
from bpy.props import IntProperty, FloatProperty



class ModalOperator(bpy.types.Operator):
    """description"""
    bl_idname = "object.modal_operator"
    bl_label = "Start vGroup scrolling"

    first_mouse_x = IntProperty()
    first_value = FloatProperty()
    
    
    def modal(self, context, event):
        
        if event.type == 'MOUSEMOVE':
            if self.lmb:
            
                return {'PASS_THROUGH'}
        ob = bpy.context.active_object
        delta = self.first_mouse_x - event.mouse_x
      
        index=  delta *0.01 %  5
        
        if event.type == 'LEFTMOUSE':

            if event.value == 'PRESS':
                mesh = bpy.context.object

                mesh.vertex_groups.active_index = index
           
                
                return {'PASS_THROUGH'}
            
            if event.value == 'RELEASE':
                return {'PASS_THROUGH'}
        
        
        if event.type == 'MOUSEMOVE':
            mesh = bpy.context.object

            mesh.vertex_groups.active_index = index
           
   
                
            return {'PASS_THROUGH'}
           
        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            context.area.header_text_set
            
            return {'CANCELLED'}
 
        
        
                    
        return {'PASS_THROUGH'}
        
        
 
    def invoke(self, context, event):
        self.lmb= False
        
           
        if context.object:
            

            self.first_mouse_x = event.mouse_x
            
            
            
            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "No active object, could not finish")
            return {'CANCELLED'}


def register():
    bpy.utils.register_class(ModalOperator)


def unregister():
    bpy.utils.unregister_class(ModalOperator)


if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.object.modal_operator('INVOKE_DEFAULT')

hopefully I receive a solution to this.