diff --git a/src/Mod/Fem/Gui/AppFemGuiPy.cpp b/src/Mod/Fem/Gui/AppFemGuiPy.cpp index 5f457aa37..3fe3b83fa 100755 --- a/src/Mod/Fem/Gui/AppFemGuiPy.cpp +++ b/src/Mod/Fem/Gui/AppFemGuiPy.cpp @@ -24,12 +24,17 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include #endif #include #include +#include #include #include +#include +#include +#include #include #include "ActiveAnalysisObserver.h" @@ -69,6 +74,43 @@ static PyObject * getActiveAnalysis(PyObject *self, PyObject *args) Py_Return; } +/* module functions */ +static PyObject * openEditor(PyObject *self, PyObject *args) +{ + char* Name; + const char* DocName; + if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName)) + return NULL; + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + PY_TRY { + QString fileName = QString::fromUtf8(EncodedName.c_str()); + QFileInfo fi; + fi.setFile(fileName); + QString ext = fi.completeSuffix().toLower(); + QList views = Gui::getMainWindow()->findChildren(); + for (QList::Iterator it = views.begin(); it != views.end(); ++it) { + if ((*it)->fileName() == fileName) { + (*it)->setFocus(); + Py_Return; + } + } + + if (ext == QLatin1String("inp")) { + Gui::TextEditor* editor = new Gui::TextEditor(); + editor->setWindowIcon(Gui::BitmapFactory().pixmap(":/icons/Fem_Inp_Editor.svg")); + Gui::EditorView* edit = new Gui::EditorView(editor, Gui::getMainWindow()); + edit->open(fileName); + edit->resize(400, 300); + QString shownName = QString::fromAscii("%1[*]").arg(fi.fileName()); + edit->setWindowTitle(shownName); + Gui::getMainWindow()->addWindow(edit); + } + } PY_CATCH; + + Py_Return; +} + /* registration table */ @@ -77,5 +119,7 @@ struct PyMethodDef FemGui_Import_methods[] = { "setActiveAnalysis(AnalysisObject) -- Set the Analysis object in work."}, {"getActiveAnalysis" ,getActiveAnalysis ,METH_VARARGS, "getActiveAnalysis() -- Returns the Analysis object in work."}, + {"openEditor" ,openEditor ,METH_VARARGS, + "openEditor() -- Opens a simple text editor for an FEM file."}, {NULL, NULL} /* end of table marker */ }; diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index 9ec3a2373..c094fd3b3 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -11,6 +11,7 @@ icons/Fem_AddFemMesh.svg icons/Fem_AddMaterial.svg icons/Fem_AddPart.svg + icons/Fem_Inp_Editor.svg icons/Fem_Material.svg icons/Fem_NewAnalysis.svg icons/Fem_Result.svg diff --git a/src/Mod/Fem/Gui/Resources/icons/Fem_Inp_Editor.svg b/src/Mod/Fem/Gui/Resources/icons/Fem_Inp_Editor.svg new file mode 100644 index 000000000..db6bc00f5 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/Fem_Inp_Editor.svg @@ -0,0 +1,252 @@ + +image/svg+xmljakub Steinerhttp://jimmac.musichall.czhomereturngodefaultuserdirectory \ No newline at end of file diff --git a/src/Mod/Fem/MechanicalAnalysis.py b/src/Mod/Fem/MechanicalAnalysis.py index c2a436d58..c4cdf9913 100644 --- a/src/Mod/Fem/MechanicalAnalysis.py +++ b/src/Mod/Fem/MechanicalAnalysis.py @@ -539,14 +539,22 @@ class _JobControlTaskPanel: QApplication.restoreOverrideCursor() - def editCalculixInputFile(self): - print 'editCalculixInputFile' - print self.Basename + '.inp' - import webbrowser - # If inp-file extension is assigned the os will use the appropriate binary (normaly an Editor) to open the file. Works perfectly on Windows if SciTE is installed. - webbrowser.open(self.Basename + '.inp') - + filename = self.Basename + '.inp' + print 'editCalculixInputFile {}'.format(filename) + from platform import system + if system() == 'Linux': + import FemGui + FemGui.openEditor(filename) + else: + import webbrowser + # If inp-file extension is assigned the os will use the appropriate binary + # (normaly an Editor) to open the file. Works perfectly on Windows if SciTE is installed. + # However using webbrower.open is not portable and not supported + # https://docs.python.org/3.4/library/webbrowser.html + # FIXME That code should be removed as soon as there is "Preferred editor" option + # added to Preferences, to allow existing SciTE users override built-in editor + webbrowser.open(filename) def runCalculix(self): print 'runCalculix'