Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
31a693cb
Commit
31a693cb
authored
Mar 17, 2013
by
Miguel Angel Ajo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring python to wxArrayString, and better exception error reporting
parent
f83a200e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
34 deletions
+66
-34
pcbnew_footprint_wizards.cpp
pcbnew/scripting/pcbnew_footprint_wizards.cpp
+2
-28
python_scripting.cpp
scripting/python_scripting.cpp
+61
-6
python_scripting.h
scripting/python_scripting.h
+3
-0
No files found.
pcbnew/scripting/pcbnew_footprint_wizards.cpp
View file @
31a693cb
...
...
@@ -63,25 +63,9 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aA
if
(
PyErr_Occurred
()
)
{
wxString
message
;
PyObject
*
t
;
PyObject
*
v
;
PyObject
*
b
;
PyErr_Fetch
(
&
t
,
&
v
,
&
b
);
message
.
Printf
(
wxT
(
"calling %s()
\n
"
"Exception: %s
\n
"
" : %s
\n
"
),
FROM_UTF8
(
aMethod
).
c_str
(),
FROM_UTF8
(
PyString_AsString
(
PyObject_Str
(
v
)
)
).
c_str
(),
FROM_UTF8
(
PyString_AsString
(
PyObject_Str
(
b
)
)
).
c_str
()
);
wxMessageBox
(
message
,
wxMessageBox
(
PyErrStringWithTraceback
(),
wxT
(
"Exception on python footprint wizard code"
),
wxICON_ERROR
|
wxOK
);
PyErr_Clear
();
}
if
(
result
)
...
...
@@ -140,17 +124,7 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod( const char* aMet
return
ret
;
}
int
list_size
=
PyList_Size
(
result
);
for
(
int
n
=
0
;
n
<
list_size
;
n
++
)
{
PyObject
*
element
=
PyList_GetItem
(
result
,
n
);
const
char
*
str_res
=
PyString_AsString
(
element
);
str_item
=
FROM_UTF8
(
str_res
);
ret
.
Add
(
str_item
,
1
);
}
ret
=
PyArrayStringToWx
(
result
);
Py_DECREF
(
result
);
}
...
...
scripting/python_scripting.cpp
View file @
31a693cb
...
...
@@ -38,6 +38,7 @@
#include <wxstruct.h>
#include <common.h>
#include <colors.h>
#include <macros.h>
/* init functions defined by swig */
...
...
@@ -62,11 +63,11 @@ static int SwigNumModules = 0;
static
void
swigAddModule
(
const
char
*
name
,
void
(
*
initfunc
)()
)
{
SwigImportInittab
[
SwigNumModules
].
name
=
(
char
*
)
name
;
SwigImportInittab
[
SwigNumModules
].
initfunc
=
initfunc
;
SwigImportInittab
[
SwigNumModules
].
name
=
(
char
*
)
name
;
SwigImportInittab
[
SwigNumModules
].
initfunc
=
initfunc
;
SwigNumModules
++
;
SwigImportInittab
[
SwigNumModules
].
name
=
(
char
*
)
0
;
SwigImportInittab
[
SwigNumModules
].
initfunc
=
0
;
SwigImportInittab
[
SwigNumModules
].
name
=
(
char
*
)
0
;
SwigImportInittab
[
SwigNumModules
].
initfunc
=
0
;
}
...
...
@@ -165,7 +166,7 @@ bool pcbnewInitPythonScripting()
{
PyLOCK
lock
;
PyRun_SimpleString
(
"import sys
\n
"
PyRun_SimpleString
(
"import sys
, traceback
\n
"
"sys.path.append(
\"
.
\"
)
\n
"
"import pcbnew
\n
"
"pcbnew.LoadPlugins()"
...
...
@@ -198,7 +199,7 @@ void RedirectStdio()
"output = wx.PyOnDemandOutputWindow()
\n
"
"sys.stderr = output
\n
"
;
PyLOCK
lock
;
PyLOCK
lock
;
PyRun_SimpleString
(
python_redirect
);
}
...
...
@@ -295,3 +296,57 @@ wxWindow* CreatePythonShellWindow( wxWindow* parent )
#endif
wxArrayString
PyArrayStringToWx
(
PyObject
*
aArrayString
)
{
wxArrayString
ret
;
int
list_size
=
PyList_Size
(
aArrayString
);
for
(
int
n
=
0
;
n
<
list_size
;
n
++
)
{
PyObject
*
element
=
PyList_GetItem
(
aArrayString
,
n
);
ret
.
Add
(
FROM_UTF8
(
PyString_AsString
(
element
)
),
1
);
}
return
ret
;
}
wxString
PyErrStringWithTraceback
()
{
wxString
err
;
if
(
!
PyErr_Occurred
()
)
return
err
;
PyObject
*
type
;
PyObject
*
value
;
PyObject
*
traceback
;
PyErr_Fetch
(
&
type
,
&
value
,
&
traceback
);
PyObject
*
tracebackModuleString
=
PyString_FromString
(
(
char
*
)
"traceback"
);
PyObject
*
tracebackModule
=
PyImport_Import
(
tracebackModuleString
);
PyObject
*
formatException
=
PyObject_GetAttrString
(
tracebackModule
,
(
char
*
)
"format_exception"
);
PyObject
*
args
=
Py_BuildValue
(
"(O,O,O)"
,
type
,
value
,
traceback
);
PyObject
*
result
=
PyObject_CallObject
(
formatException
,
args
);
Py_DECREF
(
args
);
wxArrayString
res
=
PyArrayStringToWx
(
result
);
for
(
int
i
=
0
;
i
<
res
.
Count
();
i
++
)
{
err
+=
res
[
i
]
+
wxT
(
"
\n
"
);
}
PyErr_Clear
();
return
err
;
}
scripting/python_scripting.h
View file @
31a693cb
...
...
@@ -53,4 +53,7 @@ public:
#endif
wxArrayString
PyArrayStringToWx
(
PyObject
*
arr
);
wxString
PyErrStringWithTraceback
();
#endif // __PYTHON_SCRIPTING_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment