diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2010-10-19 00:41:52 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2010-10-19 00:41:52 +0400 |
commit | f08a9dfd8a9b7d6ba10d764f087c5bbd3ff1013d (patch) | |
tree | 250e66feb6bab42b2f084fef6204cf0c2363bd0f /source | |
parent | 6e77dc19428a7887c6bee80f2485cb4628d03b78 (diff) |
Add operator for toggling cmd box on Windows.
Use through search menu (Toggle System Console) or
call bpy.ops.wm.toggle_console().
This is based on patch [#6927] Optional Console for Windows
by Fahrezal Effendi, submitted on July 10th, 2007 (!)
This paves the way for adding a command-line option to Blender to
toggle this cmd console, and for having a user preference option
for this. Command-line option I haven't added yet, as there seemed
to be problems with Python interpreter initialization (read: crashes).
This works by redirecting stdout and stderr to blenderlog.txt in user
temp directory (most likely %TEMP%\blenderlog.txt). When python problem
is fixed we can use this to always redirect stdout and stderr to this
logfile, making it also easier for us to ask users for this file in
bugreports.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 9 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 62 |
2 files changed, 68 insertions, 3 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 197f99b989e..2a36e91ac66 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -119,7 +119,7 @@ wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, char *idname, int type wmKeyMapItem *WM_keymap_add_menu(struct wmKeyMap *keymap, char *idname, int type, int val, int modifier, int keymodifier); -void WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); +void WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len); wmKeyMap *WM_keymap_list_find(ListBase *lb, char *idname, int spaceid, int regionid); @@ -220,7 +220,7 @@ struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType * int WM_operator_poll (struct bContext *C, struct wmOperatorType *ot); int WM_operator_call (struct bContext *C, struct wmOperator *op); int WM_operator_repeat (struct bContext *C, struct wmOperator *op); -int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct PointerRNA *properties); +int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct PointerRNA *properties); int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, int context, struct PointerRNA *properties, struct ReportList *reports); void WM_operator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *opstring); /* used for keymap and macro items */ @@ -342,6 +342,11 @@ void WM_clipboard_text_set(char *buf, int selection); void WM_progress_set(struct wmWindow *win, float progress); void WM_progress_clear(struct wmWindow *win); +#ifdef WIN32 + /* Windows System Console */ +void WM_toggle_console(struct bContext *C, short show); +#endif + #ifdef __cplusplus } #endif diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index de08c209d06..ccdb19adfce 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -31,7 +31,10 @@ #include <ctype.h> #include <stdio.h> #include <stddef.h> - +#ifdef WIN32 +#include <windows.h> +#include <io.h> +#endif #include "DNA_ID.h" #include "DNA_object_types.h" @@ -2007,6 +2010,60 @@ static void WM_OT_quit_blender(wmOperatorType *ot) ot->poll= WM_operator_winactive; } +/* *********************** */ +#ifdef WIN32 +static int console= 1; +void WM_toggle_console(bContext *C, short show) +{ + if(show) { + FILE *fp; + char fn[FILE_MAX]; + char tmp[FILE_MAXDIR]; + BLI_where_is_temp(tmp, 1); + BLI_make_file_string("/", fn, tmp, "blenderlog.txt"); + /* open the console */ + AllocConsole(); + + /* redirect stdin */ + fp= freopen(fn, "r", stdin); + SetStdHandle(STD_INPUT_HANDLE, (HANDLE)_get_osfhandle(_fileno(stdin))); + /* redirect stdout */ + fp= freopen(fn, "w", stdout); + SetStdHandle(STD_OUTPUT_HANDLE, (HANDLE)_get_osfhandle(_fileno(stdout))); + /* redirect stderr */ + fp= freopen(fn, "w", stderr); + SetStdHandle(STD_ERROR_HANDLE, (HANDLE)_get_osfhandle(_fileno(stderr))); + + console= 1; + } + else { + FreeConsole(); + console= 0; + } +} + +static int wm_toggle_console_op(bContext *C, wmOperator *op) +{ + if(console) { + WM_toggle_console(C, 0); + } + else { + WM_toggle_console(C, 1); + } + return OPERATOR_FINISHED; +} + +static void WM_OT_toggle_console(wmOperatorType *ot) +{ + ot->name= "Toggle System Console"; + ot->idname= "WM_OT_toggle_console"; + ot->description= "Toggle System Console"; + + ot->exec= wm_toggle_console_op; + ot->poll= WM_operator_winactive; +} +#endif + /* ************ default paint cursors, draw always around cursor *********** */ /* - returns handler to free @@ -3079,6 +3136,9 @@ void wm_operatortype_init(void) WM_operatortype_append(WM_OT_splash); WM_operatortype_append(WM_OT_search_menu); WM_operatortype_append(WM_OT_call_menu); +#ifdef WIN32 + WM_operatortype_append(WM_OT_toggle_console); +#endif #ifdef WITH_COLLADA /* XXX: move these */ |