From: vsr Date: Tue, 7 Jul 2009 14:40:34 +0000 (+0000) Subject: Issue 0020424: EDF 1069 GUI: How to add an icon in the GUI of a python module X-Git-Tag: V5_1_3rc1~49 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a401426ce70799cc112ec0c89e0cf0c35a8e35dd;p=modules%2Fgui.git Issue 0020424: EDF 1069 GUI: How to add an icon in the GUI of a python module Introduce loadIcon() method to the SalomePyQt Python interface --- diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index a7f02d0f2..b6f0b19ca 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -1258,6 +1258,40 @@ QString SalomePyQt::getExistingDirectory( QWidget* parent, return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) ); } +/*! + \fn QString SalomePyQt::loadIcon( const QString& filename ); + \brief Load an icon from the module resources by the specified file name. + \param filename icon file name + \return icon object +*/ +class TLoadIconEvent: public SALOME_Event +{ +public: + typedef QIcon TResult; + TResult myResult; + QString myModule; + QString myFileName; + TLoadIconEvent( const QString& module, const QString& filename ) + : myModule( module ), + myFileName ( filename ) {} + virtual void Execute() + { + if ( LightApp_Application* anApp = getApplication() ) { + if ( !myFileName.isEmpty() ) { + QPixmap pixmap = anApp->resourceMgr()->loadPixmap( myModule, + QApplication::translate( myModule.toLatin1().data(), + myFileName.toLatin1().data() ) ); + if ( !pixmap.isNull() ) + myResult = QIcon( pixmap ); + } + } + } +}; +QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename ) +{ + return ProcessEvent( new TLoadIconEvent( module, filename ) ); +} + /*! \brief Open external browser to display context help information. \todo diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 7bb7b9c6d..47a3a24d6 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -145,6 +145,8 @@ public: static QString getName(const QString& obj); static QString getToolTip(const QString& obj); + static QIcon loadIcon( const QString&, const QString& ); + static void helpContext( const QString&, const QString& ); static bool dumpView( const QString& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 0eaa4c879..65d493cf8 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -234,6 +234,7 @@ public: static void removeChild(const QString& = QString("") ) /ReleaseGIL/ ; static QStringList getChildren(const QString&=QString("") , const bool = false) /ReleaseGIL/ ; + static QIcon loadIcon( const QString&, const QString& ) /ReleaseGIL/ ; static void helpContext( const QString&, const QString& ) /ReleaseGIL/ ; static bool dumpView( const QString& ) /ReleaseGIL/ ;