Skip to content

Commit 7a342ea

Browse files
committed
minor
1 parent f4318d0 commit 7a342ea

File tree

5 files changed

+33
-50
lines changed

5 files changed

+33
-50
lines changed

source/plugins/Sea5kg/Python3Scripting/src/PythonExecutor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ std::wstring str2wstr(const std::string& str) {
2424
return converterX.from_bytes(str);
2525
}
2626

27-
PyThreadState *mainstate;
28-
2927
PythonExecutor::PythonExecutor(
3028
const std::string &sExtensionId,
3129
const std::string &sDirPathWithModules
@@ -38,9 +36,11 @@ PythonExecutor::PythonExecutor(
3836
for (int i = 0; i < m_vWrappers.size(); i++) {
3937
m_vWrappers[i]->Call_PyImport_AppendInittab();
4038
}
39+
4140
Py_Initialize();
41+
// Py_SetPythonHome
4242
// mainstate = PyThreadState_Swap(NULL);
43-
// Py_SetProgramName(const wchar_t *name)
43+
Py_SetProgramName(L"main.py");
4444

4545
{
4646
PyObject* pGlobalDict = PyDict_New();
@@ -161,7 +161,6 @@ int PythonExecutor::execCode(const std::string &sScriptContent) {
161161
if (pPyErrorTraceback != nullptr) {
162162
PyException_SetTraceback(pvalue, pPyErrorTraceback);
163163
}
164-
// PyObject* pPyStringExceptionType = PyObject_Str(pyExcType);
165164

166165
PyObject* str_exc_type = PyObject_Repr(ptype);
167166
PyObject* pyStr = PyUnicode_AsEncodedString(str_exc_type, "utf-8", "Error ~");

source/plugins/Sea5kg/Python3Scripting/src/format_unexpy3/FileUnexpy3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FileUnexpy3 {
2727
QVector<QString> getListOfFiles();
2828

2929
// QVector<QString> getDependencies();
30-
30+
3131
QString getId();
3232
QString getName();
3333
QString getFor();

source/plugins/Sea5kg/Python3Scripting/src/python3_wrapper/python3_unigine_stderr.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,27 @@ struct Stderr
1515
stderr_write_type write;
1616
};
1717

18-
PyObject* Stderr_write(PyObject* self, PyObject* args)
19-
{
18+
PyObject* Stderr_write(PyObject* self, PyObject* args) {
2019
std::size_t written(0);
2120
Stderr* selfimpl = reinterpret_cast<Stderr*>(self);
22-
if (selfimpl->write)
23-
{
21+
if (selfimpl->write) {
2422
char* data;
2523
if (!PyArg_ParseTuple(args, "s", &data)) {
2624
return 0;
2725
}
2826
std::string sOutputMessage(data);
29-
// selfimpl->write(sOutputMessage);
30-
// written = sOutputMessage.size();
31-
// TODO extension_id
3227
sOutputMessage = "ERROR. Python3Scripting: " + sOutputMessage;
3328
Unigine::Log::error("%s", sOutputMessage.c_str());
3429
}
3530
return PyLong_FromSize_t(written);
3631
}
3732

38-
PyObject* Stderr_flush(PyObject* self, PyObject* args)
39-
{
33+
PyObject* Stderr_flush(PyObject* self, PyObject* args) {
4034
// no-op
4135
return Py_BuildValue("");
4236
}
4337

44-
PyMethodDef Stderr_methods[] =
45-
{
38+
PyMethodDef Stderr_methods[] = {
4639
{"write", Stderr_write, METH_VARARGS, "sys.stderr.write"},
4740
{"flush", Stderr_flush, METH_VARARGS, "sys.stderr.flush"},
4841
{0, 0, 0, 0} // sentinel

source/plugins/Sea5kg/Python3Scripting/src/python3_wrapper/python3_unigine_stdout.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
typedef std::function<void(std::string)> stdout_write_type;
1111

1212
// Stdout
13-
struct Stdout
14-
{
13+
struct Stdout {
1514
PyObject_HEAD
1615
stdout_write_type write;
1716
};
1817

19-
PyObject* Stdout_write(PyObject* self, PyObject* args)
20-
{
18+
PyObject* Stdout_write(PyObject* self, PyObject* args) {
2119
std::size_t written(0);
2220
Stdout* selfimpl = reinterpret_cast<Stdout*>(self);
2321
if (selfimpl->write)
@@ -27,23 +25,18 @@ PyObject* Stdout_write(PyObject* self, PyObject* args)
2725
return 0;
2826
}
2927
std::string sOutputMessage(data);
30-
// selfimpl->write(sOutputMessage);
31-
// written = sOutputMessage.size();
32-
// TODO extension_id
3328
sOutputMessage = "Python3Scripting: " + sOutputMessage + "\n";
3429
Unigine::Log::message(sOutputMessage.c_str());
3530
}
3631
return PyLong_FromSize_t(written);
3732
}
3833

39-
PyObject* Stdout_flush(PyObject* self, PyObject* args)
40-
{
34+
PyObject* Stdout_flush(PyObject* self, PyObject* args) {
4135
// no-op
4236
return Py_BuildValue("");
4337
}
4438

45-
PyMethodDef Stdout_methods[] =
46-
{
39+
PyMethodDef Stdout_methods[] = {
4740
{"write", Stdout_write, METH_VARARGS, "sys.stdout.write"},
4841
{"flush", Stdout_flush, METH_VARARGS, "sys.stdout.flush"},
4942
{0, 0, 0, 0} // sentinel
@@ -131,13 +124,11 @@ void Python3UnigineStdout::Call_PyImport_AppendInittab() {
131124

132125
void Python3UnigineStdout::Call_PyImport_ImportModule() {
133126
PyImport_ImportModule("unigine_stdout");
134-
127+
135128
std::string buffer;
136129
stdout_write_type write = [&buffer] (std::string s) { buffer += s; };
137130

138-
// set_stdout(write);
139-
if (!g_stdout)
140-
{
131+
if (!g_stdout) {
141132
g_stdout_saved = PySys_GetObject("stdout"); // borrowed
142133
g_stdout = StdoutType.tp_new(&StdoutType, 0, 0);
143134
}

source/plugins/Sea5kg/Python3Scripting/src/python3_wrapper/pytypesobjects/python3_unigine_materials.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,25 @@ static PyObject * unigine_Materials_set_precompile_all_shaders(unigine_Materials
261261
PyObject *pArg1; // bool shaders;
262262
PyArg_ParseTuple(args, "O", &pArg1);
263263

264-
// pArg1
265-
TODO for bool
266-
267-
268-
class LocalRunner : public Python3Runner {
269-
public:
270-
virtual void run() override {
271-
Unigine::Materials::setPrecompileAllShaders(shaders);
272-
};
273-
// args
274-
bool shaders;
275-
};
276-
auto *pRunner = new LocalRunner();
277-
pRunner->shaders = shaders;
278-
Python3Runner::runInMainThread(pRunner);
279-
while (!pRunner->mutexAsync.tryLock(5)) { // milliseconds
280-
}
281-
pRunner->mutexAsync.unlock();
282-
delete pRunner;
264+
// // pArg1
265+
// TODO for bool
266+
267+
268+
// class LocalRunner : public Python3Runner {
269+
// public:
270+
// virtual void run() override {
271+
// Unigine::Materials::setPrecompileAllShaders(shaders);
272+
// };
273+
// // args
274+
// bool shaders;
275+
// };
276+
// auto *pRunner = new LocalRunner();
277+
// pRunner->shaders = shaders;
278+
// Python3Runner::runInMainThread(pRunner);
279+
// while (!pRunner->mutexAsync.tryLock(5)) { // milliseconds
280+
// }
281+
// pRunner->mutexAsync.unlock();
282+
// delete pRunner;
283283
Py_INCREF(Py_None);
284284
ret = Py_None;
285285
assert(!PyErr_Occurred());

0 commit comments

Comments
 (0)