示例#1
0
/**
 * Check for errors and log a message.
 */
void PyApi::CheckForPythonErrors() const
{
  const auto  ex = PyErr_Occurred();
  if (nullptr != ex)
  {
    //  if this is a normal exist, then we don't need to show an error message.
    if (!PyErr_ExceptionMatches(PyExc_SystemExit))
    {
      PyObject *type, *value, *traceback;
      PyErr_Fetch(&type, &value, &traceback);
      PyErr_Clear();

      std::string message = "<b>Error : </b>An error was raised in the PyAPI.";
      if (type) {
        const auto temp_bytes = PyUnicode_AsEncodedString(type, "ASCII", "strict");
        if (temp_bytes != nullptr) {
          message += "<br>";
          message += PyBytes_AS_STRING(temp_bytes); // Borrowed pointer
          Py_DECREF(temp_bytes);
        }
      }
      if (value) {
        const auto temp_bytes = PyUnicode_AsEncodedString(value, "ASCII", "strict");
        if (temp_bytes != nullptr) {
          message += "<br>";
          message += PyBytes_AS_STRING(temp_bytes); // Borrowed pointer
          Py_DECREF(temp_bytes);
        }
      }
      if (traceback) {
        const auto temp_bytes = PyUnicode_AsEncodedString(traceback, "ASCII", "strict");
        if (temp_bytes != nullptr) {
          message += "<br>";
          message += PyBytes_AS_STRING(temp_bytes); // Borrowed pointer
          Py_DECREF(temp_bytes);
        }
      }
      Py_XDECREF(type);
      Py_XDECREF(value);
      Py_XDECREF(traceback);

      // give the error message
      USES_CONVERSION;
      const wchar_t* msg = T_A2T(message.c_str());
      const unsigned int nElapse = 500;
      const unsigned int nFadeOut = 10;
      __super::Say(msg, nElapse, nFadeOut);
    }
  }

  // no more errors.
  PyErr_Clear();
}
示例#2
0
/**
 * Parse the clipboard data and add file names, texts and what ever info could be used.
 * We cannot do much with non text items.
 * Update this function as new clipboard items are discovered.
 *
 * @param vector of clipboard data been parsed.
 * @return none.
 */
void Clipboard::ParseClipboard( V_CF& s_cf )
{
  USES_CONVERSION;

  for( V_CF::const_iterator it = s_cf.begin(); it != s_cf.end(); it++ )
  {
    try
    {
      ClipboardData* cf = *it;
      if( NULL == cf )
      {
        continue;
      }

      switch( cf->uFormat )
      {
      case 0x0c006: /* FILENAME */
        {
          //  a file name was added
          const wchar_t* lp = T_A2T((CHAR*)cf->data);
          AddFileName( lp );
        }
        break;

      case 0x0c007: /*FILENAMEW*/
        {
          //  a file name was added
          const wchar_t* lp = (WCHAR*)cf->data;
          AddFileName(lp);
        }
        break;

      case CF_UNICODETEXT:
        {
          //  normal, selected text.
          const wchar_t* lp = (WCHAR*)cf->data;
          SetText( lp );
        }
        break;

      case CF_TEXT:
        {
          //  normal, selected text.
          const wchar_t* lp = T_A2T( (CHAR*)cf->data );
          SetText( lp );
        }
        break;

      case CF_HDROP:
        {
          ClipboardDropData* cdd = (ClipboardDropData*)cf->data;
          const std::vector<MYODD_STRING>& files = cdd->Files();
          for (std::vector<MYODD_STRING>::const_iterator it = files.begin(); it != files.end(); ++it)
          {
            AddFileName( *it );
          }
        }
        break;
        
      default:  //  not handled.
        break;
      }
    }
    catch(... )
    {
      _ASSERT(0); //  the main reason for failure is probably because  
                  //  there is a format in the Clipboard that I am not handling properly
                  //  there should be a way of seending me a mail when this happens so we can look into fixing it.
    }
  }// for each clipboard items
}