Attacher: add general purpose editor UI (python)

Added as PartGui.AttachmentEditor, and Part_EditAttachment gui command
This commit is contained in:
DeepSOIC
2016-05-16 01:40:25 +03:00
committed by wmayer
parent ec16290be2
commit 7d7cf5c723
12 changed files with 1378 additions and 53 deletions

View File

@@ -92,49 +92,49 @@ void PyException::ReportException (void) const
SystemExitException::SystemExitException()
{
// Set exception message and code based upon the pthon sys.exit() code and/or message
// based upon the the following sys.exit() call semantics.
//
// Invocation | _exitCode | _sErrMsg
// ---------------- + --------- + --------
// sys.exit(int#) | int# | "System Exit"
// sys.exit(string) | 1 | string
// sys.exit() | 1 | "System Exit"
long int errCode = 1;
std::string errMsg = "System exit";
PyObject *type, *value, *traceback, *code;
PyGILStateLocker locker;
PyErr_Fetch(&type, &value, &traceback);
PyErr_NormalizeException(&type, &value, &traceback);
if (value) {
code = PyObject_GetAttrString(value, "code");
if (code != NULL && value != Py_None) {
Py_DECREF(value);
value = code;
}
if (PyInt_Check(value)) {
errCode = PyInt_AsLong(value);
}
else {
const char *str = PyString_AsString(value);
if (str)
errMsg = errMsg + ": " + str;
}
}
// Set exception message and code based upon the pthon sys.exit() code and/or message
// based upon the the following sys.exit() call semantics.
//
// Invocation | _exitCode | _sErrMsg
// ---------------- + --------- + --------
// sys.exit(int#) | int# | "System Exit"
// sys.exit(string) | 1 | string
// sys.exit() | 1 | "System Exit"
long int errCode = 1;
std::string errMsg = "System exit";
PyObject *type, *value, *traceback, *code;
PyGILStateLocker locker;
PyErr_Fetch(&type, &value, &traceback);
PyErr_NormalizeException(&type, &value, &traceback);
if (value) {
code = PyObject_GetAttrString(value, "code");
if (code != NULL && value != Py_None) {
Py_DECREF(value);
value = code;
}
if (PyInt_Check(value)) {
errCode = PyInt_AsLong(value);
}
else {
const char *str = PyString_AsString(value);
if (str)
errMsg = errMsg + ": " + str;
}
}
_sErrMsg = errMsg;
_exitCode = errCode;
_exitCode = errCode;
}
SystemExitException::SystemExitException(const SystemExitException &inst)
: Exception(inst), _exitCode(inst._exitCode)
{
}
// ---------------------------------------------------------
@@ -214,6 +214,30 @@ std::string InterpreterSingleton::runString(const char *sCmd)
}
}
Py::Object InterpreterSingleton::runString_returnObject(const char *sCmd)
{
PyObject *module, *dict, *presult; /* "exec code in d, d" */
PyGILStateLocker locker;
module = PP_Load_Module("__main__"); /* get module, init python */
if (module == NULL)
throw PyException(); /* not incref'd */
dict = PyModule_GetDict(module); /* get dict namespace */
if (dict == NULL)
throw PyException(); /* not incref'd */
presult = PyRun_String(sCmd, Py_eval_input, dict, dict); /* eval direct */
if (!presult) {
if (PyErr_ExceptionMatches(PyExc_SystemExit))
throw SystemExitException();
else
throw PyException();
}
return Py::Object(presult, true);
}
void InterpreterSingleton::systemExit(void)
{
/* This code is taken from the original Python code */
@@ -314,22 +338,22 @@ void InterpreterSingleton::runFile(const char*pxFileName, bool local)
Py_INCREF(dict); // avoid to further distinguish between local and global dict
}
if (PyDict_GetItemString(dict, "__file__") == NULL) {
PyObject *f = PyString_FromString(pxFileName);
if (f == NULL) {
fclose(fp);
Py_DECREF(dict);
return;
}
if (PyDict_SetItemString(dict, "__file__", f) < 0) {
Py_DECREF(f);
fclose(fp);
Py_DECREF(dict);
return;
}
Py_DECREF(f);
}
if (PyDict_GetItemString(dict, "__file__") == NULL) {
PyObject *f = PyString_FromString(pxFileName);
if (f == NULL) {
fclose(fp);
Py_DECREF(dict);
return;
}
if (PyDict_SetItemString(dict, "__file__", f) < 0) {
Py_DECREF(f);
fclose(fp);
Py_DECREF(dict);
return;
}
Py_DECREF(f);
}
PyObject *result = PyRun_File(fp, pxFileName, Py_file_input, dict, dict);
fclose(fp);
Py_DECREF(dict);