+ FEM: Use existing internal editor for inp files
This commit is contained in:
parent
bf7bc3532e
commit
18e4fdf5c2
|
@ -24,12 +24,17 @@
|
|||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <Python.h>
|
||||
# include <QFileInfo>
|
||||
#endif
|
||||
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/ViewProviderDocumentObject.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/TextEdit.h>
|
||||
#include <Gui/EditorView.h>
|
||||
|
||||
#include <Mod/Fem/App/FemAnalysis.h>
|
||||
#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<Gui::EditorView*> views = Gui::getMainWindow()->findChildren<Gui::EditorView*>();
|
||||
for (QList<Gui::EditorView*>::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 */
|
||||
};
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<file>icons/Fem_AddFemMesh.svg</file>
|
||||
<file>icons/Fem_AddMaterial.svg</file>
|
||||
<file>icons/Fem_AddPart.svg</file>
|
||||
<file>icons/Fem_Inp_Editor.svg</file>
|
||||
<file>icons/Fem_Material.svg</file>
|
||||
<file>icons/Fem_NewAnalysis.svg</file>
|
||||
<file>icons/Fem_Result.svg</file>
|
||||
|
|
252
src/Mod/Fem/Gui/Resources/icons/Fem_Inp_Editor.svg
Normal file
252
src/Mod/Fem/Gui/Resources/icons/Fem_Inp_Editor.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 50 KiB |
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue
Block a user