Operator help: drawing callback

Ok. I am writing a operator (my first one in python, made a few in C already). I am having two problems.

The first, when I add a callback to do some drawing, it doesnt ever get in that callback. I have just honestly taken the callback example from other scripts. I dont honestly know if the (self, context) and ‘POST_PIXEL’ are doing what i want for sure and what my other options are for.

Secondly. I am writing this operator for the Text Editor. The operator for the Text Editor space that gets the text input MUST be last, or else the text input wont work. How do I add the operator to the keymap and make sure its not last (ie first, middle, second to last, just not last). Are the operators in an array that can be rearranged? (i think this is possible)

Here is the code…

import bpy
from bpy.props import *
import bgl
import blf

def draw_callback(self, context):
    printf("Drawing")
    # draw some text
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    blf.position(0, context.mouse_x, context.mouse_y, 0)
    blf.size(0, 24, 72)
    blf.draw(0, "Hello Word ")

class MyOperator(bpy.types.Operator):
    ''''''
    bl_idname = "text.myoperator"
    bl_label = "myoperator"
    bl_description = "draws..."

    @classmethod
    def poll(cls, context):
        if context.area.type != 'TEXT_EDITOR':
            return False
        else:
            return context.space_data.text != None
    
    def modal(self, context, event):
        print(event.type)
        if event.type == 'LEFTMOUSE':
            print("Done")
            context.region.callback_remove(self._handle)
            return {'FINISHED'}

        elif event.type in ('RIGHTMOUSE', 'ESC'):
            print("Cancelled")
            context.region.callback_remove(self._handle)
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        print("Invoked")
        
        if not context.space_data.text:
            self.report({'WARNING'}, "No active text, could not finish")
            return {'CANCELLED'}
        else:        
            print("Good!")
            context.window_manager.modal_handler_add(self)
            self._handle = context.region.callback_add(draw_callback, (self, context), 'POST_PIXEL')
            return {'RUNNING_MODAL'}
        
def register():
    km = bpy.context.window_manager.keyconfigs.default.keymaps['Text']
    kmi = km.items.new('text.myoperator', 'SPACE', 'PRESS', ctrl=True)

def unregister():
    km = bpy.context.window_manager.keyconfigs.default.keymaps['Text']
    kmi = km.items["text.myoperator"]
    km.items.remove(kmi)

if __name__ == "__main__":
    register()

Thanks!

The 3d view is the only region (area?) that uses callbacks.

So is there any way that I could do what I’m wanting accomplished? Which is being able to draw on the Text Editor area/region/screen/whatever and draw according to the users input.