00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OST_GUI_PYTHON_SHELL_WIDGET_HH
00025 #define OST_GUI_PYTHON_SHELL_WIDGET_HH
00026
00027
00028 #include <ost/gui/module_config.hh>
00029 #include <QPlainTextEdit>
00030 #include <QHash>
00031 #include "python_interpreter.hh"
00032 #include "shell_history.hh"
00033 #include "python_shell_fw.hh"
00034 #include "python_syntax_highlighter.hh"
00035 #include "state_machine.hh"
00036 #include "state.hh"
00037
00038 namespace ost { namespace gui {
00039
00040
00041 class Gutter;
00042 class PythonCompleter;
00043 class PathCompleter;
00044
00045
00046 class DLLEXPORT_OST_GUI PythonShellWidget : public QPlainTextEdit {
00047
00048 typedef QHash<unsigned int,QTextBlock> OutputBlockList;
00049 Q_OBJECT
00050
00051 public:
00052 PythonShellWidget(QWidget* parent=NULL);
00053 GutterBlockList GetGutterBlocks(const QRect& rect);
00054 void SetTabWidth(int width);
00055 int GetTabWidth() const;
00056 QString GetCommand();
00057 QTextBlock GetEditStartBlock();
00058
00059 int tab_width_;
00060
00061 signals:
00062 void Execute(const QString& command);
00063 void RequestCompletion(const QRect& rect,bool inline_completion);
00064 void SetCompletionPrefix(const QString& prefix);
00065 void RequestPathCompletion(const QRect& rect,bool inline_completion);
00066 void SetPathCompletionPrefix(const QString& prefix);
00067
00068 public slots:
00069 void InsertCompletion(const QString& completion);
00070 void InsertPathCompletion(const QString& completion);
00071 void AppendOutput(unsigned int id,const QString& output);
00072 void AppendError(unsigned int id,const QString& output);
00073 void OutputFinished(unsigned int id, bool error);
00074 void Complete(bool inline_completion=true);
00075 void Recomplete(const QString& completion);
00076
00077 void OnSingleLineStateEntered();
00078 void OnMultiLineActiveStateEntered();
00079 void OnMultiLineInactiveStateEntered();
00080 void OnHistoryUpStateEntered();
00081 void OnHistoryDownStateEntered();
00082 void OnExecuteStateEntered();
00083 void OnEnterTransition();
00084 void OnKeypadEnterTransition();
00085 void OnReadonlyEntered();
00086 void OnReadwriteEntered();
00087 void OnMixedToReadwrite();
00088
00089 protected:
00090 virtual void mouseReleaseEvent (QMouseEvent* event );
00091 virtual void keyPressEvent (QKeyEvent* event );
00092 virtual void resizeEvent(QResizeEvent* event);
00093 virtual void showEvent(QShowEvent* event);
00094 virtual void insertFromMimeData( const QMimeData * source );
00095 void set_output_visible_(bool flag=true);
00096 void setup_readonly_state_machine_();
00097 void setup_state_machine_();
00098 void wrap_into_function_(const QString& command);
00099 void set_command_(const QString& command);
00100 void set_block_edit_mode_(BlockEditMode flag);
00101 bool handle_completion_(QKeyEvent* event);
00102 bool handle_custom_commands_(QKeyEvent* event);
00103 BlockEditMode get_block_edit_mode_();
00104 void set_block_type_(const QTextBlock& start,const QTextBlock& end, BlockType type);
00105
00106 PythonSyntaxHighlighter highlighter_;
00107 PythonCompleter* completer_;
00108 PathCompleter* path_completer_;
00109 BlockEditMode block_edit_mode_;
00110 ShellHistory history_;
00111 Gutter* gutter_;
00112 bool output_visible_;
00113 int completion_start_;
00114 int completion_end_;
00115 QTextBlock block_edit_start_;
00116 OutputBlockList output_blocks_;
00117 StateMachine* machine_;
00118 StateMachine* readonly_machine_;
00119 State* readwrite_state_;
00120 State* multiline_active_state_;
00121 };
00122
00123 }}
00124
00125 #endif