BALL 1.5.0
Loading...
Searching...
No Matches
pyWidget.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_VIEW_WIDGETS_PYWIDGET_H
6#define BALL_VIEW_WIDGETS_PYWIDGET_H
7
8#ifndef BALL_COMMON_H
9# include <BALL/common.h>
10#endif
11
12#ifndef BALL_DATATYPE_STRING_H
13# include <BALL/DATATYPE/string.h>
14#endif
15
16#ifndef BALL_VIEW_WIDGETS_DOCKWIDGET_H
18#endif
19
20#ifndef BALL_VIEW_WIDGETS_TEXTEDITORWIDGET_H
22#endif
23
24#include <QtGui/QDragEnterEvent>
25#include <QtGui/QKeyEvent>
26#include <QtGui/QDropEvent>
27#include <QtWidgets/QLineEdit>
28#include <QtWidgets/QComboBox>
29#include <QtWidgets/QTabWidget>
30#include <QtGui/QSyntaxHighlighter>
31#include <QtGui/QValidator>
32#include <QtCore/QStringList>
33
34#include <QtCore/QThread>
35
36namespace BALL
37{
38 namespace VIEW
39 {
40
41class PythonSettings;
42class Preferences;
43
44class RunPythonThread;
45
50 : public QSyntaxHighlighter
51{
52 public:
53
55
57
59 void highlightBlock(const QString& text);
60
61 QStringList python_keywords;
62 QStringList BALL_keywords;
63 QTextCharFormat my_class_format;
64 QTextCharFormat python_format;
65 QTextCharFormat string_format;
66 QTextCharFormat comment_format;
67 vector<QRegExp> python_patterns;
68 vector<QRegExp> BALL_patterns;
71};
72
77 : public QValidator
78{
79 public:
82
83 virtual State validate(QString& input, int& pos) const;
84};
85
87 : public QThread
88{
89 public:
91
93 virtual void run();
94
95 bool state;
98};
99
102{
103
104 public:
105
106 static Hotkey createHotkey(String modifier, String key, String command,
107 bool& ok, String comment = "");
108
110 bool operator == (const Hotkey& hotkey) const;
111
113 bool operator == (const QKeyEvent& e) const;
114
116 const Hotkey& operator = (const Hotkey& s);
117
119 bool operator < (const Hotkey& key) { return this < &key;}
120
122 bool set(const String& data);
123
125 void get(String& data) const;
126
129 Qt::KeyboardModifiers button_state;
130 Qt::Key key;
131};
132
140 : public DockWidget
141{
142 class MyLineEdit
143 : public QLineEdit
144 {
145 public:
146 MyLineEdit(QWidget* parent)
147 : QLineEdit(parent) {};
148
149 void setPyWidget(PyWidget* pw) { pw_ = pw;}
150
151 protected:
152
153 virtual void keyPressEvent(QKeyEvent* event);
154
155 PyWidget* pw_;
156 };
157
158 class MyTextEdit
159 : public TextEditorWidget
160 {
161 public:
162 MyTextEdit(QWidget* parent)
163 : TextEditorWidget(parent) {};
164
165 void setPyWidget(PyWidget* pw) { pw_ = pw;}
166
167 protected:
168
169 virtual void keyPressEvent(QKeyEvent* event);
170
171 PyWidget* pw_;
172 };
173
174 friend class MyLineEdit;
175
176 Q_OBJECT
177
178 public:
179
181
182
185
186
192 PyWidget(QWidget* parent = 0, const char* name = 0);
193
196
199
201 bool isValid() const
202 { return valid_;}
203
207
210 virtual void initializeWidget(MainControl& main_control);
211
214 virtual void finalizeWidget(MainControl& main_control);
215
218
221
223 virtual void applyPreferences();
224
226 virtual void scriptDialog(bool run = false);
227
230
235 void map(String modifier, String key, String command, String comment = "");
236
238 void unmap(String modifier, String key);
239
241 void insertHotkey(const Hotkey& hotkey);
242
244 void removeHotkey(const Hotkey& hotkey);
245
247 void reactTo(const QKeyEvent& e);
248
254 virtual bool canHandle(const String& fileformat) const;
255
260 virtual bool openFile(const String& filename);
261
265 bool openFile(const String& filename, bool run, bool is_current = false);
266
267 //
268 bool runString(String command);
269
270 //
272
273 //
274 void dump(std::ostream& s, Size depth) const;
275
277 BALL_DEPRECATED void showClassDocu(String /* classname */, String /* member */);
278
279 //
280 virtual void fetchPreferences(INIFile& inifile);
281
282 //
283 virtual void writePreferences(INIFile& inifile);
284
285 //
286 void checkMenu(MainControl& main_control);
287
290
292 bool isInDirectMode() const;
293
294 public Q_SLOTS:
295
296 //
297 void showEditContextMenu(const QPoint& point);
298
299 //
300 void showContextMenu(const QPoint& point);
301
302 //
304
305 //
306 void clear();
307
308 //
310
311 //
313
316
319
322
325
328
331
332 virtual void hotkeyItem();
333
334 virtual void modifyHotkeys();
335
336 void appendText(const String& text, bool output = false, bool state_message = false);
337
338 bool getMembers(const String& classname, QStringList& sl, const String& prefix);
339
340 protected Q_SLOTS:
341
342 virtual bool returnPressed();
343
344 virtual bool completionSelected_();
345
348
349 virtual void printCursorPosition_();
350
351 virtual void createScript_();
352
353 virtual void clearHistory_();
354
355 protected:
356
358
359 void setError_(bool state);
360
366 virtual void startInterpreter();
367
368 virtual void paste();
369
371 bool parseLine_(String line);
372
373 void appendToHistory_(const String& line);
374
381
382 bool testMultilineStart_(const String& line);
383
384 //_
385 const char* getPrompt_() const;
386
387 //_
389
390 //_ Wrapper for multi and single threading call
391 String runCommand_(const String& command, bool& state);
392
394
402
403 virtual void contentsDragEnterEvent(QDragEnterEvent* e);
404
405 virtual void contentsDropEvent(QDropEvent* e);
406
407 bool keyPressed(QKeyEvent* e);
408
410 BALL_DEPRECATED void createMenuHelpEntry_(QMenu* /* menu */, TextEditorWidget* /* text_edit */, const QPoint& /* point */);
411
412 void findError_(String result);
413
414 String getCurrentWord_(QTextCursor& text_cursor);
415
416 QComboBox* getCompletionBox_();
417
418 std::list<Hotkey>::iterator findKey_(Hotkey& hotkey);
419
422 MyTextEdit* script_edit_;
423 QTabWidget* tab_widget_;
426 MyLineEdit* line_edit_;
427 QComboBox* combo_box_, *editor_combo_box_;
428 std::list<Hotkey> hotkeys_;
429 // we use an own working dir to find Python Scripts
431 bool valid_;
434
439 vector<String> history_;
440 vector<bool> results_;
447 String class_, member_;
450 bool silent_, full_silent_;
453};
454
455 } // namespaces
456} // namespaces
457
458#endif // BALL_VIEW_WIDGETS_PYWIDGET_H
#define BALL_EMBEDDABLE(TYPE, BASE)
Definition embeddable.h:31
QTextCharFormat comment_format
Definition pyWidget.h:66
QTextCharFormat python_format
Definition pyWidget.h:64
vector< QRegExp > BALL_patterns
Definition pyWidget.h:68
QTextCharFormat my_class_format
Definition pyWidget.h:63
QTextCharFormat string_format
Definition pyWidget.h:65
vector< QRegExp > python_patterns
Definition pyWidget.h:67
void highlightBlock(const QString &text)
PythonValidator(QObject *parent=0)
virtual State validate(QString &input, int &pos) const
static Hotkey createHotkey(String modifier, String key, String command, bool &ok, String comment="")
bool set(const String &data)
Qt::KeyboardModifiers button_state
Definition pyWidget.h:129
void get(String &data) const
virtual void writePreferences(INIFile &inifile)
void showEditContextMenu(const QPoint &point)
virtual void contentsDropEvent(QDropEvent *e)
virtual void contentsDragEnterEvent(QDragEnterEvent *e)
virtual bool returnPressed()
bool parseLine_(String line)
Parse a and execute a given string. If silent_ is set to true, no prompts are being printed.
std::list< Hotkey > hotkeys_
Definition pyWidget.h:428
virtual void initializeWidget(MainControl &main_control)
QString getCurrentScript()
PythonValidator validator_
Definition pyWidget.h:425
virtual bool canHandle(const String &fileformat) const
String runCommand_(const String &command, bool &state)
bool openFile(const String &filename, bool run, bool is_current=false)
String getCurrentLine() const
virtual void modifyHotkeys()
void appendText_(TextEditorWidget *te, String text)
virtual void hotkeyItem()
bool runString(String command)
virtual void clearHistory_()
void dump(std::ostream &s, Size depth) const
QLabel * curr_modifying_
Definition pyWidget.h:420
bool testMultilineStart_(const String &line)
virtual void scriptDialog(bool run=false)
Open a dialog to select a script.
MyLineEdit * line_edit_
Definition pyWidget.h:426
const char * getPrompt_() const
void showContextMenu(const QPoint &point)
vector< String > history_
Definition pyWidget.h:439
void removeHotkey(const Hotkey &hotkey)
bool getMembers(const String &classname, QStringList &sl, const String &prefix)
MyTextEdit * script_edit_
Definition pyWidget.h:422
void finalizePreferencesTab(Preferences &preferences)
virtual bool completionSelected_()
Preferences * preferences_
Definition pyWidget.h:433
void retrieveHistoryLine_(Position index)
TextEditorWidget * script_output_
Definition pyWidget.h:421
void map(String modifier, String key, String command, String comment="")
RunPythonThread * thread_
Definition pyWidget.h:444
Position current_line_
Definition pyWidget.h:435
void unmap(String modifier, String key)
see above
String getCurrentWord_(QTextCursor &text_cursor)
virtual void finalizeWidget(MainControl &main_control)
bool keyPressed(QKeyEvent *e)
virtual void printCursorPosition_()
virtual void fetchPreferences(INIFile &inifile)
BALL_DEPRECATED void showDocumentation()
virtual void createScript_()
void checkMenu(MainControl &main_control)
void appendText(const String &text, bool output=false, bool state_message=false)
QComboBox * getCompletionBox_()
QTabWidget * tab_widget_
Definition pyWidget.h:423
std::list< Hotkey >::iterator findKey_(Hotkey &hotkey)
virtual BALL_DEPRECATED void showHelp_()
bool isInDirectMode() const
BALL_DEPRECATED void createMenuHelpEntry_(QMenu *, TextEditorWidget *, const QPoint &)
void setError_(bool state)
void appendToHistory_(const String &line)
virtual bool openFile(const String &filename)
virtual void startInterpreter()
virtual void paste()
void insertHotkey(const Hotkey &hotkey)
virtual void applyPreferences()
bool getClassAndMember_(String toc)
void findError_(String result)
PythonHighlighter highlighter_1_
Definition pyWidget.h:424
BALL_DEPRECATED void showClassDocu(String, String)
PythonSettings * python_settings_
Definition pyWidget.h:443
void initializePreferencesTab(Preferences &preferences)
vector< bool > results_
Definition pyWidget.h:440
QComboBox * combo_box_
Definition pyWidget.h:427
void reactTo(const QKeyEvent &e)
Position history_position_
Definition pyWidget.h:441
#define BALL_DEPRECATED
#define BALL_VIEW_EXPORT