Salome HOME
Split PyConsole in order to be used easily outside GUI of SALOME.
[modules/gui.git] / src / PyConsole / PyConsole_Console.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : PyConsole_Console.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 /*!
27   \class PyConsole_Console
28   \brief Python console widget.
29 */  
30
31 #include "PyConsole_Interp.h"   /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!!
32 #include "PyConsole_Console.h"
33 #include "PyConsole_Editor.h"
34 #include "PyConsole_EnhEditor.h"
35 #include "PyConsole_EnhInterp.h"
36
37 #include <Qtx.h>
38
39 #include <QAction>
40 #include <QApplication>
41 #include <QClipboard>
42 #include <QEvent>
43 #include <QMenu>
44 #include <QVBoxLayout>
45
46 PyConsole_EditorBase *PyConsole_Console::PyConsole_Interp_Creator::createEditor( PyConsole_Interp *interp, PyConsole_ConsoleBase *console ) const
47 { return new PyConsole_Editor(interp,console); }
48
49 PyConsole_Interp *PyConsole_Console::PyConsole_Interp_Creator::createInterp( ) const
50 { return new PyConsole_Interp; }
51
52 /*!
53   \brief Constructor.
54
55   Creates new python console widget.
56   \param parent parent widget
57   \param interp python interpreter
58 */
59 PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp )
60   : PyConsole_ConsoleBase( parent, interp, 0 )
61 {
62   PyConsole_Interp_Creator crea;
63   defaultConstructor(interp,crea);
64 }
65
66 /**
67  * Protected constructor.
68  */
69 PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* i,  PyConsole_Editor* e )
70   : PyConsole_ConsoleBase(parent,i,e)
71 {  
72 }
73
74 /*!
75   \brief Destructor.
76
77   Does nothing for the moment.
78 */
79 PyConsole_Console::~PyConsole_Console()
80 {
81 }
82
83 /*!
84   \brief Create the context popup menu.
85
86   Fill in the popup menu with the commands.
87
88   \param menu context popup menu
89 */
90 void PyConsole_Console::contextMenuPopup( QMenu *menu )
91 {
92   PyConsole_ConsoleBase::contextMenuPopup(menu);
93 }
94
95 /*!
96   \brief Event handler.
97
98   Handles context menu request event.
99
100   \param o object
101   \param e event
102   \return True if the event is processed and further processing should be stopped
103 */
104 bool PyConsole_Console::eventFilter( QObject* o, QEvent* e )
105 {
106   if ( o == myEditor->viewport() && e->type() == QEvent::ContextMenu )
107   {
108     contextMenuRequest( (QContextMenuEvent*)e );
109     return true;
110   }
111   return QWidget::eventFilter( o, e );
112 }
113
114 PyConsole_EditorBase *PyConsole_EnhConsole::PyConsole_Interp_EnhCreator::createEditor( PyConsole_Interp *interp, PyConsole_ConsoleBase *console ) const
115 { return new PyConsole_EnhEditor(interp,console); }
116
117 PyConsole_Interp *PyConsole_EnhConsole::PyConsole_Interp_EnhCreator::createInterp( ) const
118 { return new PyConsole_EnhInterp; }
119
120 /**
121  * Similar to constructor of the base class but using enhanced objects.
122  * TODO: this should really be done in a factory to avoid code duplication.
123  * @param parent
124  * @param interp
125  */
126 PyConsole_EnhConsole::PyConsole_EnhConsole( QWidget* parent, PyConsole_Interp* interp )
127   : PyConsole_Console( parent, interp, 0 )
128 {
129   PyConsole_Interp_EnhCreator crea;
130   defaultConstructor(interp,crea);
131 }