Skip to content

Commit

Permalink
Merge pull request #200 from canorusmusic/matevz/python3.9-fixes
Browse files Browse the repository at this point in the history
python 3.9 fixes
  • Loading branch information
matevz authored Jan 2, 2023
2 parents e40520c + 101b8c2 commit c524ab3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/canorus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ void CACanorus::initSearchPaths()
if (cat == "fonts" && QDir(qApp->applicationDirPath() + "/../../src/fonts/").exists()) {
QDir::addSearchPath(cat, qApp->applicationDirPath() + "/../../src/fonts/");
}
if (cat == "scripts" && QDir(qApp->applicationDirPath() + "/../../src/scripts/").exists()) {
QDir::addSearchPath(cat, qApp->applicationDirPath() + "/../../src/scripts/");
}
if (cat == "doc" && QDir(qApp->applicationDirPath()).exists("/../../doc/")) {
QDir::addSearchPath(cat, qApp->applicationDirPath() + "/../../doc");
}
Expand Down
7 changes: 5 additions & 2 deletions src/scripting/swigpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ void CASwigPython::init()
}
#endif

// Load proxy classes.
PyRun_SimpleString("import CanorusPython");

mainThreadState = PyThreadState_Get();
PyEval_ReleaseThread(mainThreadState);

Expand Down Expand Up @@ -126,6 +129,8 @@ PyObject* CASwigPython::callFunction(QString fileName, QString function, QList<P
return args.first();
}

PyEval_RestoreThread(mainThreadState);

PyObject* pyArgs = PyTuple_New(args.size());
if (!pyArgs)
return nullptr;
Expand All @@ -136,8 +141,6 @@ PyObject* CASwigPython::callFunction(QString fileName, QString function, QList<P
QString moduleName = fileName.left(fileName.lastIndexOf(".py"));
moduleName = moduleName.remove(0, moduleName.lastIndexOf("/") + 1);

PyEval_RestoreThread(CASwigPython::mainThreadState);

PyObject* pyModule;
if (autoReload) {
PyObject* moduleDict = PyImport_GetModuleDict(); // borrowed ref.
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/pyconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ bool CAPyConsole::cmdIntern(QString strCmd)
curObject = curObject->parent();
PyEval_RestoreThread(CASwigPython::mainThreadState);
argsPython << CASwigPython::toPythonObject(static_cast<CAMainWin*>(curObject)->document(), CASwigPython::Document);
PyEval_ReleaseThread(CASwigPython::mainThreadState);
argsPython << PyUnicode_FromString(strCmd.toStdString().c_str());
PyEval_ReleaseThread(CASwigPython::mainThreadState);

// Can't autoreload because we are using global objects in pycl2.py that would get overwritten.
auto ret = CASwigPython::callFunction(QFileInfo("scripts:pycl2.py").absoluteFilePath(), "main", argsPython, false);
Expand Down

0 comments on commit c524ab3

Please sign in to comment.