OpenStructure
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-2020 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;
43 class StateMachine;
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
84  void NewLineAtEnd();
89 protected slots:
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);
106  void wrap_into_function_(const QString& command);
107  void set_command_(const QString& command);
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
virtual void insertFromMimeData(const QMimeData *source)
BlockEditMode get_block_edit_mode_()
void set_output_visible_(bool flag=true)
void set_block_edit_mode_(BlockEditMode flag)
GutterBlockList GetGutterBlocks(const QRect &rect)
void Recomplete(const QString &completion)
void InsertCompletion(const QString &completion)
void set_command_(const QString &command)
void wrap_into_function_(const QString &command)
void SetCompletionPrefix(const QString &prefix)
void OutputFinished(unsigned int id, bool error)
void SetPathCompletionPrefix(const QString &prefix)
void SetTabWidth(int width)
void Execute(const QString &command)
void RequestPathCompletion(const QRect &rect, bool inline_completion)
void Complete(bool inline_completion=true)
void AppendError(unsigned int id, const QString &output)
PythonShellWidget(QWidget *parent=NULL)
virtual void resizeEvent(QResizeEvent *event)
void RequestCompletion(const QRect &rect, bool inline_completion)
void AppendOutput(unsigned int id, const QString &output)
virtual void showEvent(QShowEvent *event)
void InsertPathCompletion(const QString &completion)
PythonSyntaxHighlighter highlighter_
void set_block_type_(const QTextBlock &start, const QTextBlock &end, BlockType type)
#define DLLEXPORT_OST_GUI
std::vector< GutterBlock > GutterBlockList
pointer_it< T > end(const std::vector< T > &values)
Definition: base.dox:1