Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Mon, 3 Sep 2018 02:48:30 +0000 (12:48 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 3 Sep 2018 02:48:51 +0000 (12:48 +1000)
1  2 
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_region_tooltip.c
source/blender/editors/util/numinput.c
source/blender/python/BPY_extern.h
source/blender/python/generic/py_capi_utils.h
source/blender/python/intern/bpy_interface.c

@@@ -310,229 -313,6 +310,229 @@@ static void ui_tooltip_region_free_cb(A
  /** \name ToolTip Creation
   * \{ */
  
-               if (BPY_execute_string_as_string(C, expr, true, &expr_result)) {
 +static bool ui_tooltip_data_append_from_keymap(
 +        bContext *C, uiTooltipData *data,
 +        wmKeyMap *keymap)
 +{
 +      const int fields_len_init = data->fields_len;
 +      char buf[512];
 +
 +      for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
 +              wmOperatorType *ot = WM_operatortype_find(kmi->idname, true);
 +              if (ot != NULL) {
 +                      /* Tip */
 +                      {
 +                              uiTooltipField *field = text_field_add(
 +                                      data, &(uiTooltipFormat){
 +                                          .style = UI_TIP_STYLE_NORMAL,
 +                                          .color_id = UI_TIP_LC_MAIN,
 +                                          .is_pad = true,
 +                                      });
 +                              field->text = BLI_strdup(ot->description[0] ? ot->description : ot->name);
 +                      }
 +                      /* Shortcut */
 +                      {
 +                              uiTooltipField *field = text_field_add(
 +                                      data, &(uiTooltipFormat){
 +                                          .style = UI_TIP_STYLE_NORMAL,
 +                                          .color_id = UI_TIP_LC_NORMAL,
 +                                      });
 +                              bool found = false;
 +                              if (WM_keymap_item_to_string(kmi, false, buf, sizeof(buf))) {
 +                                      found = true;
 +                              }
 +                              field->text = BLI_sprintfN(TIP_("Shortcut: %s"), found ? buf : "None");
 +                      }
 +
 +                      /* Python */
 +                      if (U.flag & USER_TOOLTIPS_PYTHON) {
 +                              uiTooltipField *field = text_field_add(
 +                                      data, &(uiTooltipFormat){
 +                                          .style = UI_TIP_STYLE_NORMAL,
 +                                          .color_id = UI_TIP_LC_PYTHON,
 +                                      });
 +                              char *str = WM_operator_pystring_ex(C, NULL, false, false, ot, kmi->ptr);
 +                              WM_operator_pystring_abbreviate(str, 32);
 +                              field->text = BLI_sprintfN(TIP_("Python: %s"), str);
 +                              MEM_freeN(str);
 +                      }
 +              }
 +      }
 +
 +      return (fields_len_init != data->fields_len);
 +}
 +
 +
 +/**
 + * Special tool-system exception.
 + */
 +static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but)
 +{
 +      if (but->optype == NULL) {
 +              return NULL;
 +      }
 +
 +      if (!STREQ(but->optype->idname, "WM_OT_tool_set_by_name")) {
 +              return NULL;
 +      }
 +
 +      char tool_name[MAX_NAME];
 +      RNA_string_get(but->opptr, "name", tool_name);
 +      BLI_assert(tool_name[0] != '\0');
 +
 +      /* We have a tool, now extract the info. */
 +      uiTooltipData *data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
 +
 +#ifdef WITH_PYTHON
 +      /* it turns out to be most simple to do this via Python since C
 +       * doesn't have access to information about non-active tools.
 +       */
 +      char expr[256];
 +
 +      /* Tip. */
 +      {
 +              SNPRINTF(
 +                      expr,
 +                      "__import__('bl_ui').space_toolsystem_common.description_from_name("
 +                      "__import__('bpy').context, "
 +                      "__import__('bpy').context.space_data.type, "
 +                      "'%s') + '.'",
 +                      tool_name);
 +
 +              char *expr_result = NULL;
-                               if (BPY_execute_string_as_intptr(C, expr_ptr, true, &expr_result)) {
++              if (BPY_execute_string_as_string(C, NULL, expr, true, &expr_result)) {
 +                      if (!STREQ(expr_result, ".")) {
 +                              uiTooltipField *field = text_field_add(
 +                                      data, &(uiTooltipFormat){
 +                                          .style = UI_TIP_STYLE_NORMAL,
 +                                          .color_id = UI_TIP_LC_MAIN,
 +                                          .is_pad = true,
 +                                      });
 +                              field->text = expr_result;
 +                      }
 +                      else {
 +                              MEM_freeN(expr_result);
 +                      }
 +              }
 +              else {
 +                      BLI_assert(0);
 +              }
 +      }
 +
 +      /* Shortcut. */
 +      {
 +              /* There are two kinds of shortcuts, either direct access to the tool,
 +               * when a key is bound directly to the tool (as if the toolbar button is pressed),
 +               * or when a key is assigned to the operator it's self (bypassing the tool).
 +               *
 +               * Either way case it's useful to show the shortcut.
 +               */
 +              char *shortcut = NULL;
 +
 +              {
 +                      uiStringInfo op_keymap = {BUT_GET_OP_KEYMAP, NULL};
 +                      UI_but_string_info_get(C, but, &op_keymap, NULL);
 +                      shortcut = op_keymap.strinfo;
 +              }
 +
 +              if (shortcut == NULL) {
 +                      /* Check for direct access to the tool. */
 +                      char shortcut_toolbar[128] = "";
 +                      if (WM_key_event_operator_string(
 +                                  C, "WM_OT_toolbar", WM_OP_INVOKE_REGION_WIN, NULL, true,
 +                                  shortcut_toolbar, ARRAY_SIZE(shortcut_toolbar)))
 +                      {
 +                              /* Generate keymap in order to inspect it.
 +                               * Note, we could make a utility to avoid the keymap generation part of this. */
 +                              const char *expr_ptr = (
 +                                      "getattr("
 +                                      "__import__('bl_ui').space_toolsystem_common.keymap_from_context("
 +                                      "__import__('bpy').context, "
 +                                      "__import__('bpy').context.space_data.type), "
 +                                      "'as_pointer', lambda: 0)()");
 +
 +                              intptr_t expr_result = 0;
-               if (BPY_execute_string_as_intptr(C, expr, true, &expr_result)) {
++                              if (BPY_execute_string_as_intptr(C, NULL, expr_ptr, true, &expr_result)) {
 +                                      if (expr_result != 0) {
 +                                              wmKeyMap *keymap = (wmKeyMap *)expr_result;
 +                                              for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
 +                                                      if (STREQ(kmi->idname, but->optype->idname)) {
 +                                                              char tool_name_test[MAX_NAME];
 +                                                              RNA_string_get(kmi->ptr, "name", tool_name_test);
 +                                                              if (STREQ(tool_name, tool_name_test)) {
 +                                                                      char buf[128];
 +                                                                      WM_keymap_item_to_string(kmi, false, buf, sizeof(buf));
 +                                                                      shortcut = BLI_sprintfN("%s, %s", shortcut_toolbar, buf);
 +                                                                      break;
 +                                                              }
 +                                                      }
 +                                              }
 +                                      }
 +                              }
 +                              else {
 +                                      BLI_assert(0);
 +                              }
 +                      }
 +              }
 +
 +              if (shortcut != NULL) {
 +                      uiTooltipField *field = text_field_add(
 +                              data, &(uiTooltipFormat){
 +                                  .style = UI_TIP_STYLE_NORMAL,
 +                                  .color_id = UI_TIP_LC_VALUE,
 +                                  .is_pad = true,
 +                              });
 +                      field->text = BLI_sprintfN(TIP_("Shortcut: %s"), shortcut);
 +                      MEM_freeN(shortcut);
 +              }
 +      }
 +
 +      /* Keymap */
 +
 +      /* This is too handy not to expose somehow, let's be sneaky for now. */
 +      if (CTX_wm_window(C)->eventstate->shift) {
 +
 +              SNPRINTF(
 +                      expr,
 +                      "getattr("
 +                      "__import__('bl_ui').space_toolsystem_common.keymap_from_name("
 +                      "__import__('bpy').context, "
 +                      "__import__('bpy').context.space_data.type, "
 +                      "'%s'), "
 +                      "'as_pointer', lambda: 0)()",
 +                      tool_name);
 +
 +              intptr_t expr_result = 0;
++              if (BPY_execute_string_as_intptr(C, NULL, expr, true, &expr_result)) {
 +                      if (expr_result != 0) {
 +                              {
 +                                      uiTooltipField *field = text_field_add(
 +                                              data, &(uiTooltipFormat){
 +                                                  .style = UI_TIP_STYLE_NORMAL,
 +                                                  .color_id = UI_TIP_LC_NORMAL,
 +                                                  .is_pad = true,
 +                                              });
 +                                      field->text = BLI_strdup("Tool Keymap:");
 +                              }
 +                              wmKeyMap *keymap = (wmKeyMap *)expr_result;
 +                              ui_tooltip_data_append_from_keymap(C, data, keymap);
 +                      }
 +              }
 +              else {
 +                      BLI_assert(0);
 +              }
 +      }
 +#endif  /* WITH_PYTHON */
 +
 +      if (data->fields_len == 0) {
 +              MEM_freeN(data);
 +              return NULL;
 +      }
 +      else {
 +              return data;
 +      }
 +}
 +
  static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but)
  {
        uiStringInfo but_tip = {BUT_GET_TIP, NULL};
Simple merge
@@@ -76,9 -76,10 +76,10 @@@ PyObject *      PyC_UnicodeFromByteAndS
  const char *    PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
  const char *    PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce);
  
 -/* name namespace function for bpy & bge */
 +/* name namespace function for bpy */
- PyObject *            PyC_DefaultNameSpace(const char *filename);
- void                  PyC_RunQuicky(const char *filepath, int n, ...);
+ PyObject *PyC_DefaultNameSpace(const char *filename);
+ void PyC_RunQuicky(const char *filepath, int n, ...);
+ bool PyC_NameSpace_ImportArray(PyObject *py_dict, const char *imports[]);
  
  void PyC_MainModule_Backup(PyObject **main_mod);
  void PyC_MainModule_Restore(PyObject *main_mod);