forked from bartvdbraak/blender
Started operator registration with python. This is a piece of cake!
Made space_script header area customizable with python - need Brecht to check this. Added a base for operator registration: a menu in Scripts Window with two items "Reload Scripts" and "Export". The former will do guess what? The latter will be populated with submenu items each corresponding to an exporter :)
This commit is contained in:
parent
a892799db7
commit
6563e9ff8a
73
release/ui/space_script.py
Normal file
73
release/ui/space_script.py
Normal file
@ -0,0 +1,73 @@
|
||||
import bpy
|
||||
|
||||
class SCRIPT_HT_header(bpy.types.Header):
|
||||
__space_type__ = "SCRIPTS_WINDOW"
|
||||
__idname__ = "SCRIPT_HT_header"
|
||||
|
||||
def draw(self, context):
|
||||
st = context.space_data
|
||||
layout = self.layout
|
||||
|
||||
layout.template_header(context)
|
||||
|
||||
if context.area.show_menus:
|
||||
row = layout.row(align=True)
|
||||
row.itemM(context, "SCRIPT_MT_scripts")
|
||||
|
||||
# draw menu item to reload scripts from
|
||||
# release/io
|
||||
#
|
||||
# it should call operator or
|
||||
# a func that will:
|
||||
# for each .py file in the dir,
|
||||
# import/reload module, in the module:
|
||||
# find subclasses of bpy.types.Operator,
|
||||
# for each subclass create menus under "Export"
|
||||
# with (row.)itemO
|
||||
#
|
||||
# for interface api documentation, see
|
||||
# see source/blender/editors/interface/interface_api.c
|
||||
#
|
||||
# hint: reloading ui scripts in scripts window is Shift+P
|
||||
|
||||
|
||||
class SCRIPT_MT_scripts(bpy.types.Menu):
|
||||
__space_type__ = "SCRIPTS_WINDOW"
|
||||
__label__ = "Scripts"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.column()
|
||||
layout.itemM(context, "SCRIPT_MT_export")
|
||||
layout.itemO("SCRIPT_OT_reload_scripts")
|
||||
|
||||
class SCRIPT_MT_export(bpy.types.Menu):
|
||||
__space_type__ = "SCRIPTS_WINDOW"
|
||||
__label__ = "Export"
|
||||
|
||||
def draw(self, context):
|
||||
pass
|
||||
|
||||
class SCRIPT_OT_reload_scripts(bpy.types.Operator):
|
||||
__label__ = 'Reload Scripts'
|
||||
|
||||
def exec(self, context):
|
||||
print("SCRIPT_OT_reload_scripts: exec")
|
||||
return 'FINISHED'
|
||||
|
||||
def invoke(self, context, event):
|
||||
print("SCRIPT_OT_reload_scripts: invoke")
|
||||
return self.exec(context)
|
||||
|
||||
def poll(self, context):
|
||||
pass
|
||||
|
||||
|
||||
bpy.types.register(SCRIPT_HT_header)
|
||||
bpy.types.register(SCRIPT_MT_scripts)
|
||||
bpy.types.register(SCRIPT_MT_export)
|
||||
|
||||
if (hasattr(bpy.ops, "SCRIPT_OT_reload_scripts")):
|
||||
bpy.ops.remove(bpy.ops.SCRIPT_OT_reload_scripts)
|
||||
|
||||
bpy.ops.add(SCRIPT_OT_reload_scripts)
|
@ -175,29 +175,32 @@ static void script_main_area_draw(const bContext *C, ARegion *ar)
|
||||
/* add handlers, stuff you only do once or on area/region changes */
|
||||
static void script_header_area_init(wmWindowManager *wm, ARegion *ar)
|
||||
{
|
||||
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
|
||||
/* UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); */
|
||||
ED_region_header_init(ar);
|
||||
}
|
||||
|
||||
static void script_header_area_draw(const bContext *C, ARegion *ar)
|
||||
{
|
||||
float col[3];
|
||||
/* float col[3]; */
|
||||
|
||||
/* clear */
|
||||
if(ED_screen_area_active(C))
|
||||
UI_GetThemeColor3fv(TH_HEADER, col);
|
||||
else
|
||||
UI_GetThemeColor3fv(TH_HEADERDESEL, col);
|
||||
/* /\* clear *\/ */
|
||||
/* if(ED_screen_area_active(C)) */
|
||||
/* UI_GetThemeColor3fv(TH_HEADER, col); */
|
||||
/* else */
|
||||
/* UI_GetThemeColor3fv(TH_HEADERDESEL, col); */
|
||||
|
||||
glClearColor(col[0], col[1], col[2], 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
/* glClearColor(col[0], col[1], col[2], 0.0); */
|
||||
/* glClear(GL_COLOR_BUFFER_BIT); */
|
||||
|
||||
/* set view2d view matrix for scrolling (without scrollers) */
|
||||
UI_view2d_view_ortho(C, &ar->v2d);
|
||||
/* /\* set view2d view matrix for scrolling (without scrollers) *\/ */
|
||||
/* UI_view2d_view_ortho(C, &ar->v2d); */
|
||||
|
||||
script_header_buttons(C, ar);
|
||||
/* script_header_buttons(C, ar); */
|
||||
|
||||
/* restore view matrix? */
|
||||
UI_view2d_view_restore(C);
|
||||
/* /\* restore view matrix? *\/ */
|
||||
/* UI_view2d_view_restore(C); */
|
||||
|
||||
ED_region_header(C, ar);
|
||||
}
|
||||
|
||||
static void script_main_area_listener(ARegion *ar, wmNotifier *wmn)
|
||||
|
Loading…
Reference in New Issue
Block a user