1
$\begingroup$

The transformation-operators of blender are showing some hints/informations on the header of the 3D-View. This hints/informations are replacing the default layout-elements of the header (template_header(), VIEW3D_MT_editor_menus, template_header_3D(), …). I want to use this bar in my operators. But i can't find any information about this bar.

Does someone know how to uses this bar?
If not: Does someone know how this bar is named, so that i maybe can find the solution in the startup-scripts / blender c-code?

I might could prepend a very long label to VIEW3D_HT_header and remove it after executing/aborting the operator. But this seams to me like a messy workaround.

Thanks.

$\endgroup$
3
$\begingroup$

You do this by using Area.header_text_set()

Here is an example using the Modal Operator template:

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):
        context.area.header_text_set("Well see? Its working...") #add text to header
        if event.type == 'MOUSEMOVE':
            delta = self.first_mouse_x - event.mouse_x
            context.object.location.x = self.first_value + delta * 0.01

        elif event.type == 'LEFTMOUSE':            
            context.area.header_text_set() #on confirm restore header to default
            return {'FINISHED'}

        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            context.object.location.x = self.first_value
            context.area.header_text_set() #on exit restore header to default
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        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()

Note that using header_text_set without an argument restores the header to default.

$\endgroup$

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.