Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-04-22 22:39:44 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-04-22 22:39:44 +0400
commitaf02a0aa4e0b80c3c1154e7be095f4a387f81179 (patch)
tree3f714e683c96929cc4e44962570860ab0f635bc9 /source/blender/makesrna
parent643d59bb9bf3bdd46f41a0b8c79384146629f9c8 (diff)
UI
* Headers and menus can now be created in python. * Replaced the uiMenuItem functions to create menus with equivalent uiItem functions using a layout, removing duplicated code. * More uiItem functions are now exposed to python. * The text editor header, panels and one of its menus are now created in space_text.py. * Buttons window data context icon new changes depending on active object. Issues * Icons are not wrapped yet, hardcoded ints at the moment. * The ID browse template is unfinished.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/rna_context.c12
-rw-r--r--source/blender/makesrna/intern/rna_screen.c2
-rw-r--r--source/blender/makesrna/intern/rna_space.c2
-rw-r--r--source/blender/makesrna/intern/rna_text.c13
-rw-r--r--source/blender/makesrna/intern/rna_ui.c159
5 files changed, 180 insertions, 8 deletions
diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c
index d3089917649..ece5b6cc1f9 100644
--- a/source/blender/makesrna/intern/rna_context.c
+++ b/source/blender/makesrna/intern/rna_context.c
@@ -37,31 +37,31 @@
static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
{
bContext *C= (bContext*)ptr->data;
- return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_manager(C));
+ return rna_pointer_inherit_refine(ptr, &RNA_WindowManager, CTX_wm_manager(C));
}
/*static PointerRNA rna_Context_window_get(PointerRNA *ptr)
{
bContext *C= (bContext*)ptr->data;
- return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_window(C));
+ return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C));
}*/
static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
{
bContext *C= (bContext*)ptr->data;
- return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_screen(C));
+ return rna_pointer_inherit_refine(ptr, &RNA_Screen, CTX_wm_screen(C));
}
static PointerRNA rna_Context_area_get(PointerRNA *ptr)
{
bContext *C= (bContext*)ptr->data;
- return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_area(C));
+ return rna_pointer_inherit_refine(ptr, &RNA_Area, CTX_wm_area(C));
}
static PointerRNA rna_Context_space_data_get(PointerRNA *ptr)
{
bContext *C= (bContext*)ptr->data;
- return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_space_data(C));
+ return rna_pointer_inherit_refine(ptr, &RNA_Space, CTX_wm_space_data(C));
}
static PointerRNA rna_Context_region_get(PointerRNA *ptr)
@@ -73,7 +73,7 @@ static PointerRNA rna_Context_region_get(PointerRNA *ptr)
/*static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
{
bContext *C= (bContext*)ptr->data;
- return rna_pointer_inherit_refine(ptr, &RNA_Region, CTX_wm_region_data(C));
+ return rna_pointer_inherit_refine(ptr, &RNA_RegionData, CTX_wm_region_data(C));
}*/
static PointerRNA rna_Context_main_get(PointerRNA *ptr)
diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c
index 5be3130609c..034fd603367 100644
--- a/source/blender/makesrna/intern/rna_screen.c
+++ b/source/blender/makesrna/intern/rna_screen.c
@@ -37,7 +37,7 @@ EnumPropertyItem region_type_items[] = {
{RGN_TYPE_HEADER, "HEADER", "Header", ""},
{RGN_TYPE_CHANNELS, "CHANNELS", "Channels", ""},
{RGN_TYPE_TEMPORARY, "TEMPORARY", "Temporary", ""},
- {RGN_TYPE_UI, "BUTTONS_WINDOW", "Window", ""},
+ {RGN_TYPE_UI, "UI", "UI", ""},
{0, NULL, NULL, NULL}};
#ifdef RNA_RUNTIME
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 9950d70af24..229a260efce 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -341,7 +341,7 @@ static void rna_def_space_text(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Text", "Text displayed and edited in this space.");
RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceTextEditor_text_set");
- RNA_def_property_update(prop, NC_TEXT|ND_CURSOR, NULL);
+ RNA_def_property_update(prop, NC_TEXT|NA_EDITED, NULL);
/* display */
prop= RNA_def_property(srna, "syntax_highlight", PROP_BOOLEAN, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_text.c b/source/blender/makesrna/intern/rna_text.c
index 838822119e8..3dacd4c0898 100644
--- a/source/blender/makesrna/intern/rna_text.c
+++ b/source/blender/makesrna/intern/rna_text.c
@@ -40,6 +40,8 @@
#ifdef RNA_RUNTIME
+int text_file_modified(Text *text);
+
static void rna_Text_filename_get(PointerRNA *ptr, char *value)
{
Text *text= (Text*)ptr->data;
@@ -69,6 +71,12 @@ static void rna_Text_filename_set(PointerRNA *ptr, const char *value)
text->name= NULL;
}
+static int rna_Text_modified_get(PointerRNA *ptr)
+{
+ Text *text= (Text*)ptr->data;
+ return text_file_modified(text);
+}
+
static void rna_TextLine_line_get(PointerRNA *ptr, char *value)
{
TextLine *line= (TextLine*)ptr->data;
@@ -174,6 +182,11 @@ static void rna_def_text(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Dirty", "Text file has been edited since last save.");
+ prop= RNA_def_property(srna, "modified", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_Text_modified_get", NULL);
+ RNA_def_property_ui_text(prop, "Modified", "Text file on disk is different than the one in memory.");
+
prop= RNA_def_property(srna, "memory", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISMEM);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index 4ad5273dd5d..405ae9a0f74 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -276,6 +276,121 @@ static StructRNA* rna_Header_refine(struct PointerRNA *htr)
return (hdr->type)? hdr->type->py_srna: &RNA_Header;
}
+/* Menu */
+
+static int menu_poll(const bContext *C, MenuType *pt)
+{
+ PointerRNA ptr;
+ ParameterList *list;
+ FunctionRNA *func;
+ void *ret;
+ int visible;
+
+ RNA_pointer_create(NULL, pt->py_srna, NULL, &ptr); /* dummy */
+ func= RNA_struct_find_function(&ptr, "poll");
+
+ list= RNA_parameter_list_create(&ptr, func);
+ RNA_parameter_set_lookup(list, "context", &C);
+ pt->py_call(&ptr, func, list);
+
+ RNA_parameter_get_lookup(list, "visible", &ret);
+ visible= *(int*)ret;
+
+ RNA_parameter_list_free(list);
+
+ return visible;
+}
+
+static void menu_draw(const bContext *C, Menu *hdr)
+{
+ PointerRNA mtr;
+ ParameterList *list;
+ FunctionRNA *func;
+
+ RNA_pointer_create(&CTX_wm_screen(C)->id, hdr->type->py_srna, hdr, &mtr);
+ func= RNA_struct_find_function(&mtr, "draw");
+
+ list= RNA_parameter_list_create(&mtr, func);
+ RNA_parameter_set_lookup(list, "context", &C);
+ hdr->type->py_call(&mtr, func, list);
+
+ RNA_parameter_list_free(list);
+}
+
+static void rna_Menu_unregister(const bContext *C, StructRNA *type)
+{
+ ARegionType *art;
+ MenuType *mt= RNA_struct_blender_type_get(type);
+
+ if(!mt)
+ return;
+ if(!(art=region_type_find(NULL, mt->space_type, RGN_TYPE_HEADER)))
+ return;
+
+ BLI_freelinkN(&art->menutypes, mt);
+ RNA_struct_free(&BLENDER_RNA, type);
+
+ /* update while blender is running */
+ if(C)
+ WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+}
+
+static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void *data, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+{
+ ARegionType *art;
+ MenuType *mt, dummymt = {0};
+ Menu dummymenu= {0};
+ PointerRNA dummymtr;
+ int have_function[2];
+
+ /* setup dummy menu & menu type to store static properties in */
+ dummymenu.type= &dummymt;
+ RNA_pointer_create(NULL, &RNA_Menu, &dummymenu, &dummymtr);
+
+ /* validate the python class */
+ if(validate(&dummymtr, data, have_function) != 0)
+ return NULL;
+
+ if(!(art=region_type_find(reports, dummymt.space_type, RGN_TYPE_HEADER)))
+ return NULL;
+
+ /* check if we have registered this menu type before, and remove it */
+ for(mt=art->menutypes.first; mt; mt=mt->next) {
+ if(strcmp(mt->idname, dummymt.idname) == 0) {
+ if(mt->py_srna)
+ rna_Menu_unregister(C, mt->py_srna);
+ break;
+ }
+ }
+
+ /* create a new menu type */
+ mt= MEM_callocN(sizeof(MenuType), "python buttons menu");
+ memcpy(mt, &dummymt, sizeof(dummymt));
+
+ mt->py_srna= RNA_def_struct(&BLENDER_RNA, mt->idname, "Menu");
+ mt->py_data= data;
+ mt->py_call= call;
+ mt->py_free= free;
+ RNA_struct_blender_type_set(mt->py_srna, mt);
+
+ mt->poll= (have_function[0])? menu_poll: NULL;
+ mt->draw= (have_function[1])? menu_draw: NULL;
+
+ BLI_addtail(&art->menutypes, mt);
+
+ /* update while blender is running */
+ if(C)
+ WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
+
+ return mt->py_srna;
+}
+
+static StructRNA* rna_Menu_refine(struct PointerRNA *mtr)
+{
+ Menu *hdr= (Menu*)mtr->data;
+ return (hdr->type)? hdr->type->py_srna: &RNA_Menu;
+}
+
#else
static void rna_def_ui_layout(BlenderRNA *brna)
@@ -373,11 +488,55 @@ static void rna_def_header(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_REGISTER);
}
+static void rna_def_menu(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+ FunctionRNA *func;
+
+ srna= RNA_def_struct(brna, "Menu", NULL);
+ RNA_def_struct_ui_text(srna, "Menu", "Editor menu containing buttons.");
+ RNA_def_struct_sdna(srna, "Menu");
+ RNA_def_struct_refine_func(srna, "rna_Menu_refine");
+ RNA_def_struct_register_funcs(srna, "rna_Menu_register", "rna_Menu_unregister");
+
+ /* poll */
+ func= RNA_def_function(srna, "poll", NULL);
+ RNA_def_function_ui_description(func, "Test if the menu is visible or not.");
+ RNA_def_function_flag(func, FUNC_REGISTER|FUNC_REGISTER_OPTIONAL);
+ RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
+ RNA_def_pointer(func, "context", "Context", "", "");
+
+ /* draw */
+ func= RNA_def_function(srna, "draw", NULL);
+ RNA_def_function_ui_description(func, "Draw buttons into the menu UI layout.");
+ RNA_def_function_flag(func, FUNC_REGISTER);
+ RNA_def_pointer(func, "context", "Context", "", "");
+
+ prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "UILayout");
+
+ /* registration */
+ prop= RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->idname");
+ RNA_def_property_flag(prop, PROP_REGISTER);
+
+ prop= RNA_def_property(srna, "label", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->label");
+ RNA_def_property_flag(prop, PROP_REGISTER);
+
+ prop= RNA_def_property(srna, "space_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "type->space_type");
+ RNA_def_property_enum_items(prop, space_type_items);
+ RNA_def_property_flag(prop, PROP_REGISTER);
+}
+
void RNA_def_ui(BlenderRNA *brna)
{
rna_def_ui_layout(brna);
rna_def_panel(brna);
rna_def_header(brna);
+ rna_def_menu(brna);
}
#endif