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 <ost/gui/module_config.hh>
29 #include "python_interpreter.hh"
30 #include "shell_history.hh"
31 #include "python_shell_fw.hh"
33 #include "state_machine.hh"
34 #include "state.hh"
35 
36 #include <QPlainTextEdit>
37 #include <QHash>
38 namespace ost { namespace gui {
39 
40 // fw decl
41 class Gutter;
42 class PythonCompleter;
43 class PathCompleter;
44 
45 
46 class DLLEXPORT_OST_GUI PythonShellWidget : public QPlainTextEdit {
47 
48  typedef QHash<unsigned int,QTextBlock> OutputBlockList;
49  Q_OBJECT
50 
51 public:
52  PythonShellWidget(QWidget* parent=NULL);
53  GutterBlockList GetGutterBlocks(const QRect& rect);
54  void SetTabWidth(int width);
55  int GetTabWidth() const;
56  QString GetCommand();
57  QTextBlock GetEditStartBlock();
58 
60 
61 signals:
62  void Execute(const QString& command);
63  void RequestCompletion(const QRect& rect,bool inline_completion);
64  void SetCompletionPrefix(const QString& prefix);
65  void RequestPathCompletion(const QRect& rect,bool inline_completion);
66  void SetPathCompletionPrefix(const QString& prefix);
67 
68 public slots:
69  void InsertCompletion(const QString& completion);
70  void InsertPathCompletion(const QString& completion);
71  void AppendOutput(unsigned int id,const QString& output);
72  void AppendError(unsigned int id,const QString& output);
73  void OutputFinished(unsigned int id, bool error);
74  void Complete(bool inline_completion=true);
75  void Recomplete(const QString& completion);
76  // slots for state machine
77  void OnSingleLineStateEntered();
78  void OnMultiLineActiveStateEntered();
79  void OnMultiLineInactiveStateEntered();
80  void OnHistoryUpStateEntered();
81  void OnHistoryDownStateEntered();
82  void OnExecuteStateEntered();
83  void NewLineAtEnd();
84  void NewLineAtCursor();
85  void OnReadonlyEntered();
86  void OnReadwriteEntered();
87  void OnMixedToReadwrite();
88 protected slots:
89  void handle_completion_();
90  void handle_output_toggle_();
91  void handle_wrap_to_function_();
92  void handle_select_all_();
93  void handle_select_all_rw_();
94  void handle_delete_();
95  void handle_backspace_();
96  void handle_clear_all_();
97 
98 protected:
99  virtual void resizeEvent(QResizeEvent* event);
100  virtual void showEvent(QShowEvent* event);
101  virtual void insertFromMimeData( const QMimeData * source );
102  void set_output_visible_(bool flag=true);
103  void setup_readonly_state_machine_();
104  void setup_state_machine_();
105  void wrap_into_function_(const QString& command);
106  void set_command_(const QString& command);
107  void set_block_edit_mode_(BlockEditMode flag);
108  BlockEditMode get_block_edit_mode_();
109  void set_block_type_(const QTextBlock& start,const QTextBlock& end, BlockType type);
110 
120  QTextBlock block_edit_start_;
121  OutputBlockList output_blocks_;
126 };
127 
128 }}//ns
129 
130 #endif