Loading...
Searching...
No Matches
pyWidget.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_VIEW_WIDGETS_PYWIDGET_H
#define BALL_VIEW_WIDGETS_PYWIDGET_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_DATATYPE_STRING_H
# include <BALL/DATATYPE/string.h>
#endif
#ifndef BALL_VIEW_WIDGETS_DOCKWIDGET_H
# include <BALL/VIEW/WIDGETS/dockWidget.h>
#endif
#ifndef BALL_VIEW_WIDGETS_TEXTEDITORWIDGET_H
# include <BALL/VIEW/WIDGETS/textEditorWidget.h>
#endif
#include <QtGui/QDragEnterEvent>
#include <QtGui/QKeyEvent>
#include <QtGui/QDropEvent>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QTabWidget>
#include <QtGui/QSyntaxHighlighter>
#include <QtGui/QValidator>
#include <QtCore/QStringList>
#include <QtCore/QThread>
namespace BALL
{
namespace VIEW
{
class PythonSettings;
class Preferences;
class RunPythonThread;
class BALL_VIEW_EXPORT BALL_DEPRECATED PythonHighlighter
: public QSyntaxHighlighter
{
public:
PythonHighlighter();
~PythonHighlighter() {};
void compilePattern();
void highlightBlock(const QString& text);
QStringList python_keywords;
QStringList BALL_keywords;
QTextCharFormat my_class_format;
QTextCharFormat python_format;
QTextCharFormat string_format;
QTextCharFormat comment_format;
vector<QRegExp> python_patterns;
vector<QRegExp> BALL_patterns;
QRegExp string_pattern;
QRegExp comment_pattern;
};
class BALL_VIEW_EXPORT BALL_DEPRECATED PythonValidator
: public QValidator
{
public:
PythonValidator(QObject* parent = 0);
virtual ~PythonValidator();
virtual State validate(QString& input, int& pos) const;
};
class BALL_VIEW_EXPORT BALL_DEPRECATED RunPythonThread
: public QThread
{
public:
RunPythonThread();
virtual void run();
bool state;
String input;
String output;
};
struct BALL_VIEW_EXPORT BALL_DEPRECATED Hotkey
{
public:
static Hotkey createHotkey(String modifier, String key, String command,
bool& ok, String comment = "");
bool operator == (const Hotkey& hotkey) const;
bool operator == (const QKeyEvent& e) const;
const Hotkey& operator = (const Hotkey& s);
bool operator < (const Hotkey& key) { return this < &key;}
bool set(const String& data);
void get(String& data) const;
String comment;
String action;
Qt::KeyboardModifiers button_state;
Qt::Key key;
};
class BALL_VIEW_EXPORT BALL_DEPRECATED PyWidget
: public DockWidget
{
class MyLineEdit
: public QLineEdit
{
public:
MyLineEdit(QWidget* parent)
: QLineEdit(parent) {};
void setPyWidget(PyWidget* pw) { pw_ = pw;}
protected:
virtual void keyPressEvent(QKeyEvent* event);
PyWidget* pw_;
};
class MyTextEdit
: public TextEditorWidget
{
public:
MyTextEdit(QWidget* parent)
: TextEditorWidget(parent) {};
void setPyWidget(PyWidget* pw) { pw_ = pw;}
protected:
virtual void keyPressEvent(QKeyEvent* event);
PyWidget* pw_;
};
friend class MyLineEdit;
Q_OBJECT
public:
BALL_EMBEDDABLE(PyWidget, Embeddable)
PyWidget(QWidget* parent = 0, const char* name = 0);
PyWidget(const PyWidget& p);
~PyWidget();
bool isValid() const
{ return valid_;}
virtual void initializeWidget(MainControl& main_control);
virtual void finalizeWidget(MainControl& main_control);
void initializePreferencesTab(Preferences &preferences);
void finalizePreferencesTab(Preferences &preferences);
virtual void applyPreferences();
virtual void scriptDialog(bool run = false);
bool toAbortScript();
void map(String modifier, String key, String command, String comment = "");
void unmap(String modifier, String key);
void insertHotkey(const Hotkey& hotkey);
void removeHotkey(const Hotkey& hotkey);
void reactTo(const QKeyEvent& e);
virtual bool canHandle(const String& fileformat) const;
virtual bool openFile(const String& filename);
bool openFile(const String& filename, bool run, bool is_current = false);
//
bool runString(String command);
//
String getCurrentLine() const;
//
void dump(std::ostream& s, Size depth) const;
BALL_DEPRECATED void showClassDocu(String /* classname */, String /* member */);
//
virtual void fetchPreferences(INIFile& inifile);
//
virtual void writePreferences(INIFile& inifile);
//
void checkMenu(MainControl& main_control);
QString getCurrentScript();
bool isInDirectMode() const;
public Q_SLOTS:
//
void showEditContextMenu(const QPoint& point);
//
void showContextMenu(const QPoint& point);
//
void showCompletion();
//
void clear();
//
void exportHistory();
//
void abortScript();
BALL_DEPRECATED void showDocumentation();
bool runCurrentScript();
void loadScript();
void execScript();
void saveScript();
void clearScript();
virtual void hotkeyItem();
virtual void modifyHotkeys();
void appendText(const String& text, bool output = false, bool state_message = false);
bool getMembers(const String& classname, QStringList& sl, const String& prefix);
protected Q_SLOTS:
virtual bool returnPressed();
virtual bool completionSelected_();
BALL_DEPRECATED virtual void showHelp_();
virtual void printCursorPosition_();
virtual void createScript_();
virtual void clearHistory_();
protected:
bool getClassAndMember_(String toc);
void setError_(bool state);
virtual void startInterpreter();
virtual void paste();
bool parseLine_(String line);
void appendToHistory_(const String& line);
void newPrompt_();
bool testMultilineStart_(const String& line);
//_
const char* getPrompt_() const;
//_
bool storeScript_();
//_ Wrapper for multi and single threading call
String runCommand_(const String& command, bool& state);
void appendText_(TextEditorWidget* te, String text);
void retrieveHistoryLine_(Position index);
virtual void contentsDragEnterEvent(QDragEnterEvent* e);
virtual void contentsDropEvent(QDropEvent* e);
bool keyPressed(QKeyEvent* e);
BALL_DEPRECATED void createMenuHelpEntry_(QMenu* /* menu */, TextEditorWidget* /* text_edit */, const QPoint& /* point */);
void findError_(String result);
String getCurrentWord_(QTextCursor& text_cursor);
QComboBox* getCompletionBox_();
std::list<Hotkey>::iterator findKey_(Hotkey& hotkey);
QLabel* curr_modifying_;
TextEditorWidget* text_edit_, *script_output_;
MyTextEdit* script_edit_;
QTabWidget* tab_widget_;
PythonHighlighter highlighter_1_, highlighter_2_;
PythonValidator validator_;
MyLineEdit* line_edit_;
QComboBox* combo_box_, *editor_combo_box_;
std::list<Hotkey> hotkeys_;
// we use an own working dir to find Python Scripts
String working_dir_;
bool valid_;
bool started_startup_script_;
Preferences* preferences_;
Position current_line_;
bool multi_line_mode_;
Size multi_lines_;
String multi_line_text_;
vector<String> history_;
vector<bool> results_;
Position history_position_;
String startup_script_;
PythonSettings* python_settings_;
RunPythonThread* thread_;
bool stop_script_;
Size complete_prefix_;
String class_, member_;
Position intend_;
bool running_;
bool silent_, full_silent_;
bool script_mode_;
String current_script_;
};
} // namespaces
} // namespaces
#endif // BALL_VIEW_WIDGETS_PYWIDGET_H
BALL_DEPRECATED
#define BALL_DEPRECATED
Definition COMMON/global.h:64
BALL_VIEW_EXPORT
#define BALL_VIEW_EXPORT
Definition COMMON/global.h:52
BALL::Embeddable::Embeddable
Embeddable(const String &identifier="<Embeddable>")
BALL::INIFile
Definition INIFile.h:29
BALL::String
Definition string.h:57
BALL::VIEW::DockWidget::DockWidget
DockWidget(QWidget *parent, const char *title=0)
Use this constructor!
BALL::VIEW::MainControl
Definition mainControl.h:118
BALL::VIEW::Preferences
Definition preferences.h:43
BALL::VIEW::PyWidget::writePreferences
virtual void writePreferences(INIFile &inifile)
BALL::VIEW::PyWidget::showEditContextMenu
void showEditContextMenu(const QPoint &point)
BALL::VIEW::PyWidget::text_edit_
TextEditorWidget * text_edit_
Definition pyWidget.h:421
BALL::VIEW::PyWidget::contentsDropEvent
virtual void contentsDropEvent(QDropEvent *e)
BALL::VIEW::PyWidget::contentsDragEnterEvent
virtual void contentsDragEnterEvent(QDragEnterEvent *e)
BALL::VIEW::PyWidget::returnPressed
virtual bool returnPressed()
BALL::VIEW::PyWidget::parseLine_
bool parseLine_(String line)
Parse a and execute a given string. If silent_ is set to true, no prompts are being printed.
BALL::VIEW::PyWidget::hotkeys_
std::list< Hotkey > hotkeys_
Definition pyWidget.h:428
BALL::VIEW::PyWidget::initializeWidget
virtual void initializeWidget(MainControl &main_control)
BALL::VIEW::PyWidget::exportHistory
void exportHistory()
BALL::VIEW::PyWidget::getCurrentScript
QString getCurrentScript()
BALL::VIEW::PyWidget::validator_
PythonValidator validator_
Definition pyWidget.h:425
BALL::VIEW::PyWidget::canHandle
virtual bool canHandle(const String &fileformat) const
BALL::VIEW::PyWidget::runCurrentScript
bool runCurrentScript()
BALL::VIEW::PyWidget::execScript
void execScript()
BALL::VIEW::PyWidget::runCommand_
String runCommand_(const String &command, bool &state)
BALL::VIEW::PyWidget::openFile
bool openFile(const String &filename, bool run, bool is_current=false)
BALL::VIEW::PyWidget::showCompletion
void showCompletion()
BALL::VIEW::PyWidget::getCurrentLine
String getCurrentLine() const
BALL::VIEW::PyWidget::modifyHotkeys
virtual void modifyHotkeys()
BALL::VIEW::PyWidget::member_
String member_
Definition pyWidget.h:447
BALL::VIEW::PyWidget::appendText_
void appendText_(TextEditorWidget *te, String text)
BALL::VIEW::PyWidget::hotkeyItem
virtual void hotkeyItem()
BALL::VIEW::PyWidget::script_mode_
bool script_mode_
Definition pyWidget.h:451
BALL::VIEW::PyWidget::runString
bool runString(String command)
BALL::VIEW::PyWidget::PyWidget
PyWidget(QWidget *parent=0, const char *name=0)
BALL::VIEW::PyWidget::clearHistory_
virtual void clearHistory_()
BALL::VIEW::PyWidget::dump
void dump(std::ostream &s, Size depth) const
BALL::VIEW::PyWidget::curr_modifying_
QLabel * curr_modifying_
Definition pyWidget.h:420
BALL::VIEW::PyWidget::newPrompt_
void newPrompt_()
BALL::VIEW::PyWidget::testMultilineStart_
bool testMultilineStart_(const String &line)
BALL::VIEW::PyWidget::scriptDialog
virtual void scriptDialog(bool run=false)
Open a dialog to select a script.
BALL::VIEW::PyWidget::startup_script_
String startup_script_
Definition pyWidget.h:442
BALL::VIEW::PyWidget::highlighter_2_
PythonHighlighter highlighter_2_
Definition pyWidget.h:424
BALL::VIEW::PyWidget::saveScript
void saveScript()
BALL::VIEW::PyWidget::line_edit_
MyLineEdit * line_edit_
Definition pyWidget.h:426
BALL::VIEW::PyWidget::stop_script_
bool stop_script_
Definition pyWidget.h:445
BALL::VIEW::PyWidget::getPrompt_
const char * getPrompt_() const
BALL::VIEW::PyWidget::showContextMenu
void showContextMenu(const QPoint &point)
BALL::VIEW::PyWidget::history_
vector< String > history_
Definition pyWidget.h:439
BALL::VIEW::PyWidget::removeHotkey
void removeHotkey(const Hotkey &hotkey)
BALL::VIEW::PyWidget::getMembers
bool getMembers(const String &classname, QStringList &sl, const String &prefix)
BALL::VIEW::PyWidget::isValid
bool isValid() const
Is full Python support available?
Definition pyWidget.h:201
BALL::VIEW::PyWidget::multi_lines_
Size multi_lines_
Definition pyWidget.h:437
BALL::VIEW::PyWidget::script_edit_
MyTextEdit * script_edit_
Definition pyWidget.h:422
BALL::VIEW::PyWidget::started_startup_script_
bool started_startup_script_
Definition pyWidget.h:432
BALL::VIEW::PyWidget::full_silent_
bool full_silent_
Definition pyWidget.h:450
BALL::VIEW::PyWidget::finalizePreferencesTab
void finalizePreferencesTab(Preferences &preferences)
BALL::VIEW::PyWidget::completionSelected_
virtual bool completionSelected_()
BALL::VIEW::PyWidget::preferences_
Preferences * preferences_
Definition pyWidget.h:433
BALL::VIEW::PyWidget::retrieveHistoryLine_
void retrieveHistoryLine_(Position index)
BALL::VIEW::PyWidget::valid_
bool valid_
Definition pyWidget.h:431
BALL::VIEW::PyWidget::multi_line_text_
String multi_line_text_
Definition pyWidget.h:438
BALL::VIEW::PyWidget::script_output_
TextEditorWidget * script_output_
Definition pyWidget.h:421
BALL::VIEW::PyWidget::map
void map(String modifier, String key, String command, String comment="")
BALL::VIEW::PyWidget::thread_
RunPythonThread * thread_
Definition pyWidget.h:444
BALL::VIEW::PyWidget::current_line_
Position current_line_
Definition pyWidget.h:435
BALL::VIEW::PyWidget::unmap
void unmap(String modifier, String key)
see above
BALL::VIEW::PyWidget::getCurrentWord_
String getCurrentWord_(QTextCursor &text_cursor)
BALL::VIEW::PyWidget::finalizeWidget
virtual void finalizeWidget(MainControl &main_control)
BALL::VIEW::PyWidget::keyPressed
bool keyPressed(QKeyEvent *e)
BALL::VIEW::PyWidget::printCursorPosition_
virtual void printCursorPosition_()
BALL::VIEW::PyWidget::fetchPreferences
virtual void fetchPreferences(INIFile &inifile)
BALL::VIEW::PyWidget::running_
bool running_
Definition pyWidget.h:449
BALL::VIEW::PyWidget::showDocumentation
BALL_DEPRECATED void showDocumentation()
BALL::VIEW::PyWidget::complete_prefix_
Size complete_prefix_
Definition pyWidget.h:446
BALL::VIEW::PyWidget::createScript_
virtual void createScript_()
BALL::VIEW::PyWidget::checkMenu
void checkMenu(MainControl &main_control)
BALL::VIEW::PyWidget::appendText
void appendText(const String &text, bool output=false, bool state_message=false)
BALL::VIEW::PyWidget::getCompletionBox_
QComboBox * getCompletionBox_()
BALL::VIEW::PyWidget::tab_widget_
QTabWidget * tab_widget_
Definition pyWidget.h:423
BALL::VIEW::PyWidget::findKey_
std::list< Hotkey >::iterator findKey_(Hotkey &hotkey)
BALL::VIEW::PyWidget::editor_combo_box_
QComboBox * editor_combo_box_
Definition pyWidget.h:427
BALL::VIEW::PyWidget::showHelp_
virtual BALL_DEPRECATED void showHelp_()
BALL::VIEW::PyWidget::isInDirectMode
bool isInDirectMode() const
BALL::VIEW::PyWidget::createMenuHelpEntry_
BALL_DEPRECATED void createMenuHelpEntry_(QMenu *, TextEditorWidget *, const QPoint &)
BALL::VIEW::PyWidget::setError_
void setError_(bool state)
BALL::VIEW::PyWidget::intend_
Position intend_
Definition pyWidget.h:448
BALL::VIEW::PyWidget::appendToHistory_
void appendToHistory_(const String &line)
BALL::VIEW::PyWidget::class_
String class_
Definition pyWidget.h:447
BALL::VIEW::PyWidget::openFile
virtual bool openFile(const String &filename)
BALL::VIEW::PyWidget::storeScript_
bool storeScript_()
BALL::VIEW::PyWidget::startInterpreter
virtual void startInterpreter()
BALL::VIEW::PyWidget::paste
virtual void paste()
BALL::VIEW::PyWidget::insertHotkey
void insertHotkey(const Hotkey &hotkey)
BALL::VIEW::PyWidget::abortScript
void abortScript()
BALL::VIEW::PyWidget::current_script_
String current_script_
Definition pyWidget.h:452
BALL::VIEW::PyWidget::toAbortScript
bool toAbortScript()
BALL::VIEW::PyWidget::applyPreferences
virtual void applyPreferences()
BALL::VIEW::PyWidget::clearScript
void clearScript()
BALL::VIEW::PyWidget::clear
void clear()
BALL::VIEW::PyWidget::working_dir_
String working_dir_
Definition pyWidget.h:430
BALL::VIEW::PyWidget::getClassAndMember_
bool getClassAndMember_(String toc)
BALL::VIEW::PyWidget::findError_
void findError_(String result)
BALL::VIEW::PyWidget::highlighter_1_
PythonHighlighter highlighter_1_
Definition pyWidget.h:424
BALL::VIEW::PyWidget::loadScript
void loadScript()
BALL::VIEW::PyWidget::multi_line_mode_
bool multi_line_mode_
Definition pyWidget.h:436
BALL::VIEW::PyWidget::showClassDocu
BALL_DEPRECATED void showClassDocu(String, String)
BALL::VIEW::PyWidget::python_settings_
PythonSettings * python_settings_
Definition pyWidget.h:443
BALL::VIEW::PyWidget::initializePreferencesTab
void initializePreferencesTab(Preferences &preferences)
BALL::VIEW::PyWidget::results_
vector< bool > results_
Definition pyWidget.h:440
BALL::VIEW::PyWidget::silent_
bool silent_
Definition pyWidget.h:450
BALL::VIEW::PyWidget::combo_box_
QComboBox * combo_box_
Definition pyWidget.h:427
BALL::VIEW::PyWidget::reactTo
void reactTo(const QKeyEvent &e)
BALL::VIEW::PyWidget::history_position_
Position history_position_
Definition pyWidget.h:441
BALL::VIEW::PythonHighlighter
Definition pyWidget.h:51
BALL::VIEW::PythonHighlighter::comment_format
QTextCharFormat comment_format
Definition pyWidget.h:66
BALL::VIEW::PythonHighlighter::comment_pattern
QRegExp comment_pattern
Definition pyWidget.h:70
BALL::VIEW::PythonHighlighter::BALL_keywords
QStringList BALL_keywords
Definition pyWidget.h:62
BALL::VIEW::PythonHighlighter::python_format
QTextCharFormat python_format
Definition pyWidget.h:64
BALL::VIEW::PythonHighlighter::BALL_patterns
vector< QRegExp > BALL_patterns
Definition pyWidget.h:68
BALL::VIEW::PythonHighlighter::~PythonHighlighter
~PythonHighlighter()
Definition pyWidget.h:56
BALL::VIEW::PythonHighlighter::PythonHighlighter
PythonHighlighter()
BALL::VIEW::PythonHighlighter::my_class_format
QTextCharFormat my_class_format
Definition pyWidget.h:63
BALL::VIEW::PythonHighlighter::string_format
QTextCharFormat string_format
Definition pyWidget.h:65
BALL::VIEW::PythonHighlighter::python_patterns
vector< QRegExp > python_patterns
Definition pyWidget.h:67
BALL::VIEW::PythonHighlighter::python_keywords
QStringList python_keywords
Definition pyWidget.h:61
BALL::VIEW::PythonHighlighter::string_pattern
QRegExp string_pattern
Definition pyWidget.h:69
BALL::VIEW::PythonHighlighter::compilePattern
void compilePattern()
BALL::VIEW::PythonHighlighter::highlightBlock
void highlightBlock(const QString &text)
BALL::VIEW::PythonSettings
Definition pythonSettings.h:38
BALL::VIEW::PythonValidator
Definition pyWidget.h:78
BALL::VIEW::PythonValidator::PythonValidator
PythonValidator(QObject *parent=0)
BALL::VIEW::PythonValidator::validate
virtual State validate(QString &input, int &pos) const
BALL::VIEW::PythonValidator::~PythonValidator
virtual ~PythonValidator()
BALL::VIEW::RunPythonThread
Definition pyWidget.h:88
BALL::VIEW::RunPythonThread::output
String output
Definition pyWidget.h:97
BALL::VIEW::RunPythonThread::state
bool state
Definition pyWidget.h:95
BALL::VIEW::RunPythonThread::RunPythonThread
RunPythonThread()
BALL::VIEW::RunPythonThread::input
String input
Definition pyWidget.h:96
BALL::VIEW::RunPythonThread::run
virtual void run()
BALL::VIEW::TextEditorWidget
Definition textEditorWidget.h:33
QLineEdit
QObject
QSyntaxHighlighter
QThread
QValidator
QWidget
common.h
dockWidget.h
BALL_EMBEDDABLE
#define BALL_EMBEDDABLE(TYPE, BASE)
Definition embeddable.h:31
BALL::VIEW
Definition constraints.h:35
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
string.h
BALL::VIEW::Hotkey
Definition pyWidget.h:102
BALL::VIEW::Hotkey::action
String action
Definition pyWidget.h:128
BALL::VIEW::Hotkey::createHotkey
static Hotkey createHotkey(String modifier, String key, String command, bool &ok, String comment="")
BALL::VIEW::Hotkey::set
bool set(const String &data)
BALL::VIEW::Hotkey::comment
String comment
Definition pyWidget.h:127
BALL::VIEW::Hotkey::button_state
Qt::KeyboardModifiers button_state
Definition pyWidget.h:129
BALL::VIEW::Hotkey::key
Qt::Key key
Definition pyWidget.h:130
BALL::VIEW::Hotkey::get
void get(String &data) const
textEditorWidget.h