operator draw function working again. needed to add layout to the operator to give access to "self.layout" - like panels, headers and manu's have

This commit is contained in:
Campbell Barton 2009-12-24 21:17:14 +00:00
parent 4b8bc301c6
commit 5f4e24d599
23 changed files with 72 additions and 32 deletions

@ -1131,7 +1131,7 @@ class Export3DS(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
def poll(self, context): # Poll isnt working yet def poll(self, context): # Poll isnt working yet
return context.active_object != None return context.active_object != None

@ -3431,7 +3431,7 @@ class ExportFBX(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
bpy.types.register(ExportFBX) bpy.types.register(ExportFBX)

@ -178,7 +178,7 @@ class ExportMDD(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
bpy.types.register(ExportMDD) bpy.types.register(ExportMDD)

@ -985,7 +985,7 @@ class ExportOBJ(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}

@ -302,7 +302,7 @@ class ExportPLY(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout

@ -1238,7 +1238,7 @@ class ExportX3D(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
bpy.types.register(ExportX3D) bpy.types.register(ExportX3D)

@ -892,7 +892,7 @@ class BvhImporter(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
bpy.types.register(BvhImporter) bpy.types.register(BvhImporter)

@ -1164,7 +1164,7 @@ class IMPORT_OT_autodesk_3ds(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
bpy.types.register(IMPORT_OT_autodesk_3ds) bpy.types.register(IMPORT_OT_autodesk_3ds)

@ -1621,7 +1621,7 @@ class IMPORT_OT_obj(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
bpy.types.register(IMPORT_OT_obj) bpy.types.register(IMPORT_OT_obj)

@ -216,7 +216,7 @@ class WM_OT_properties_edit(bpy.types.Operator):
#return wm.invoke_props_popup(self, event) #return wm.invoke_props_popup(self, event)
wm.invoke_props_popup(self, event) wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
class WM_OT_properties_add(bpy.types.Operator): class WM_OT_properties_add(bpy.types.Operator):

@ -63,7 +63,7 @@ class SelectPattern(bpy.types.Operator):
wm = context.manager wm = context.manager
# return wm.invoke_props_popup(self, event) # return wm.invoke_props_popup(self, event)
wm.invoke_props_popup(self, event) wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout

@ -61,7 +61,7 @@ class AddPresetBase(bpy.types.Operator):
#return wm.invoke_props_popup(self, event) #return wm.invoke_props_popup(self, event)
wm.invoke_props_popup(self, event) wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
class AddPresetRender(AddPresetBase): class AddPresetRender(AddPresetBase):

@ -354,7 +354,7 @@ class WM_OT_doc_edit(bpy.types.Operator):
class_name, class_prop = doc_id.split('.') class_name, class_prop = doc_id.split('.')
if not doc_new: if not doc_new:
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
# check if this is an operator # check if this is an operator
op_name = class_name.upper() + '_OT_' + class_prop op_name = class_name.upper() + '_OT_' + class_prop
@ -367,7 +367,7 @@ class WM_OT_doc_edit(bpy.types.Operator):
rna = op_class.bl_rna rna = op_class.bl_rna
doc_orig = rna.description doc_orig = rna.description
if doc_orig == doc_new: if doc_orig == doc_new:
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
print("op - old:'%s' -> new:'%s'" % (doc_orig, doc_new)) print("op - old:'%s' -> new:'%s'" % (doc_orig, doc_new))
upload["title"] = 'OPERATOR %s:%s' % (doc_id, doc_orig) upload["title"] = 'OPERATOR %s:%s' % (doc_id, doc_orig)
@ -379,7 +379,7 @@ class WM_OT_doc_edit(bpy.types.Operator):
rna = getattr(bpy.types, class_name).bl_rna rna = getattr(bpy.types, class_name).bl_rna
doc_orig = rna.properties[class_prop].description doc_orig = rna.properties[class_prop].description
if doc_orig == doc_new: if doc_orig == doc_new:
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
print("rna - old:'%s' -> new:'%s'" % (doc_orig, doc_new)) print("rna - old:'%s' -> new:'%s'" % (doc_orig, doc_new))
upload["title"] = 'RNA %s:%s' % (doc_id, doc_orig) upload["title"] = 'RNA %s:%s' % (doc_id, doc_orig)

@ -38,7 +38,7 @@ class ExportSomeData(bpy.types.Operator):
if True: if True:
# File selector # File selector
wm.add_fileselect(self) # will run self.execute() wm.add_fileselect(self) # will run self.execute()
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
elif 0: elif 0:
# Redo popup # Redo popup
return wm.invoke_props_popup(self, event) # return wm.invoke_props_popup(self, event) #

@ -275,7 +275,7 @@ class AsScript(bpy.types.Operator):
self.properties.path = os.path.splitext(bpy.data.filename)[0] + "-" + bpy.utils.clean_name(obj.name) + ".py" self.properties.path = os.path.splitext(bpy.data.filename)[0] + "-" + bpy.utils.clean_name(obj.name) + ".py"
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
# operators that use the GUI # operators that use the GUI

@ -1741,7 +1741,7 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
wm = context.manager wm = context.manager
wm.add_fileselect(self) wm.add_fileselect(self)
return ('RUNNING_MODAL',) return {'RUNNING_MODAL'}
class WM_OT_keymap_edit(bpy.types.Operator): class WM_OT_keymap_edit(bpy.types.Operator):

@ -175,7 +175,9 @@ static void file_panel_operator(const bContext *C, Panel *pa)
int empty= 1, flag; int empty= 1, flag;
if(op->type->ui) { if(op->type->ui) {
op->type->ui((bContext*)C, op, pa->layout); op->layout= pa->layout;
op->type->ui((bContext*)C, op);
op->layout= NULL;
} }
else { else {
RNA_STRUCT_BEGIN(op->ptr, prop) { RNA_STRUCT_BEGIN(op->ptr, prop) {

@ -142,8 +142,11 @@ static void view3d_panel_operator_redo_buts(const bContext *C, Panel *pa, wmOper
} }
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
if(op->type->ui) if(op->type->ui) {
op->type->ui((bContext*)C, op, pa->layout); op->layout= pa->layout;
op->type->ui((bContext*)C, op);
op->layout= NULL;
}
else else
uiDefAutoButsRNA(C, pa->layout, &ptr, 1); uiDefAutoButsRNA(C, pa->layout, &ptr, 1);
} }

@ -279,6 +279,7 @@ typedef struct wmOperator {
ListBase macro; /* list of operators, can be a tree */ ListBase macro; /* list of operators, can be a tree */
struct wmOperator *opm; /* current running macro, not saved */ struct wmOperator *opm; /* current running macro, not saved */
struct uiLayout *layout; /* runtime for drawing */
short flag, pad[3]; short flag, pad[3];
} wmOperator; } wmOperator;

@ -675,6 +675,21 @@ static int operator_invoke(bContext *C, wmOperator *op, wmEvent *event)
return result; return result;
} }
static void operator_draw(bContext *C, wmOperator *op)
{
PointerRNA opr;
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(&CTX_wm_screen(C)->id, op->type->ext.srna, op, &opr);
func= RNA_struct_find_function(&opr, "draw");
RNA_parameter_list_create(&list, &opr, func);
RNA_parameter_set_lookup(&list, "context", &C);
op->type->ext.call(&opr, func, &list);
RNA_parameter_list_free(&list);
}
void operator_wrapper(wmOperatorType *ot, void *userdata); void operator_wrapper(wmOperatorType *ot, void *userdata);
@ -686,7 +701,7 @@ static StructRNA *rna_Operator_register(const bContext *C, ReportList *reports,
wmOperatorType dummyot = {0}; wmOperatorType dummyot = {0};
wmOperator dummyop= {0}; wmOperator dummyop= {0};
PointerRNA dummyotr; PointerRNA dummyotr;
int have_function[3]; int have_function[4];
/* setup dummy operator & operator type to store static properties in */ /* setup dummy operator & operator type to store static properties in */
dummyop.type= &dummyot; dummyop.type= &dummyot;
@ -737,6 +752,7 @@ static StructRNA *rna_Operator_register(const bContext *C, ReportList *reports,
dummyot.pyop_poll= (have_function[0])? operator_poll: NULL; dummyot.pyop_poll= (have_function[0])? operator_poll: NULL;
dummyot.exec= (have_function[1])? operator_exec: NULL; dummyot.exec= (have_function[1])? operator_exec: NULL;
dummyot.invoke= (have_function[2])? operator_invoke: NULL; dummyot.invoke= (have_function[2])? operator_invoke: NULL;
dummyot.ui= (have_function[3])? operator_draw: NULL;
WM_operatortype_append_ptr(operator_wrapper, (void *)&dummyot); WM_operatortype_append_ptr(operator_wrapper, (void *)&dummyot);
@ -778,6 +794,9 @@ static void rna_def_operator(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Properties", ""); RNA_def_property_ui_text(prop, "Properties", "");
RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL); RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL);
prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "UILayout");
/* Registration */ /* Registration */
prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE); prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "type->idname"); RNA_def_property_string_sdna(prop, NULL, "type->idname");

@ -205,14 +205,14 @@ void RNA_api_operator(StructRNA *srna)
/* poll */ /* poll */
func= RNA_def_function(srna, "poll", NULL); func= RNA_def_function(srna, "poll", NULL);
RNA_def_function_ui_description(func, "Test if the operator can be called or not."); RNA_def_function_ui_description(func, "Test if the operator can be called or not.");
RNA_def_function_flag(func, FUNC_REGISTER|FUNC_REGISTER_OPTIONAL); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", "")); RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
RNA_def_pointer(func, "context", "Context", "", ""); RNA_def_pointer(func, "context", "Context", "", "");
/* exec */ /* exec */
func= RNA_def_function(srna, "execute", NULL); func= RNA_def_function(srna, "execute", NULL);
RNA_def_function_ui_description(func, "Execute the operator."); RNA_def_function_ui_description(func, "Execute the operator.");
RNA_def_function_flag(func, FUNC_REGISTER); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
RNA_def_pointer(func, "context", "Context", "", ""); RNA_def_pointer(func, "context", "Context", "", "");
parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name? parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
@ -222,13 +222,19 @@ void RNA_api_operator(StructRNA *srna)
/* invoke */ /* invoke */
func= RNA_def_function(srna, "invoke", NULL); func= RNA_def_function(srna, "invoke", NULL);
RNA_def_function_ui_description(func, "Invoke the operator."); RNA_def_function_ui_description(func, "Invoke the operator.");
RNA_def_function_flag(func, FUNC_REGISTER); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
RNA_def_pointer(func, "context", "Context", "", ""); RNA_def_pointer(func, "context", "Context", "", "");
RNA_def_pointer(func, "event", "Event", "", ""); RNA_def_pointer(func, "event", "Event", "", "");
parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name? parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
RNA_def_property_flag(parm, PROP_ENUM_FLAG); RNA_def_property_flag(parm, PROP_ENUM_FLAG);
RNA_def_function_return(func, parm); RNA_def_function_return(func, parm);
/* draw */
func= RNA_def_function(srna, "draw", NULL);
RNA_def_function_ui_description(func, "Draw function for the operator.");
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
RNA_def_pointer(func, "context", "Context", "", "");
} }
void RNA_api_keyconfig(StructRNA *srna) void RNA_api_keyconfig(StructRNA *srna)

@ -383,7 +383,7 @@ typedef struct wmOperatorType {
int (*poll)(struct bContext *); int (*poll)(struct bContext *);
/* optional panel for redo and repeat, autogenerated if not set */ /* optional panel for redo and repeat, autogenerated if not set */
void (*ui)(struct bContext *, struct wmOperator *, struct uiLayout *); void (*ui)(struct bContext *, struct wmOperator *);
/* rna for properties */ /* rna for properties */
struct StructRNA *srna; struct StructRNA *srna;

@ -774,8 +774,11 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, 20, style); layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, 20, style);
uiItemL(layout, op->type->name, 0); uiItemL(layout, op->type->name, 0);
if(op->type->ui) if(op->type->ui) {
op->type->ui((bContext*)C, op, layout); op->layout= layout;
op->type->ui((bContext*)C, op);
op->layout= NULL;
}
else else
uiDefAutoButsRNA(C, layout, &ptr, columns); uiDefAutoButsRNA(C, layout, &ptr, columns);
@ -808,8 +811,11 @@ static uiBlock *wm_operator_create_ui(bContext *C, ARegion *ar, void *userData)
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr); RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, style); layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, style);
if(op->type->ui) if(op->type->ui) {
op->type->ui((bContext*)C, op, layout); op->layout= layout;
op->type->ui((bContext*)C, op);
op->layout= NULL;
}
uiPopupBoundsBlock(block, 4.0f, 0, 0); uiPopupBoundsBlock(block, 4.0f, 0, 0);
uiEndBlock(C, block); uiEndBlock(C, block);
@ -862,8 +868,11 @@ static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style); layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
uiItemL(layout, op->type->name, 0); uiItemL(layout, op->type->name, 0);
if(op->type->ui) if(op->type->ui) {
op->type->ui(C, op, layout); op->layout= layout;
op->type->ui(C, op);
op->layout= NULL;
}
else else
uiDefAutoButsRNA(C, layout, op->ptr, 2); uiDefAutoButsRNA(C, layout, op->ptr, 2);