Changeset View
Changeset View
Standalone View
Standalone View
src/backends/python/pythonserver.cpp
Show First 20 Lines • Show All 138 Lines • ▼ Show 20 Line(s) | |||||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | void PythonServer::setFilePath(const QString& path) | 141 | void PythonServer::setFilePath(const QString& path) | ||
142 | { | 142 | { | ||
143 | this->filePath = path; | 143 | this->filePath = path; | ||
144 | PyRun_SimpleString(("__file__ = '"+path.toStdString()+"'").c_str()); | 144 | PyRun_SimpleString(("__file__ = '"+path.toStdString()+"'").c_str()); | ||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | QString PythonServer::variables(bool parseValue) const | ||||
148 | { | ||||
149 | // FIXME: This code allows get full form of numpy array, but for big arrays it's could cause performonce problems | ||||
150 | // especially for displaying in variables panel | ||||
151 | // So, uncomment this, when fix this problem | ||||
152 | /* | ||||
153 | "try: \n" | ||||
154 | " import numpy \n" | ||||
155 | " __cantor_numpy_internal__ = numpy.get_printoptions()['threshold'] \n" | ||||
156 | " numpy.set_printoptions(threshold=100000000) \n" | ||||
157 | "except ModuleNotFoundError: \n" | ||||
158 | " pass \n" | ||||
159 | | ||||
160 | "try: \n" | ||||
161 | " import numpy \n" | ||||
162 | " numpy.set_printoptions(threshold=__cantor_numpy_internal__) \n" | ||||
163 | " del __cantor_numpy_internal__ \n" | ||||
164 | "except ModuleNotFoundError: \n" | ||||
165 | " pass \n" | ||||
166 | */ | ||||
167 | | ||||
168 | PyRun_SimpleString("__tmp_globals__ = globals()"); | ||||
169 | PyObject* globals = PyObject_GetAttrString(m_pModule,"__tmp_globals__"); | ||||
170 | PyObject *key, *value; | ||||
171 | Py_ssize_t pos = 0; | ||||
172 | | ||||
173 | QStringList vars; | ||||
174 | const QChar sep(30); // INFORMATION SEPARATOR TWO | ||||
175 | while (PyDict_Next(globals, &pos, &key, &value)) { | ||||
176 | const QString& keyString = pyObjectToQString(key); | ||||
177 | if (keyString.startsWith(QLatin1String("__"))) | ||||
178 | continue; | ||||
179 | | ||||
180 | if (keyString == QLatin1String("CatchOutPythonBackend") | ||||
181 | || keyString == QLatin1String("errorPythonBackend") | ||||
182 | || keyString == QLatin1String("outputPythonBackend")) | ||||
183 | continue; | ||||
184 | | ||||
185 | if (PyModule_Check(value)) | ||||
186 | continue; | ||||
187 | | ||||
188 | if (PyFunction_Check(value)) | ||||
189 | continue; | ||||
190 | | ||||
191 | if (PyType_Check(value)) | ||||
192 | continue; | ||||
193 | | ||||
194 | QString valueString; | ||||
195 | if (parseValue) | ||||
196 | valueString = pyObjectToQString(PyObject_Repr(value)); | ||||
197 | | ||||
198 | | ||||
199 | vars.append(keyString + QChar(31) + valueString); | ||||
200 | } | ||||
201 | | ||||
202 | return vars.join(sep); | ||||
203 | } | ||||
204 | | ||||
147 | 205 | |