OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
python_shell_widget.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 /*
20  Authors: Marco Biasini, Andreas Schenk
21  */
22 
23 
24 #ifndef OST_GUI_PYTHON_SHELL_WIDGET_HH
25 #define OST_GUI_PYTHON_SHELL_WIDGET_HH
26 
27 
28 #include "python_interpreter.hh"
29 #include "shell_history.hh"
30 #include "python_shell_fw.hh"
32 #include <ost/gui/module_config.hh>
33 
34 #include <QPlainTextEdit>
35 #include <QHash>
36 namespace ost { namespace gui {
37 
38 // fw decl
39 class Gutter;
40 class PythonCompleter;
41 class PathCompleter;
42 class State;
44 
45 typedef std::vector<GutterBlock> GutterBlockList;
46 
47 class DLLEXPORT_OST_GUI PythonShellWidget : public QPlainTextEdit {
48 
49  typedef QHash<unsigned int,QTextBlock> OutputBlockList;
50  Q_OBJECT
51 
52 public:
53  PythonShellWidget(QWidget* parent=NULL);
54  GutterBlockList GetGutterBlocks(const QRect& rect);
55  void SetTabWidth(int width);
56  int GetTabWidth() const;
57  QString GetCommand();
58  QTextBlock GetEditStartBlock();
59 
61 
62 signals:
63  void Execute(const QString& command);
64  void RequestCompletion(const QRect& rect,bool inline_completion);
65  void SetCompletionPrefix(const QString& prefix);
66  void RequestPathCompletion(const QRect& rect,bool inline_completion);
67  void SetPathCompletionPrefix(const QString& prefix);
68 
69 public slots:
70  void InsertCompletion(const QString& completion);
71  void InsertPathCompletion(const QString& completion);
72  void AppendOutput(unsigned int id,const QString& output);
73  void AppendError(unsigned int id,const QString& output);
74  void OutputFinished(unsigned int id, bool error);
75  void Complete(bool inline_completion=true);
76  void Recomplete(const QString& completion);
77  // slots for state machine
78  void OnSingleLineStateEntered();
79  void OnMultiLineActiveStateEntered();
80  void OnMultiLineInactiveStateEntered();
81  void OnHistoryUpStateEntered();
82  void OnHistoryDownStateEntered();
83  void OnExecuteStateEntered();
84  void NewLineAtEnd();
85  void NewLineAtCursor();
86  void OnReadonlyEntered();
87  void OnReadwriteEntered();
88  void OnMixedToReadwrite();
89 protected slots:
90  void handle_completion_();
91  void handle_output_toggle_();
92  void handle_wrap_to_function_();
93  void handle_select_all_();
94  void handle_select_all_rw_();
95  void handle_delete_();
96  void handle_backspace_();
97  void handle_clear_all_();
98 
99 protected:
100  virtual void resizeEvent(QResizeEvent* event);
101  virtual void showEvent(QShowEvent* event);
102  virtual void insertFromMimeData( const QMimeData * source );
103  void set_output_visible_(bool flag=true);
104  void setup_readonly_state_machine_();
105  void setup_state_machine_();
106  void wrap_into_function_(const QString& command);
107  void set_command_(const QString& command);
108  void set_block_edit_mode_(BlockEditMode flag);
109  BlockEditMode get_block_edit_mode_();
110  void set_block_type_(const QTextBlock& start,const QTextBlock& end, BlockType type);
111 
121  QTextBlock block_edit_start_;
122  OutputBlockList output_blocks_;
127 };
128 
129 }}//ns
130 
131 #endif
pointer_it< T > end(const std::vector< T > &values)
std::vector< GutterBlock > GutterBlockList
#define DLLEXPORT_OST_GUI
PythonSyntaxHighlighter highlighter_