From f9fa705cd3c6de502e0d15c182dd6eddd99ede3f Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Tue, 25 May 2004 06:08:49 +0000 Subject: [PATCH] * Added support for python scripts to register themselves in the UV/Image editor 'UVs' menu Script authors can use: Group: 'UV' in the headers of their scripts to let them appear in this menu. * Updated the UV Face Layout script to reside in the UVs menu, rather than the (incorrect) File->Export menu. --- release/scripts/uv_export.py | 6 +++--- source/blender/python/BPY_menus.c | 3 +++ source/blender/python/BPY_menus.h | 1 + source/blender/src/header_image.c | 26 +++++++++++++++++++++++--- source/blender/src/header_info.c | 15 ++++++--------- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/release/scripts/uv_export.py b/release/scripts/uv_export.py index fe685d1e614..ef224b6eba8 100644 --- a/release/scripts/uv_export.py +++ b/release/scripts/uv_export.py @@ -1,10 +1,10 @@ #!BPY """ -Name: 'UV Face Layout' +Name: 'Save UV Face Layout...' Blender: 232 -Group: 'Export' -Tooltip: 'Export the UV Faces layout of the selected object to tga' +Group: 'UV' +Tooltip: 'Export the UV face layout of the selected object to a .TGA file' """ # -------------------------------------------------------------------------- diff --git a/source/blender/python/BPY_menus.c b/source/blender/python/BPY_menus.c index b1d392f3b7f..f2879f654c1 100644 --- a/source/blender/python/BPY_menus.c +++ b/source/blender/python/BPY_menus.c @@ -82,6 +82,7 @@ static int bpymenu_group_atoi (char *str) else if (!strcmp(str, "Wizards")) return PYMENU_WIZARDS; else if (!strcmp(str, "Animation")) return PYMENU_ANIMATION; else if (!strcmp(str, "Materials")) return PYMENU_MATERIALS; + else if (!strcmp(str, "UV")) return PYMENU_UV; /* "Misc" or an inexistent group name: use misc */ else return PYMENU_MISC; } @@ -110,6 +111,8 @@ char *BPyMenu_group_itoa (short menugroup) case PYMENU_MATERIALS: return "Materials"; break; + case PYMENU_UV: + return "UV"; case PYMENU_MISC: return "Misc"; break; diff --git a/source/blender/python/BPY_menus.h b/source/blender/python/BPY_menus.h index b9826ed4bc2..5e7139f213e 100644 --- a/source/blender/python/BPY_menus.h +++ b/source/blender/python/BPY_menus.h @@ -87,6 +87,7 @@ typedef enum { PYMENU_IMPORT, PYMENU_EXPORT, PYMENU_ANIMATION, + PYMENU_UV, /* UV editing tools, to go in UV/Image editor space, 'UV' menu */ PYMENU_TOTAL } PYMENUHOOKS; diff --git a/source/blender/src/header_image.c b/source/blender/src/header_image.c index 7a45fc2d961..93dd39ef79c 100644 --- a/source/blender/src/header_image.c +++ b/source/blender/src/header_image.c @@ -81,6 +81,8 @@ #include "BSE_filesel.h" #include "BSE_headerbuttons.h" +#include "BPY_menus.h" + #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -568,9 +570,9 @@ static void do_image_imagemenu(void *arg, int event) if(G.sima->image) strcpy(name, G.sima->image->name); else strcpy(name, U.textudir); if(G.qual==LR_CTRLKEY) - activate_imageselect(FILE_SPECIAL, "SELECT IMAGE", name, load_space_image); + activate_imageselect(FILE_SPECIAL, "Open Image", name, load_space_image); else - activate_fileselect(FILE_SPECIAL, "SELECT IMAGE", name, load_space_image); + activate_fileselect(FILE_SPECIAL, "Open Image", name, load_space_image); break; case 1: /* Replace */ if(G.sima->image) strcpy(name, G.sima->image->name); @@ -813,7 +815,13 @@ static uiBlock *image_uvs_transformmenu(void *arg_unused) static void do_image_uvsmenu(void *arg, int event) { - switch(event) + extern int BPY_menu_do_python(short menutype, int event); // BPY_interface.c + ScrArea *sa; + + /* events >=20 are registered bpython scripts */ + if (event >= 20) BPY_menu_do_python(PYMENU_UV, event - 20); + + else switch(event) { case 1: /* UVs Constrained Rectangular */ if(G.sima->flag & SI_BE_SQUARE) G.sima->flag &= ~SI_BE_SQUARE; @@ -846,6 +854,8 @@ static uiBlock *image_uvsmenu(void *arg_unused) { uiBlock *block; short yco= 0, menuwidth=120; + BPyMenu *pym; + int i = 0; block= uiNewBlock(&curarea->uiblocks, "image_uvsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin); uiBlockSetButmFunc(block, do_image_uvsmenu, NULL); @@ -878,6 +888,16 @@ static uiBlock *image_uvsmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + /* note that we acount for the 3 previous entries with i+3: */ + for (pym = BPyMenuTable[PYMENU_UV]; pym; pym = pym->next, i++) { + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, pym->name, 0, yco-=20, menuwidth, 19, + NULL, 0.0, 0.0, 1, i+20, + pym->tooltip?pym->tooltip:pym->filename); + } + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBlockBut(block, image_uvs_showhidemenu, NULL, ICON_RIGHTARROW_THIN, "Show/Hide Faces", 0, yco-=20, menuwidth, 19, ""); if(curarea->headertype==HEADERTOP) { diff --git a/source/blender/src/header_info.c b/source/blender/src/header_info.c index 5cbaa7b6c34..e8127931fed 100644 --- a/source/blender/src/header_info.c +++ b/source/blender/src/header_info.c @@ -698,11 +698,9 @@ static uiBlock *info_file_importmenu(void *arg_unused) //uiBlockSetXOfs(block, -50); // offset to parent button for (pym = BPyMenuTable[PYMENU_IMPORT]; pym; pym = pym->next, i++) { - uiDefBut(block, BUTM, 1, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i, pym->tooltip?pym->tooltip:pym->filename); } - uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); - uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -751,19 +749,18 @@ static uiBlock *info_file_exportmenu(void *arg_unused) uiBlockSetButmFunc(block, do_info_file_exportmenu, NULL); //uiBlockSetXOfs(block, -50); // offset to parent button - uiDefBut(block, BUTM, 1, "VRML 1.0...|Ctrl F2", + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "VRML 1.0...|Ctrl F2", 0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 0, ""); - uiDefBut(block, BUTM, 1, "DXF...|Shift F2", + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "DXF...|Shift F2", 0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 1, ""); - uiDefBut(block, BUTM, 1, "Videoscape...|Alt W", + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Videoscape...|Alt W", 0, yco-=20, 120, 19, NULL, 0.0, 0.0, 1, 2, ""); - uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, - 0.0, 0.0, 0, 0, ""); + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); /* note that we acount for the 3 previous entries with i+3: */ for (pym = BPyMenuTable[PYMENU_EXPORT]; pym; pym = pym->next, i++) { - uiDefBut(block, BUTM, 1, pym->name, 0, yco-=20, menuwidth, 19, + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, pym->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, i+3, pym->tooltip?pym->tooltip:pym->filename); }