18 #include "milxQtPythonPlugin.h" 25 MainWindow = qobject_cast<
milxQtMain *>(theParent);
31 pluginName =
"Python";
36 dock =
new QDockWidget(tr(
"Python Console"));
37 dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
42 highlighter->rehighlight();
47 milxQtPythonPlugin::~milxQtPythonPlugin()
51 cerr <<
"Python Plugin Destroyed." << endl;
61 QString openPythonExt =
"";
82 QString savePythonExt =
"";
141 QMutexLocker locker(&mutex);
151 PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
165 mainContext.addObject(
"milxQtUnifiedWindow", unified);
169 void milxQtPythonPlugin::createConnections()
171 QObject::connect(
dock, SIGNAL(topLevelChanged(
bool)),
this, SLOT(resizeForFloat(
bool)));
177 void milxQtPythonPlugin::resizeForFloat(
bool floating)
182 pyConsole->setMaximumHeight(QWIDGETSIZE_MAX);
187 pyConsole->setMaximumHeight(consoleMinHeight);
197 keywords <<
"\\band\\b" <<
"\\bassert\bb" <<
"\\bbreak\\b" <<
"\\bclass\\b" <<
"\\bcontinue\\b" <<
"\\bdef\\b" 198 <<
"\\bdel\\b" <<
"\\belif\\b" <<
"\\belse\\b" <<
"\\bexcept\\b" <<
"\\bexec\\b" <<
"\\bfinally\\b" 199 <<
"\\bfor\\b" <<
"\\bfrom\\b" <<
"\\bglobal\\b" <<
"\\bif\\b" <<
"\\bimport\\b" <<
"\\bin\\b" 200 <<
"\\bis\\b" <<
"\\blambda\\b" <<
"\\bnot\\b" <<
"\\bor\\b" <<
"\\bpass\\b" <<
"\\bprint\\b" <<
"\\braise\\b" 201 <<
"\\breturn\\b" <<
"\\btry\\b" <<
"\\bwhile\\b" <<
"\\byield\\b";
203 HighlightingRule rule;
205 keywordFormat.setForeground(Qt::darkBlue);
206 keywordFormat.setFontWeight(QFont::Bold);
208 multiLineCommentFormat.setForeground(Qt::darkRed);
209 multiLineEscapeFormat.setForeground(Qt::black);
213 commentStartExpression = QRegExp(
"/\\*");
214 commentEndExpression = QRegExp(
"\\*/");
215 escapeStartExpression = QRegExp(
"/\\@");
216 escapeEndExpression = QRegExp(
"\\@/");
219 foreach (
const QString &pattern, keywords)
221 rule.pattern = QRegExp(pattern);
222 rule.format = keywordFormat;
223 highlightingRules.append(rule);
227 quotationFormat.setForeground(Qt::magenta);
228 rule.pattern = QRegExp(
"\".*\"");
229 rule.format = quotationFormat;
230 highlightingRules.append(rule);
233 singleQuotationFormat.setForeground(Qt::darkYellow);
234 rule.pattern = QRegExp(
"'.*'");
235 rule.format = singleQuotationFormat;
236 highlightingRules.append(rule);
239 singleLineCommentFormat.setForeground(Qt::darkRed);
240 rule.pattern = QRegExp(
"#[^\n]*");
241 rule.format = singleLineCommentFormat;
242 highlightingRules.append(rule);
247 foreach (
const HighlightingRule &rule, highlightingRules)
249 QRegExp expression(rule.pattern);
250 int index = expression.indexIn(text);
253 int length = expression.matchedLength();
254 setFormat(index, length, rule.format);
255 index = expression.indexIn(text, index + length);
258 setCurrentBlockState(0);
262 if (previousBlockState() != 1)
263 startIndex = commentStartExpression.indexIn(text);
265 while (startIndex >= 0)
267 int endIndex = commentEndExpression.indexIn(text, startIndex);
272 setCurrentBlockState(1);
273 commentLength = text.length() - startIndex;
276 commentLength = endIndex - startIndex + commentEndExpression.matchedLength();
278 setFormat(startIndex, commentLength, multiLineCommentFormat);
279 startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
284 if (previousBlockState() != 2)
285 startIndex = escapeStartExpression.indexIn(text);
287 while (startIndex >= 0)
289 int endIndex = escapeEndExpression.indexIn(text, startIndex);
294 setCurrentBlockState(2);
295 commentLength = text.length() - startIndex;
298 commentLength = endIndex - startIndex + escapeEndExpression.matchedLength();
300 setFormat(startIndex, commentLength, multiLineEscapeFormat);
301 startIndex = escapeStartExpression.indexIn(text, startIndex + commentLength);
QPointer< milxQtPythonConsole > pyConsole
Python Console widget.
QStringList openExtensions()
Get a list of supported file format extensions. [Implement this in your plugin].
bool threaded
Threaded plugin?
void SetInputCollection(vtkPolyDataCollection *collection, QStringList &filenames)
Pass a collection to internal plugin class. [Implement this in your plugin].
QString saveFileSupport()
Get the file support string for saving (extension wildcard list). [Implement this in your plugin]...
This class represents the MILX Qt Render Window Display object using QVTK.
milxQtModel * modelResult()
Get the model result. The result can then be displayed in milxQtMain etc. [Implement this in your plu...
bool consoleWindow
console window?
This class represents the MILX Qt Image Display object using VTK.
milxQtRenderWindow * genericResult()
Get the generic result, which is a milxQtRenderWindow. The result can then be displayed in milxQtMain...
bool extension
Extension rather than a plugin?
This class represents the MILX Qt File I/O object using VTK/ITK/Qt.
void highlightBlock(const QString &text)
This class represents the MILX Qt Model/Mesh Display object using VTK.
void save(QString filename)
Save the result as a file using the plugin. [Implement this in your plugin].
bool dockable
Dockable plugin?
Syntax highlighting for Python to be applied to the console (such as milxQtPythonConsole).
The class maintains a state and render of multiple display objects (such as a milxQtModel or milxQtIm...
void open(QString filename)
Open the file using the plugin. [Implement this in your plugin].
The interface for any plugins that can be made for milxQtMain.
milxQtPythonConsole * pluginWindow(QWidget *window)
QStringList saveExtensions()
Get a list of supported file format extensions. [Implement this in your plugin].
QPointer< QDockWidget > dock
Dock widget.
QString openFileSupport()
Get the file support string for opening (extension wildcard list). [Implement this in your plugin]...
milxQtPythonPlugin(QObject *theParent=0)
milxQtPythonSyntaxHighlighter(QTextEdit *textEdit)
QString name()
Get the Name of the plugin. [Implement this in your plugin].
This class represents the MILX Qt Main Window object using Qt.
QDockWidget * dockWidget()
Return the dock widget (if one is provided by plugin). [Implement this in your plugin].
A simple console for python scripting with some syntax highlighting.
PythonQtObjectPtr mainContext
Python Context to Python Intepreter.
milxQtImage * imageResult()
Get the image result. The result can then be displayed in milxQtMain etc.[Implement this in your plug...
bool isPluginWindow(QWidget *window)
Is the window provided a plugin generated window? In this case a milxQtShapeModel window...