MIRA
PythonEditor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Redistribution and modification of this code is strictly prohibited.
9  *
10  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
11  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
13  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
20  */
21 
30 #ifndef _MIRA_TOOLBOXES_PYTHON_PYTHONEDITOR_H_
31 #define _MIRA_TOOLBOXES_PYTHON_PYTHONEDITOR_H_
32 
33 #include <QEvent>
34 
35 #include <fw/Framework.h>
36 #include <rcp/EditorPart.h>
37 
38 class QTextEdit;
39 
40 namespace mira { namespace python {
41 
43 
44 class PythonEditorUI : public QWidget
45 {
46  Q_OBJECT;
47 
48  friend class PythonEditor;
49 
50 public:
51  PythonEditorUI(QWidget* parent) :
52  QWidget(parent)
53  {
54  setupUi();
55  }
56 
57 public slots:
58  void onExecuteScript();
59  void clearHighlight();
60 
61 protected:
62  void setupUi();
63  void highlightLine(int line, const QColor& background, const QColor& underline);
64  void backgroundHighlightLine(int line, const QColor& color);
65  void underlineHighlightLine(int line, const QColor& color);
66 
67  QTextEdit* mLEExecuteScript;
68  QTextEdit* mLEMessage;
69 };
70 
72 
73 class PythonEditor : public EditorPart
74 {
75 Q_OBJECT
76 
78  ("Name", "Python editor view")
79  ("Category", "Script")
80  ("Description", "Python console"))
81 
82 protected:
83  const static std::string sDefaultPythonProgram;
84 
85 public:
86  PythonEditor();
87  virtual ~PythonEditor() {}
88 
89  template<typename Reflector>
90  void reflect(Reflector& r)
91  {
92  r.member("EditorText",
95  "Editor's program", sDefaultPythonProgram);
96  r.property("ShowWhitespace", mShowWhitespace,
98  "Show tabs and spaces", false);
99  r.property("ShowSeparators", mShowSeparators,
100  setter<bool>(&PythonEditor::onShowSeparators, this),
101  "Show line and paragraph separators", false);
102  }
103 
104  virtual QWidget* createPartControl();
105 
106  void setEditorText(const std::string& text);
107  std::string getEditorText() const;
108 
109 protected slots:
110  void onShowWhitespace(bool show);
111  void onShowSeparators(bool show);
112 
113 protected:
114  void updateTextDisplay();
115 
116 protected:
118 
120  std::string mEditorText;
121 
124 };
125 
127 
128 }} // namespace
129 
130 #endif
virtual QWidget * createPartControl()
Setter< T > setter(void(*f)(const T &))
void underlineHighlightLine(int line, const QColor &color)
QTextEdit * mLEExecuteScript
Definition: PythonEditor.h:67
void onShowSeparators(bool show)
PythonEditorUI * mUI
Definition: PythonEditor.h:119
#define MIRA_META_OBJECT(classIdentifier, MetaInfo)
Definition: PythonEditor.h:73
std::string mEditorText
Definition: PythonEditor.h:120
Getter< T > getter(T(*f)())
PythonEditorUI(QWidget *parent)
Definition: PythonEditor.h:51
bool mShowWhitespace
Definition: PythonEditor.h:122
QTextEdit * mLEMessage
Definition: PythonEditor.h:68
virtual ~PythonEditor()
Definition: PythonEditor.h:87
void backgroundHighlightLine(int line, const QColor &color)
void onShowWhitespace(bool show)
void highlightLine(int line, const QColor &background, const QColor &underline)
void reflect(Reflector &r)
Definition: PythonEditor.h:90
void setEditorText(const std::string &text)
bool mShowSeparators
Definition: PythonEditor.h:123
std::string getEditorText() const
Authority mAuthority
Definition: PythonEditor.h:117
Definition: PythonEditor.h:44