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 "python_interpreter.hh"
00029 #include "shell_history.hh"
00030 #include "python_shell_fw.hh"
00031 #include "python_syntax_highlighter.hh"
00032 #include <ost/gui/module_config.hh>
00033
00034 #include <QPlainTextEdit>
00035 #include <QHash>
00036 namespace ost { namespace gui {
00037
00038
00039 class Gutter;
00040 class PythonCompleter;
00041 class PathCompleter;
00042 class State;
00043 class StateMachine;
00044
00045 typedef std::vector<GutterBlock> GutterBlockList;
00046
00047 class DLLEXPORT_OST_GUI PythonShellWidget : public QPlainTextEdit {
00048
00049 typedef QHash<unsigned int,QTextBlock> OutputBlockList;
00050 Q_OBJECT
00051
00052 public:
00053 PythonShellWidget(QWidget* parent=NULL);
00054 GutterBlockList GetGutterBlocks(const QRect& rect);
00055 void SetTabWidth(int width);
00056 int GetTabWidth() const;
00057 QString GetCommand();
00058 QTextBlock GetEditStartBlock();
00059
00060 int tab_width_;
00061
00062 signals:
00063 void Execute(const QString& command);
00064 void RequestCompletion(const QRect& rect,bool inline_completion);
00065 void SetCompletionPrefix(const QString& prefix);
00066 void RequestPathCompletion(const QRect& rect,bool inline_completion);
00067 void SetPathCompletionPrefix(const QString& prefix);
00068
00069 public slots:
00070 void InsertCompletion(const QString& completion);
00071 void InsertPathCompletion(const QString& completion);
00072 void AppendOutput(unsigned int id,const QString& output);
00073 void AppendError(unsigned int id,const QString& output);
00074 void OutputFinished(unsigned int id, bool error);
00075 void Complete(bool inline_completion=true);
00076 void Recomplete(const QString& completion);
00077
00078 void OnSingleLineStateEntered();
00079 void OnMultiLineActiveStateEntered();
00080 void OnMultiLineInactiveStateEntered();
00081 void OnHistoryUpStateEntered();
00082 void OnHistoryDownStateEntered();
00083 void OnExecuteStateEntered();
00084 void NewLineAtEnd();
00085 void NewLineAtCursor();
00086 void OnReadonlyEntered();
00087 void OnReadwriteEntered();
00088 void OnMixedToReadwrite();
00089 protected slots:
00090 void handle_completion_();
00091 void handle_output_toggle_();
00092 void handle_wrap_to_function_();
00093 void handle_select_all_();
00094 void handle_select_all_rw_();
00095 void handle_delete_();
00096 void handle_backspace_();
00097 void handle_clear_all_();
00098
00099 protected:
00100 virtual void resizeEvent(QResizeEvent* event);
00101 virtual void showEvent(QShowEvent* event);
00102 virtual void insertFromMimeData( const QMimeData * source );
00103 void set_output_visible_(bool flag=true);
00104 void setup_readonly_state_machine_();
00105 void setup_state_machine_();
00106 void wrap_into_function_(const QString& command);
00107 void set_command_(const QString& command);
00108 void set_block_edit_mode_(BlockEditMode flag);
00109 BlockEditMode get_block_edit_mode_();
00110 void set_block_type_(const QTextBlock& start,const QTextBlock& end, BlockType type);
00111
00112 PythonSyntaxHighlighter highlighter_;
00113 PythonCompleter* completer_;
00114 PathCompleter* path_completer_;
00115 BlockEditMode block_edit_mode_;
00116 ShellHistory history_;
00117 Gutter* gutter_;
00118 bool output_visible_;
00119 int completion_start_;
00120 int completion_end_;
00121 QTextBlock block_edit_start_;
00122 OutputBlockList output_blocks_;
00123 StateMachine* machine_;
00124 StateMachine* readonly_machine_;
00125 State* readwrite_state_;
00126 State* multiline_active_state_;
00127 };
00128
00129 }}
00130
00131 #endif