From 49820bf9e05880f0391b5e7b94f68f50cd53bf5c Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 22 Feb 2016 14:44:49 +0100 Subject: [PATCH] First step of split. --- src/PyConsole/CMakeLists.txt | 3 + src/PyConsole/PyConsole_Console.cxx | 281 +------------------ src/PyConsole/PyConsole_Console.h | 56 +--- src/PyConsole/PyConsole_ConsoleBase.cxx | 349 ++++++++++++++++++++++++ src/PyConsole/PyConsole_ConsoleBase.h | 107 ++++++++ 5 files changed, 478 insertions(+), 318 deletions(-) create mode 100644 src/PyConsole/PyConsole_ConsoleBase.cxx create mode 100644 src/PyConsole/PyConsole_ConsoleBase.h diff --git a/src/PyConsole/CMakeLists.txt b/src/PyConsole/CMakeLists.txt index 6dc393da5..aebd5fd6f 100755 --- a/src/PyConsole/CMakeLists.txt +++ b/src/PyConsole/CMakeLists.txt @@ -25,6 +25,7 @@ INCLUDE(UseQtExt) INCLUDE_DIRECTORIES( ${QT_INCLUDES} ${PYTHON_INCLUDE_DIRS} + ${PROJECT_SOURCE_DIR}/src/PyConsole ${PROJECT_SOURCE_DIR}/src/Qtx ${PROJECT_SOURCE_DIR}/src/SUIT ${PROJECT_SOURCE_DIR}/src/Event @@ -42,6 +43,7 @@ SET(_link_LIBRARIES ${QT_LIBRARIES} ${PYTHON_LIBRARIES} qtx suit PyInterp Event) # header files / to be processed by moc SET(_moc_HEADERS PyConsole_Console.h + PyConsole_ConsoleBase.h PyConsole_Editor.h PyConsole_EnhEditor.h ) @@ -75,6 +77,7 @@ QT_WRAP_MOC(_moc_SOURCES ${_moc_HEADERS}) # sources / static SET(_other_SOURCES PyConsole_Console.cxx + PyConsole_ConsoleBase.cxx PyConsole_Editor.cxx PyConsole_EnhEditor.cxx PyConsole_EnhInterp.cxx diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx index e684bf1e6..f315800e6 100644 --- a/src/PyConsole/PyConsole_Console.cxx +++ b/src/PyConsole/PyConsole_Console.cxx @@ -50,33 +50,15 @@ \param interp python interpreter */ PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp ) -: QWidget( parent ) + : PyConsole_ConsoleBase( parent, interp ) { - PyConsole_Interp* anInterp = interp ? interp : new PyConsole_Interp(); - - // initialize Python interpretator - anInterp->initialize(); - - // create editor console - QVBoxLayout* lay = new QVBoxLayout( this ); - lay->setMargin( 0 ); - myEditor = new PyConsole_Editor( anInterp, this ); - char* synchronous = getenv("PYTHON_CONSOLE_SYNC"); - if (synchronous && atoi(synchronous)) - { - myEditor->setIsSync(true); - } - myEditor->viewport()->installEventFilter( this ); - lay->addWidget( myEditor ); - - createActions(); } /** * Protected constructor. */ -PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* /*i*/, PyConsole_Editor* e ) - : QWidget (parent), myEditor(e) +PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* i, PyConsole_Editor* e ) + : PyConsole_ConsoleBase(parent,i,e) {} /*! @@ -88,149 +70,6 @@ PyConsole_Console::~PyConsole_Console() { } -PyConsole_Interp* PyConsole_Console::getInterp() const -{ - return myEditor ? myEditor->getInterp() : 0; -} - -/*! - \brief Execute python command in the interpreter. - \param command string with command and arguments -*/ -void PyConsole_Console::exec( const QString& command ) -{ - if ( myEditor ) - myEditor->exec( command ); -} - -/*! - \brief Execute python command in the interpreter - and wait until it is finished. - - Block execution of main application until the python command is executed. - \param command string with command and arguments -*/ -void PyConsole_Console::execAndWait( const QString& command ) -{ - if ( myEditor ) - myEditor->execAndWait( command ); -} - -/*! - \brief Get synchronous mode flag value. - - \sa setIsSync() - \return True if python console works in synchronous mode -*/ -bool PyConsole_Console::isSync() const -{ - return myEditor->isSync(); -} - -/*! - \brief Set synchronous mode flag value. - - In synhronous mode the Python commands are executed in the GUI thread - and the GUI is blocked until the command is finished. In the asynchronous - mode each Python command is executed in the separate thread that does not - block the main GUI loop. - - \param on synhronous mode flag -*/ -void PyConsole_Console::setIsSync( const bool on ) -{ - myEditor->setIsSync( on ); -} - -/*! - \brief Get suppress output flag value. - - \sa setIsSuppressOutput() - \return True if python console output is suppressed. -*/ -bool PyConsole_Console::isSuppressOutput() const -{ - return myEditor->isSuppressOutput(); -} - -/*! - \brief Set suppress output flag value. - - In case if suppress output flag is true, the python - console output suppressed. - - \param on suppress output flag -*/ -void PyConsole_Console::setIsSuppressOutput( const bool on ) -{ - myEditor->setIsSuppressOutput(on); -} - -/*! - \brief Get 'show banner' flag value. - - \sa setIsShowBanner() - \return \c true if python console shows banner -*/ -bool PyConsole_Console::isShowBanner() const -{ - return myEditor->isShowBanner(); -} - -/*! - \brief Set 'show banner' flag value. - - The banner is shown in the top of the python console window. - - \sa isShowBanner() - \param on 'show banner' flag -*/ -void PyConsole_Console::setIsShowBanner( const bool on ) -{ - myEditor->setIsShowBanner( on ); -} - -/*! - \brief Change the python console's font. - \param f new font -*/ -void PyConsole_Console::setFont( const QFont& f ) -{ - if( myEditor ) - myEditor->setFont( f ); -} - -/*! - \brief Get python console font. - \return current python console's font -*/ -QFont PyConsole_Console::font() const -{ - QFont res; - if( myEditor ) - res = myEditor->font(); - return res; -} - -/*! - \brief Event handler. - - Handles context menu request event. - - \param o object - \param e event - \return True if the event is processed and further processing should be stopped -*/ -bool PyConsole_Console::eventFilter( QObject* o, QEvent* e ) -{ - if ( o == myEditor->viewport() && e->type() == QEvent::ContextMenu ) - { - contextMenuRequest( (QContextMenuEvent*)e ); - return true; - } - return QWidget::eventFilter( o, e ); -} - /*! \brief Create the context popup menu. @@ -261,112 +100,22 @@ void PyConsole_Console::contextMenuPopup( QMenu* menu ) } /*! - \brief Set actions to be visible in the context popup menu. - - Actions, which IDs are set in \a flags parameter, will be shown in the - context popup menu. Other actions will not be shown. - - \param flags ORed together actions flags -*/ -void PyConsole_Console::setMenuActions( const int flags ) -{ - myActions[CopyId]->setVisible( flags & CopyId ); - myActions[PasteId]->setVisible( flags & PasteId ); - myActions[ClearId]->setVisible( flags & ClearId ); - myActions[SelectAllId]->setVisible( flags & SelectAllId ); - myActions[DumpCommandsId]->setVisible( flags & DumpCommandsId ); - myActions[StartLogId]->setVisible( flags & StartLogId ); - myActions[StopLogId]->setVisible( flags & StopLogId ); -} - -/*! - \brief Get menu actions which are currently visible in the context popup menu. - \return ORed together actions flags - \sa setMenuActions() -*/ -int PyConsole_Console::menuActions() const -{ - int ret = 0; - ret = ret | ( myActions[CopyId]->isVisible() ? CopyId : 0 ); - ret = ret | ( myActions[PasteId]->isVisible() ? PasteId : 0 ); - ret = ret | ( myActions[ClearId]->isVisible() ? ClearId : 0 ); - ret = ret | ( myActions[SelectAllId]->isVisible() ? SelectAllId : 0 ); - ret = ret | ( myActions[DumpCommandsId]->isVisible() ? DumpCommandsId : 0 ); - ret = ret | ( myActions[StartLogId]->isVisible() ? StartLogId : 0 ); - ret = ret | ( myActions[StopLogId]->isVisible() ? StopLogId : 0 ); - return ret; -} - -/*! - \brief Create menu actions. - - Create context popup menu actions. -*/ -void PyConsole_Console::createActions() -{ - QAction* a = new QAction( tr( "EDIT_COPY_CMD" ), this ); - a->setStatusTip( tr( "EDIT_COPY_CMD" ) ); - connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( copy() ) ); - myActions.insert( CopyId, a ); - - a = new QAction( tr( "EDIT_PASTE_CMD" ), this ); - a->setStatusTip( tr( "EDIT_PASTE_CMD" ) ); - connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( paste() ) ); - myActions.insert( PasteId, a ); - - a = new QAction( tr( "EDIT_CLEAR_CMD" ), this ); - a->setStatusTip( tr( "EDIT_CLEAR_CMD" ) ); - connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( clear() ) ); - myActions.insert( ClearId, a ); - - a = new QAction( tr( "EDIT_SELECTALL_CMD" ), this ); - a->setStatusTip( tr( "EDIT_SELECTALL_CMD" ) ); - connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( selectAll() ) ); - myActions.insert( SelectAllId, a ); - - a = new QAction( tr( "EDIT_DUMPCOMMANDS_CMD" ), this ); - a->setStatusTip( tr( "EDIT_DUMPCOMMANDS_CMD" ) ); - connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( dump() ) ); - myActions.insert( DumpCommandsId, a ); - - a = new QAction( tr( "EDIT_STARTLOG_CMD" ), this ); - a->setStatusTip( tr( "EDIT_STARTLOG_CMD" ) ); - connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( startLog() ) ); - myActions.insert( StartLogId, a ); - - a = new QAction( tr( "EDIT_STOPLOG_CMD" ), this ); - a->setStatusTip( tr( "EDIT_STOPLOG_CMD" ) ); - connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( stopLog() ) ); - myActions.insert( StopLogId, a ); -} - -/*! - \brief Update menu actions. - - Update context popup menu action state. -*/ -void PyConsole_Console::updateActions() -{ - myActions[CopyId]->setEnabled( myEditor->textCursor().hasSelection() ); - myActions[PasteId]->setEnabled( !myEditor->isReadOnly() && !QApplication::clipboard()->text().isEmpty() ); - myActions[SelectAllId]->setEnabled( !myEditor->document()->isEmpty() ); -} + \brief Event handler. -/*! - \brief Start python trace logging - \param fileName the path to the log file -*/ -void PyConsole_Console::startLog( const QString& fileName ) -{ - myEditor->startLog( fileName ); -} + Handles context menu request event. -/*! - \brief Stop python trace logging + \param o object + \param e event + \return True if the event is processed and further processing should be stopped */ -void PyConsole_Console::stopLog() +bool PyConsole_Console::eventFilter( QObject* o, QEvent* e ) { - myEditor->stopLog(); + if ( o == myEditor->viewport() && e->type() == QEvent::ContextMenu ) + { + contextMenuRequest( (QContextMenuEvent*)e ); + return true; + } + return QWidget::eventFilter( o, e ); } /** diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index ce8f36467..64c2e081c 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -27,7 +27,7 @@ #define PYCONSOLE_CONSOLE_H #include "PyConsole.h" - +#include #include #include #include @@ -35,65 +35,18 @@ class PyConsole_Interp; class PyConsole_Editor; -class PYCONSOLE_EXPORT PyConsole_Console : public QWidget, public SUIT_PopupClient +class PYCONSOLE_EXPORT PyConsole_Console : public PyConsole_ConsoleBase, public SUIT_PopupClient { Q_OBJECT - -public: - //! Context popup menu actions flags - enum - { - CopyId = 0x01, //!< "Copy" menu action - PasteId = 0x02, //!< "Paste" menu action - ClearId = 0x04, //!< "Clear" menu action - SelectAllId = 0x08, //!< "Select All" menu action - DumpCommandsId = 0x10, //!< "DumpCommands" menu action - StartLogId = 0x20, //!< "Start log" menu action - StopLogId = 0x40, //!< "Stop log" menu action - All = 0xFF, //!< all menu actions - }; - public: PyConsole_Console( QWidget* parent, PyConsole_Interp* interp = 0 ); virtual ~PyConsole_Console(); - - //! \brief Get python interperter - PyConsole_Interp* getInterp() const; - QFont font() const; - virtual void setFont( const QFont& ); - - bool isSync() const; - void setIsSync( const bool ); - - bool isSuppressOutput() const; - void setIsSuppressOutput( const bool ); - - bool isShowBanner() const; - void setIsShowBanner( const bool ); - - void exec( const QString& ); - void execAndWait( const QString& ); - - virtual bool eventFilter( QObject*, QEvent* ); - //! \brief Get popup client symbolic name virtual QString popupClientType() const { return QString( "PyConsole" ); } virtual void contextMenuPopup( QMenu* ); - - void setMenuActions( const int ); - int menuActions() const; - - void startLog( const QString& ); - void stopLog(); - + virtual bool eventFilter( QObject*, QEvent* ); protected: - void createActions(); - void updateActions(); - PyConsole_Console( QWidget* parent, PyConsole_Interp*, PyConsole_Editor*); - - PyConsole_Editor* myEditor; //!< python console editor widget - QMap myActions; //!< menu actions list }; /** @@ -101,10 +54,9 @@ protected: * Similar to PyConsole_Console except that an enhanced interpreter and enhanced editor * are encapsulated. */ -class PYCONSOLE_EXPORT PyConsole_EnhConsole: public PyConsole_Console +class PYCONSOLE_EXPORT PyConsole_EnhConsole : public PyConsole_Console { Q_OBJECT - public: PyConsole_EnhConsole( QWidget* parent, PyConsole_Interp* interp = 0 ); virtual ~PyConsole_EnhConsole() {} diff --git a/src/PyConsole/PyConsole_ConsoleBase.cxx b/src/PyConsole/PyConsole_ConsoleBase.cxx new file mode 100644 index 000000000..79b717087 --- /dev/null +++ b/src/PyConsole/PyConsole_ConsoleBase.cxx @@ -0,0 +1,349 @@ +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : PyConsole_ConsoleBase.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// +/*! + \class PyConsole_Console + \brief Python console widget. +*/ + +#include "PyConsole_Interp.h" /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!! +#include "PyConsole_ConsoleBase.h" +#include "PyConsole_EnhEditor.h" +#include "PyConsole_EnhInterp.h" + +#include +#include +#include +#include +#include +#include + +/*! + \brief Constructor. + + Creates new python console widget. + \param parent parent widget + \param interp python interpreter +*/ +PyConsole_ConsoleBase::PyConsole_ConsoleBase( QWidget* parent, PyConsole_Interp* interp ) +: QWidget( parent ) +{ + PyConsole_Interp* anInterp = interp ? interp : new PyConsole_Interp(); + + // initialize Python interpretator + anInterp->initialize(); + + // create editor console + QVBoxLayout* lay = new QVBoxLayout( this ); + lay->setMargin( 0 ); + myEditor = new PyConsole_Editor( anInterp, this ); + char* synchronous = getenv("PYTHON_CONSOLE_SYNC"); + if (synchronous && atoi(synchronous)) + { + myEditor->setIsSync(true); + } + myEditor->viewport()->installEventFilter( this ); + lay->addWidget( myEditor ); + + createActions(); +} + +/** + * Protected constructor. + */ +PyConsole_ConsoleBase::PyConsole_ConsoleBase( QWidget* parent, PyConsole_Interp* /*i*/, PyConsole_Editor* e ) + : QWidget (parent), myEditor(e) +{} + +/*! + \brief Destructor. + + Does nothing for the moment. +*/ +PyConsole_ConsoleBase::~PyConsole_ConsoleBase() +{ +} + +PyConsole_Interp* PyConsole_ConsoleBase::getInterp() const +{ + return myEditor ? myEditor->getInterp() : 0; +} + +/*! + \brief Execute python command in the interpreter. + \param command string with command and arguments +*/ +void PyConsole_ConsoleBase::exec( const QString& command ) +{ + if ( myEditor ) + myEditor->exec( command ); +} + +/*! + \brief Execute python command in the interpreter + and wait until it is finished. + + Block execution of main application until the python command is executed. + \param command string with command and arguments +*/ +void PyConsole_ConsoleBase::execAndWait( const QString& command ) +{ + if ( myEditor ) + myEditor->execAndWait( command ); +} + +/*! + \brief Get synchronous mode flag value. + + \sa setIsSync() + \return True if python console works in synchronous mode +*/ +bool PyConsole_ConsoleBase::isSync() const +{ + return myEditor->isSync(); +} + +/*! + \brief Set synchronous mode flag value. + + In synhronous mode the Python commands are executed in the GUI thread + and the GUI is blocked until the command is finished. In the asynchronous + mode each Python command is executed in the separate thread that does not + block the main GUI loop. + + \param on synhronous mode flag +*/ +void PyConsole_ConsoleBase::setIsSync( const bool on ) +{ + myEditor->setIsSync( on ); +} + +/*! + \brief Get suppress output flag value. + + \sa setIsSuppressOutput() + \return True if python console output is suppressed. +*/ +bool PyConsole_ConsoleBase::isSuppressOutput() const +{ + return myEditor->isSuppressOutput(); +} + +/*! + \brief Set suppress output flag value. + + In case if suppress output flag is true, the python + console output suppressed. + + \param on suppress output flag +*/ +void PyConsole_ConsoleBase::setIsSuppressOutput( const bool on ) +{ + myEditor->setIsSuppressOutput(on); +} + +/*! + \brief Get 'show banner' flag value. + + \sa setIsShowBanner() + \return \c true if python console shows banner +*/ +bool PyConsole_ConsoleBase::isShowBanner() const +{ + return myEditor->isShowBanner(); +} + +/*! + \brief Set 'show banner' flag value. + + The banner is shown in the top of the python console window. + + \sa isShowBanner() + \param on 'show banner' flag +*/ +void PyConsole_ConsoleBase::setIsShowBanner( const bool on ) +{ + myEditor->setIsShowBanner( on ); +} + +/*! + \brief Change the python console's font. + \param f new font +*/ +void PyConsole_ConsoleBase::setFont( const QFont& f ) +{ + if( myEditor ) + myEditor->setFont( f ); +} + +/*! + \brief Get python console font. + \return current python console's font +*/ +QFont PyConsole_ConsoleBase::font() const +{ + QFont res; + if( myEditor ) + res = myEditor->font(); + return res; +} + +/*! + \brief Set actions to be visible in the context popup menu. + + Actions, which IDs are set in \a flags parameter, will be shown in the + context popup menu. Other actions will not be shown. + + \param flags ORed together actions flags +*/ +void PyConsole_ConsoleBase::setMenuActions( const int flags ) +{ + myActions[CopyId]->setVisible( flags & CopyId ); + myActions[PasteId]->setVisible( flags & PasteId ); + myActions[ClearId]->setVisible( flags & ClearId ); + myActions[SelectAllId]->setVisible( flags & SelectAllId ); + myActions[DumpCommandsId]->setVisible( flags & DumpCommandsId ); + myActions[StartLogId]->setVisible( flags & StartLogId ); + myActions[StopLogId]->setVisible( flags & StopLogId ); +} + +/*! + \brief Get menu actions which are currently visible in the context popup menu. + \return ORed together actions flags + \sa setMenuActions() +*/ +int PyConsole_ConsoleBase::menuActions() const +{ + int ret = 0; + ret = ret | ( myActions[CopyId]->isVisible() ? CopyId : 0 ); + ret = ret | ( myActions[PasteId]->isVisible() ? PasteId : 0 ); + ret = ret | ( myActions[ClearId]->isVisible() ? ClearId : 0 ); + ret = ret | ( myActions[SelectAllId]->isVisible() ? SelectAllId : 0 ); + ret = ret | ( myActions[DumpCommandsId]->isVisible() ? DumpCommandsId : 0 ); + ret = ret | ( myActions[StartLogId]->isVisible() ? StartLogId : 0 ); + ret = ret | ( myActions[StopLogId]->isVisible() ? StopLogId : 0 ); + return ret; +} + +/*! + \brief Create menu actions. + + Create context popup menu actions. +*/ +void PyConsole_ConsoleBase::createActions() +{ + QAction* a = new QAction( tr( "EDIT_COPY_CMD" ), this ); + a->setStatusTip( tr( "EDIT_COPY_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( copy() ) ); + myActions.insert( CopyId, a ); + + a = new QAction( tr( "EDIT_PASTE_CMD" ), this ); + a->setStatusTip( tr( "EDIT_PASTE_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( paste() ) ); + myActions.insert( PasteId, a ); + + a = new QAction( tr( "EDIT_CLEAR_CMD" ), this ); + a->setStatusTip( tr( "EDIT_CLEAR_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( clear() ) ); + myActions.insert( ClearId, a ); + + a = new QAction( tr( "EDIT_SELECTALL_CMD" ), this ); + a->setStatusTip( tr( "EDIT_SELECTALL_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( selectAll() ) ); + myActions.insert( SelectAllId, a ); + + a = new QAction( tr( "EDIT_DUMPCOMMANDS_CMD" ), this ); + a->setStatusTip( tr( "EDIT_DUMPCOMMANDS_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( dump() ) ); + myActions.insert( DumpCommandsId, a ); + + a = new QAction( tr( "EDIT_STARTLOG_CMD" ), this ); + a->setStatusTip( tr( "EDIT_STARTLOG_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( startLog() ) ); + myActions.insert( StartLogId, a ); + + a = new QAction( tr( "EDIT_STOPLOG_CMD" ), this ); + a->setStatusTip( tr( "EDIT_STOPLOG_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( stopLog() ) ); + myActions.insert( StopLogId, a ); +} + +/*! + \brief Update menu actions. + + Update context popup menu action state. +*/ +void PyConsole_ConsoleBase::updateActions() +{ + myActions[CopyId]->setEnabled( myEditor->textCursor().hasSelection() ); + myActions[PasteId]->setEnabled( !myEditor->isReadOnly() && !QApplication::clipboard()->text().isEmpty() ); + myActions[SelectAllId]->setEnabled( !myEditor->document()->isEmpty() ); +} + +/*! + \brief Start python trace logging + \param fileName the path to the log file +*/ +void PyConsole_ConsoleBase::startLog( const QString& fileName ) +{ + myEditor->startLog( fileName ); +} + +/*! + \brief Stop python trace logging +*/ +void PyConsole_ConsoleBase::stopLog() +{ + myEditor->stopLog(); +} + +/** + * Similar to constructor of the base class but using enhanced objects. + * TODO: this should really be done in a factory to avoid code duplication. + * @param parent + * @param interp + */ +PyConsole_EnhConsoleBase::PyConsole_EnhConsoleBase( QWidget* parent, PyConsole_Interp* interp ) + : PyConsole_ConsoleBase( parent, interp, 0 ) +{ + PyConsole_Interp* anInterp = interp ? interp : new PyConsole_EnhInterp(); + + // initialize Python interpretator + anInterp->initialize(); + + // create editor console + QVBoxLayout* lay = new QVBoxLayout( this ); + lay->setMargin( 0 ); + myEditor = new PyConsole_EnhEditor( anInterp, this ); + char* synchronous = getenv("PYTHON_CONSOLE_SYNC"); + if (synchronous && atoi(synchronous)) + { + myEditor->setIsSync(true); + } + myEditor->viewport()->installEventFilter( this ); + lay->addWidget( myEditor ); + + createActions(); +} diff --git a/src/PyConsole/PyConsole_ConsoleBase.h b/src/PyConsole/PyConsole_ConsoleBase.h new file mode 100644 index 000000000..2add981b7 --- /dev/null +++ b/src/PyConsole/PyConsole_ConsoleBase.h @@ -0,0 +1,107 @@ +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : PyConsole_Console.h +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// +#ifndef PYCONSOLE_CONSOLEBASE_H +#define PYCONSOLE_CONSOLEBASE_H + +#include "PyConsole.h" + +#include +#include +#include + +class PyConsole_Interp; +class PyConsole_Editor; + +class PYCONSOLE_EXPORT PyConsole_ConsoleBase : public QWidget +{ + Q_OBJECT + +public: + //! Context popup menu actions flags + enum + { + CopyId = 0x01, //!< "Copy" menu action + PasteId = 0x02, //!< "Paste" menu action + ClearId = 0x04, //!< "Clear" menu action + SelectAllId = 0x08, //!< "Select All" menu action + DumpCommandsId = 0x10, //!< "DumpCommands" menu action + StartLogId = 0x20, //!< "Start log" menu action + StopLogId = 0x40, //!< "Stop log" menu action + All = 0xFF, //!< all menu actions + }; + +public: + PyConsole_ConsoleBase( QWidget* parent, PyConsole_Interp* interp = 0 ); + virtual ~PyConsole_ConsoleBase(); + + //! \brief Get python interperter + PyConsole_Interp* getInterp() const; + QFont font() const; + virtual void setFont( const QFont& ); + + bool isSync() const; + void setIsSync( const bool ); + + bool isSuppressOutput() const; + void setIsSuppressOutput( const bool ); + + bool isShowBanner() const; + void setIsShowBanner( const bool ); + + void exec( const QString& ); + void execAndWait( const QString& ); + + void setMenuActions( const int ); + int menuActions() const; + + void startLog( const QString& ); + void stopLog(); + +protected: + void createActions(); + void updateActions(); + + PyConsole_ConsoleBase( QWidget* parent, PyConsole_Interp*, PyConsole_Editor*); + + PyConsole_Editor* myEditor; //!< python console editor widget + QMap myActions; //!< menu actions list +}; + +/** + * Enhance console object providing auto-completion. + * Similar to PyConsole_Console except that an enhanced interpreter and enhanced editor + * are encapsulated. + */ +class PYCONSOLE_EXPORT PyConsole_EnhConsoleBase : public PyConsole_ConsoleBase +{ + Q_OBJECT + +public: + PyConsole_EnhConsoleBase( QWidget* parent, PyConsole_Interp* interp = 0 ); + virtual ~PyConsole_EnhConsoleBase() {} +}; + +#endif // PYCONSOLE_CONSOLE_H -- 2.39.2