From d794aa9a78046e12d381ef34a82d7695aa08b851 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 9 Mar 2011 15:45:48 +0000 Subject: [PATCH] 0021137: EDF 1612 ALL: Shortcut for the Python console, Object Browser and Message Log --- src/LightApp/LightApp_Application.cxx | 43 ++++++++++++------ src/LightApp/resources/LightApp.xml | 1 + src/LightApp/resources/LightApp_msg_en.ts | 4 ++ src/PyConsole/PyConsole_Console.cxx | 24 ++++++++++ src/PyConsole/PyConsole_Console.h | 2 + src/PyConsole/PyConsole_Editor.cxx | 54 ++++++++++++++++++++--- src/PyConsole/PyConsole_Editor.h | 6 +++ src/Qtx/QtxDockAction.cxx | 8 ++++ src/Qtx/QtxDockAction.h | 2 + src/SalomeApp/SalomeApp_Application.cxx | 5 ++- src/SalomeApp/resources/SalomeApp.xml | 1 + 11 files changed, 129 insertions(+), 21 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index b044b0958..56f2f9a51 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -328,15 +328,15 @@ LightApp_Application::LightApp_Application() QStringList anAddFamilies = aResMgr->stringValue( "PyConsole", "additional_families" ).split( ";", QString::SkipEmptyParts ); QString aFamily; for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it ) + { + aFamily = *it; + if ( famdb.contains(aFamily) ) { - aFamily = *it; - if ( famdb.contains(aFamily) ) - { - f.setFamily( aFamily ); - aResMgr->setValue( "PyConsole", "font", f ); - break; - } + f.setFamily( aFamily ); + aResMgr->setValue( "PyConsole", "font", f ); + break; } + } } /*!Destructor. @@ -1151,6 +1151,11 @@ void LightApp_Application::insertDockWindow( const int id, QWidget* wid ) dock->setFeatures( QDockWidget::AllDockWidgetFeatures ); dock->setObjectName( QString( "window_%1" ).arg( id ) ); dock->setWidget( wid ); + + QKeySequence accel = wid->property( "shortcut" ).value(); + if ( !accel.isEmpty() ) + dock->toggleViewAction()->setShortcut( accel ); + dock->show(); } @@ -1175,8 +1180,11 @@ void LightApp_Application::removeDockWindow( const int id ) void LightApp_Application::placeDockWindow( const int id, Qt::DockWidgetArea place ) { QDockWidget* dock = windowDock( dockWindow( id ) ); - if ( dock && desktop() ) + if ( dock && desktop() ) { desktop()->addDockWidget( place, dock ); + QtxDockAction* a = qobject_cast( action( ViewWindowsId ) ); + if ( a ) a->update(); + } } /*! @@ -1737,9 +1745,8 @@ QWidget* LightApp_Application::createWindow( const int flag ) ob->treeView()->header()->setResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed); ob->treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId); ob->treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH); - + ob->setProperty( "shortcut", QKeySequence( "Alt+Shift+O" ) ); wid = ob; - ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } #ifndef DISABLE_PYCONSOLE @@ -1748,6 +1755,9 @@ QWidget* LightApp_Application::createWindow( const int flag ) PyConsole_Console* pyCons = new PyConsole_Console( desktop(),new LightApp_PyInterp()); pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) ); pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" )); + pyCons->setIsShowBanner(resourceMgr()->booleanValue( "PyConsole", "show_banner", true )); + pyCons->setProperty( "shortcut", QKeySequence( "Alt+Shift+P" ) ); + wid = pyCons; pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } @@ -1756,6 +1766,7 @@ QWidget* LightApp_Application::createWindow( const int flag ) { LogWindow* logWin = new LogWindow( desktop() ); logWin->setWindowTitle( tr( "LOG_WINDOW" ) ); + logWin->setProperty( "shortcut", QKeySequence( "Alt+Shift+L" ) ); wid = logWin; logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } @@ -1947,6 +1958,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab ); pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" ); + pref->addPreference( tr( "PREF_SHOW_BANNER" ), pythonConsoleGroup, LightApp_Preferences::Bool, "PyConsole", "show_banner" ); int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat ); @@ -2549,11 +2561,14 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString } #ifndef DISABLE_PYCONSOLE - if( sec=="PyConsole" ) + if( sec=="PyConsole" && pythonConsole() ) { - if( param=="font" ) - if( pythonConsole() ) - pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) ); + if ( param=="font" ) { + pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) ); + } + else if ( param=="show_banner" ) { + pythonConsole()->setIsShowBanner( resMgr->booleanValue( "PyConsole", "show_banner", true ) ); + } } #endif diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index dd1a20855..de746b8c2 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -81,6 +81,7 @@
+
diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 89910ee12..804b47529 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -346,6 +346,10 @@ The changes will be applied on the next application session. PREF_GROUP_PY_CONSOLE Python console properties + + PREF_SHOW_BANNER + Show banner + PREF_GROUP_STYLE Salome style diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx index 4abd2af8e..7c99936c8 100644 --- a/src/PyConsole/PyConsole_Console.cxx +++ b/src/PyConsole/PyConsole_Console.cxx @@ -152,6 +152,30 @@ 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 diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index 8833039fb..edca2edb2 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -66,6 +66,8 @@ public: bool isSuppressOutput() const; void setIsSuppressOutput( const bool ); + bool isShowBanner() const; + void setIsShowBanner( const bool ); void exec( const QString& ); void execAndWait( const QString& ); diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx index c1bce6b3e..d3430ae6c 100644 --- a/src/PyConsole/PyConsole_Editor.cxx +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -226,8 +226,8 @@ private: void staticCallback( void* data, char* c ) { - if(!((PyConsole_Editor*)data)->isSuppressOutput()) - QApplication::postEvent( (PyConsole_Editor*)data, new PrintEvent( c ) ); + if(!((PyConsole_Editor*)data)->isSuppressOutput()) + QApplication::postEvent( (PyConsole_Editor*)data, new PrintEvent( c ) ); } /*! @@ -243,8 +243,9 @@ PyConsole_Editor::PyConsole_Editor( PyConsole_Interp* theInterp, myInterp( 0 ), myCmdInHistory( -1 ), myEventLoop( 0 ), + myShowBanner( true ), myIsSync( false ), - myIsSuppressOutput(false) + myIsSuppressOutput( false ) { QString fntSet( "" ); QFont aFont = SUIT_Tools::stringToFont( fntSet ); @@ -302,7 +303,7 @@ void PyConsole_Editor::setIsSync( const bool on ) \brief Get suppress output flag value. \sa setIsSuppressOutput() - \return True if python console output is suppressed. + \return \c true if python console output is suppressed. */ bool PyConsole_Editor::isSuppressOutput() const { @@ -322,6 +323,45 @@ void PyConsole_Editor::setIsSuppressOutput( const bool on ) myIsSuppressOutput = on; } +/*! + \brief Get 'show banner' flag value. + + \sa setIsShowBanner() + \return \c true if python console shows banner +*/ +bool PyConsole_Editor::isShowBanner() const +{ + return myShowBanner; +} + +/*! + \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_Editor::setIsShowBanner( const bool on ) +{ + if ( myShowBanner != on ) { + myShowBanner = on; + clear(); + } +} + +/*! + \brief Get size hint for the Python console window + \return size hint value +*/ +QSize PyConsole_Editor::sizeHint() const +{ + QFontMetrics fm( font() ); + int nbLines = ( isShowBanner() ? myBanner.split("\n").count() : 0 ) + 1; + QSize s(100, fm.lineSpacing()*nbLines); + return s; +} + /*! \brief Put the string \a str to the python editor. \param str string to be put in the command line of the editor @@ -1036,7 +1076,8 @@ void PyConsole_Editor::onPyInterpChanged( PyConsole_Interp* interp ) if ( myInterp ) { // print banner myBanner = myInterp->getbanner().c_str(); - addText( myBanner ); + if ( isShowBanner() ) + addText( myBanner ); // clear command buffer myCommandBuffer.truncate(0); // unset read-only state @@ -1123,7 +1164,8 @@ void PyConsole_Editor::paste() void PyConsole_Editor::clear() { QTextEdit::clear(); - addText( myBanner ); + if ( isShowBanner() ) + addText( myBanner ); myPrompt = READY_PROMPT; addText( myPrompt ); } diff --git a/src/PyConsole/PyConsole_Editor.h b/src/PyConsole/PyConsole_Editor.h index 6f8eba127..8a5931a1b 100644 --- a/src/PyConsole/PyConsole_Editor.h +++ b/src/PyConsole/PyConsole_Editor.h @@ -55,6 +55,11 @@ public: bool isSuppressOutput() const; void setIsSuppressOutput(const bool); + bool isShowBanner() const; + void setIsShowBanner( const bool ); + + virtual QSize sizeHint() const; + protected: virtual void dropEvent( QDropEvent* event ); virtual void mouseReleaseEvent( QMouseEvent* event ); @@ -81,6 +86,7 @@ private: QStringList myHistory; //!< commands history buffer QEventLoop* myEventLoop; //!< internal event loop QString myBanner; //!< current banner + bool myShowBanner; //!< 'show banner' flag QStringList myQueue; //!< python commands queue bool myIsSync; //!< synchronous mode flag bool myIsSuppressOutput; //!< suppress output flag diff --git a/src/Qtx/QtxDockAction.cxx b/src/Qtx/QtxDockAction.cxx index 5a1f3fa58..819323d95 100755 --- a/src/Qtx/QtxDockAction.cxx +++ b/src/Qtx/QtxDockAction.cxx @@ -95,6 +95,14 @@ QtxDockAction::~QtxDockAction() } } +/*! + \brief Update associated menu +*/ +void QtxDockAction::update() +{ + updateMenu(); +} + /*! \brief Get parent main window. \return main window pointer. diff --git a/src/Qtx/QtxDockAction.h b/src/Qtx/QtxDockAction.h index 64b2c4ea1..114c9f084 100755 --- a/src/Qtx/QtxDockAction.h +++ b/src/Qtx/QtxDockAction.h @@ -57,6 +57,8 @@ public: QtxDockAction( const QString&, const QIcon&, const QString&, QMainWindow* ); virtual ~QtxDockAction(); + void update(); + int dockType() const; void setDockType( const int ); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index c74eae84e..1e7e3863e 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -940,6 +940,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) ob->setAutoSizeFirstColumn(autoSizeFirst); ob->setAutoSizeColumns(autoSize); ob->setResizeOnExpandItem(resizeOnExpandItem); + ob->setProperty( "shortcut", QKeySequence( "Alt+Shift+O" ) ); // temporary commented /* @@ -964,8 +965,10 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) PyConsole_Console* pyCons = new PyConsole_Console( desktop(), new SalomeApp_PyInterp() ); pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) ); pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" )); + pyCons->setIsShowBanner(resourceMgr()->booleanValue( "PyConsole", "show_banner", true )); + pyCons->setProperty( "shortcut", QKeySequence( "Alt+Shift+P" ) ); wid = pyCons; - pyCons->resize( pyCons->width(), desktop()->height()/4 ); + //pyCons->resize( pyCons->width(), desktop()->height()/4 ); pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } return wid; diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index 358809fc3..b8053da90 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -120,6 +120,7 @@
+
-- 2.39.2