summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp')
-rw-r--r--kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp56
1 files changed, 31 insertions, 25 deletions
diff --git a/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp b/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp
index dd228934..52c966b4 100644
--- a/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp
+++ b/kivio/kiviopart/kiviosdk/kivio_py_stencil.cpp
@@ -46,7 +46,7 @@ KivioPyStencil::KivioPyStencil()
static bool first_time = true;
if ( first_time ) {
Py_Initialize(); // initialize python only once
- //kdDebug(43000) << "init kivioc" << endl;
+ //kdDebug(43000) << "init kivioc" << endl;
initkivioc();
first_time = false;
}
@@ -190,7 +190,7 @@ TQDomElement KivioPyStencil::saveXML( TQDomDocument &doc )
PyObject* gdic = PyModule_GetDict(mainmod);
PyObject *ldic = Py_BuildValue("{s:O,s:{}}", "ldic", vars ,"res");
- char *dump_code = "import copy\n"\
+ const char *dump_code = "import copy\n"\
"import pickle\n"\
"cres = {}\n"\
"for key in ldic.keys():\n"\
@@ -203,7 +203,7 @@ TQDomElement KivioPyStencil::saveXML( TQDomDocument &doc )
if ( !PyRun_String(dump_code, Py_file_input, gdic, ldic) )
PyErr_Print();
- TQString sVars = PyString_AsString( PyDict_GetItemString( ldic, "res") );
+ TQString sVars = PyBytes_AS_STRING( PyDict_GetItemString( ldic, "res") );
XmlWriteString( dE, "vars", sVars );
XmlWriteString( dE, "resizeCode", resizeCode );
@@ -361,7 +361,7 @@ KivioStencil *KivioPyStencil::duplicate()
PyObject* gdic = PyModule_GetDict(mainmod);
PyObject *ldic = Py_BuildValue("{s:O,s:{}}", "ldic", vars ,"res");
- char *copy_code = "import copy\n"\
+ const char *copy_code = "import copy\n"\
"for key in ldic.keys():\n"\
" try:\n"\
" res[key] = copy.deepcopy(ldic[key])\n"\
@@ -535,7 +535,7 @@ int KivioPyStencil::runPython(TQString code)
}
//const char *ccode = code.local8Bit().data();
- const char *ccode = code.latin1();
+ const char *ccode = code.latin1();
//kdDebug(43000) << "code to run:" << endl << ccode << endl;
@@ -546,7 +546,13 @@ int KivioPyStencil::runPython(TQString code)
return 0;
}
- if (Py_FlushLine())
+ PyObject *f = PySys_GetObject("stdout");
+ int ret = 0;
+ if (f)
+ {
+ ret = PyFile_WriteString("\n", f);
+ }
+ if (ret)
PyErr_Clear();
Py_DECREF(v);
@@ -563,8 +569,8 @@ double KivioPyStencil::getDoubleFromDict( PyObject *dict, const char *key )
if ( PyFloat_Check(val) )
return PyFloat_AsDouble( val );
- if ( PyInt_Check(val) )
- return PyInt_AsLong( val );
+ if ( PyLong_Check(val) )
+ return PyLong_AsLong( val );
if ( PyLong_Check(val) )
return PyLong_AsDouble( val );
@@ -575,8 +581,8 @@ double KivioPyStencil::getDoubleFromDict( PyObject *dict, const char *key )
TQString KivioPyStencil::getStringFromDict( PyObject *dict, const char *key )
{
PyObject *val = PyDict_GetItemString(dict,const_cast<char*>(key));
- if ( val && PyString_Check(val) )
- return TQString( PyString_AsString(val) );
+ if ( val && PyBytes_Check(val) )
+ return TQString( PyBytes_AS_STRING(val) );
return TQString("");
}
@@ -829,8 +835,8 @@ TQColor KivioPyStencil::readColor( PyObject *color )
if ( !color )
return TQColor();
- if ( PyString_Check(color) ) {
- return TQColor( PyString_AsString(color) );
+ if ( PyBytes_Check(color) ) {
+ return TQColor( PyBytes_AsString(color) );
}
if ( PyList_Check(color) ) {
@@ -841,11 +847,11 @@ TQColor KivioPyStencil::readColor( PyObject *color )
int r=0, g=0, b=0;
if ( PyNumber_Check(ro) )
- r = PyInt_AsLong( PyNumber_Int(ro));
+ r = PyLong_AsLong( PyNumber_Long(ro));
if ( PyNumber_Check(go) )
- g = PyInt_AsLong( PyNumber_Int(go));
+ g = PyLong_AsLong( PyNumber_Long(go));
if ( PyNumber_Check(bo) )
- b = PyInt_AsLong( PyNumber_Int(bo));
+ b = PyLong_AsLong( PyNumber_Long(bo));
return TQColor(r,g,b);
@@ -858,7 +864,7 @@ TQColor KivioPyStencil::readColor( PyObject *color )
void KivioPyStencil::PyDebug( PyObject * o )
{
- kdDebug(43000) << "py_debug: " << PyString_AsString(PyObject_Str(o)) << endl;
+ kdDebug(43000) << "py_debug: " << PyBytes_AsString(PyObject_Str(o)) << endl;
}
@@ -912,7 +918,7 @@ double KivioPyStencil::lineWidth()
PyObject *lw = PyDict_GetItemString( PyDict_GetItemString(vars,"style"), "linewidth" );
if ( lw )
if ( PyNumber_Check(lw) )
- return ( PyInt_AsLong( PyNumber_Int(lw)) );
+ return ( PyLong_AsLong( PyNumber_Long(lw)) );
return 1.0;
}
@@ -967,23 +973,23 @@ TQFont KivioPyStencil::textFont()
if ( fs )
if ( PyNumber_Check(fs))
- f.setPointSize( PyInt_AsLong( PyNumber_Int(fs)));
+ f.setPointSize( PyLong_AsLong( PyNumber_Long(fs)));
if ( bd )
if ( PyNumber_Check(bd))
- f.setBold( PyInt_AsLong( PyNumber_Int(bd)));
+ f.setBold( PyLong_AsLong( PyNumber_Long(bd)));
if ( it )
if ( PyNumber_Check(it))
- f.setItalic( PyInt_AsLong( PyNumber_Int(it)));
+ f.setItalic( PyLong_AsLong( PyNumber_Long(it)));
if ( ul )
if ( PyNumber_Check(ul))
- f.setUnderline( PyInt_AsLong( PyNumber_Int(ul)));
+ f.setUnderline( PyLong_AsLong( PyNumber_Long(ul)));
if ( fn )
- if ( PyString_Check(fn))
- f.setFamily( PyString_AsString(fn));
+ if ( PyBytes_Check(fn))
+ f.setFamily( PyBytes_AsString(fn));
return f;
}
@@ -994,7 +1000,7 @@ int KivioPyStencil::hTextAlign()
if ( hta )
if ( PyNumber_Check(hta) )
- return ( PyInt_AsLong( PyNumber_Int(hta)));
+ return ( PyLong_AsLong( PyNumber_Long(hta)));
return TQt::AlignHCenter;
}
@@ -1005,7 +1011,7 @@ int KivioPyStencil::vTextAlign()
if ( vta )
if ( PyNumber_Check(vta) )
- return ( PyInt_AsLong( PyNumber_Int(vta)));
+ return ( PyLong_AsLong( PyNumber_Long(vta)));
return TQt::AlignVCenter;
}