SMILX  1.01
milxQtPythonPlugin.h
1 /*=========================================================================
2  The Software is copyright (c) Commonwealth Scientific and Industrial Research Organisation (CSIRO)
3  ABN 41 687 119 230.
4  All rights reserved.
5 
6  Licensed under the CSIRO BSD 3-Clause License
7  You may not use this file except in compliance with the License.
8  You may obtain a copy of the License in the file LICENSE.md or at
9 
10  https://stash.csiro.au/projects/SMILI/repos/smili/browse/license.txt
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 =========================================================================*/
18 #ifndef MILXQTPYTHONPLUGIN_H
19 #define MILXQTPYTHONPLUGIN_H
20 
21 #include <QSyntaxHighlighter>
22 
23 #include <milxQtMain.h>
24 #include <milxQtFile.h>
25 #include <milxQtUnifiedWindow.h>
26 #include <milxQtPluginInterface.h>
27 
28 #include "milxQtPythonConsole.h"
29 
30 const int consoleMinHeight = 96;
31 
33 {
34  Q_OBJECT
35 
36 public:
37  milxQtPythonPlugin(QObject *theParent = 0);
39 
40  QString name();
41 
42  inline bool hasOpenSupport()
43  { return false; }
44  QString openFileSupport();
45  QStringList openExtensions();
46  inline bool hasSaveSupport()
47  { return false; }
48  QString saveFileSupport();
49  QStringList saveExtensions();
50 
51  inline bool hasCollectionSupport()
52  { return false; }
53  void SetInputCollection(vtkPolyDataCollection* collection, QStringList &filenames);
54 
55  void open(QString filename);
56  void save(QString filename);
57 
61  QDockWidget* dockWidget();
62  inline Qt::DockWidgetArea dockDefaultArea()
63  { return Qt::BottomDockWidgetArea; }
64 
65  bool isPluginWindow(QWidget *window);
66 
70  milxQtPythonConsole* pluginWindow(QWidget *window);
71 
72 public slots:
73  void resizeForFloat(bool floating);
74  void addObject(milxQtRenderWindow *rnd)
75  { mainContext.addObject("rnd_" + rnd->strippedBaseName(), rnd); }
76  void addObject(milxQtImage *img)
77  { mainContext.addObject("img_" + img->strippedBaseName(), img); }
78  void addObject(milxQtModel *mdl)
79  { mainContext.addObject("mdl_" + mdl->strippedBaseName(), mdl); }
80  virtual void loadExtension() {}
81  virtual void update() {}
82  void preStartTasks() {}
83  void postStartTasks() {}
84 
85 protected:
86  QPointer<milxQtPythonConsole> pyConsole;
87  QPointer<QDockWidget> dock;
88 
89  QPointer<milxQtMain> MainWindow;
90 
91  PythonQtObjectPtr mainContext;
92 
93  void run();
94  void setupPython();
95  void createConnections();
96 
97 private:
98 
99 };
100 
102 {
103  Q_OBJECT
104  Q_INTERFACES(milxQtPluginFactory)
105 
106 public:
107  milxQtPluginInterface* newPlugin(QObject *theParent = 0)
108  { return new milxQtPythonPlugin(theParent); }
109 };
110 
111 //Syntax Highlighter
120 class MILXQT_PLUGIN_EXPORT milxQtPythonSyntaxHighlighter : public QSyntaxHighlighter
121 {
122 public:
123  milxQtPythonSyntaxHighlighter(QTextEdit *textEdit);
124 
125  void highlightBlock(const QString &text);
126 
127 private:
128  struct HighlightingRule
129  {
130  QRegExp pattern;
131  QTextCharFormat format;
132  };
133  QList<HighlightingRule> highlightingRules;
134  QStringList keywords;
135 
136  QTextCharFormat keywordFormat;
137  QTextCharFormat singleLineCommentFormat;
138  QTextCharFormat multiLineCommentFormat;
139  QTextCharFormat multiLineEscapeFormat;
140  QTextCharFormat quotationFormat;
141  QTextCharFormat singleQuotationFormat;
142 
143  QRegExp commentStartExpression;
144  QRegExp commentEndExpression;
145  QRegExp escapeStartExpression;
146  QRegExp escapeEndExpression;
147 };
148 
149 #endif // MILXQTPYTHONPLUGIN_H
QPointer< milxQtPythonConsole > pyConsole
Python Console widget.
bool hasSaveSupport()
Does the plugin support opening files? [Implement this in your plugin].
virtual QDockWidget * dockWidget()=0
Return the dock widget (if one is provided by plugin). [Implement this in your plugin].
virtual QString saveFileSupport()=0
Get the file support string for saving (extension wildcard list). [Implement this in your plugin]...
virtual milxQtImage * imageResult()=0
Get the image result. The result can then be displayed in milxQtMain etc.[Implement this in your plug...
This class represents the MILX Qt Render Window Display object using QVTK.
virtual QStringList saveExtensions()=0
Get a list of supported file format extensions. [Implement this in your plugin].
This class represents the MILX Qt Image Display object using VTK.
Definition: milxQtImage.h:118
virtual QStringList openExtensions()=0
Get a list of supported file format extensions. [Implement this in your plugin].
virtual void loadExtension()=0
Load the extension. [Implement this in your plugin].
bool hasCollectionSupport()
Does the plugin support collections (PolyData collection etc.). [Implement this in your plugin]...
virtual void postStartTasks()=0
Tasks to complete after running or starting the thread. [Implement this].
virtual QString name()=0
Get the Name of the plugin. [Implement this in your plugin].
This class represents the MILX Qt Model/Mesh Display object using VTK.
Definition: milxQtModel.h:115
Syntax highlighting for Python to be applied to the console (such as milxQtPythonConsole).
virtual void SetInputCollection(vtkPolyDataCollection *collection, QStringList &filenames)=0
Pass a collection to internal plugin class. [Implement this in your plugin].
virtual void preStartTasks()=0
Tasks to complete before running or starting the thread. [Implement this].
The interface for any plugins that can be made for milxQtMain.
virtual void update()=0
Update the plugin. [Implement this in your plugin].
virtual bool isPluginWindow(QWidget *window)=0
Is the window provided a plugin generated window? In this case a milxQtShapeModel window...
virtual milxQtModel * modelResult()=0
Get the model result. The result can then be displayed in milxQtMain etc. [Implement this in your plu...
QPointer< QDockWidget > dock
Dock widget.
QString strippedBaseName()
Returns the stripped (path removed) base (no suffix) name of the data.
Definition: milxQtWindow.h:88
virtual milxQtRenderWindow * genericResult()=0
Get the generic result, which is a milxQtRenderWindow. The result can then be displayed in milxQtMain...
virtual QString openFileSupport()=0
Get the file support string for opening (extension wildcard list). [Implement this in your plugin]...
bool hasOpenSupport()
Does the plugin support opening files? [Implement this in your plugin].
virtual void open(QString filename)=0
Open the file using the plugin. [Implement this in your plugin].
#define MILXQT_PLUGIN_EXPORT
Define Windows Plugin DLL importing.
Qt::DockWidgetArea dockDefaultArea()
Return the default dock widget area (if one is provided by plugin). [Implement this in your plugin]...
A simple console for python scripting with some syntax highlighting.
virtual void save(QString filename)=0
Save the result as a file using the plugin. [Implement this in your plugin].
PythonQtObjectPtr mainContext
Python Context to Python Intepreter.