From ea2ce8f99abd26806435f570a3deb394de07c3c1 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 7 Jul 2009 15:20:03 +0000 Subject: [PATCH] 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 --- src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 34 ++++++++++++++++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 3 ++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 1 + src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip | 1 + 4 files changed, 39 insertions(+) diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index dee7dd661..b9ce286f1 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -1035,6 +1035,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 QIconSet 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, + qApp->translate( myModule.latin1(), + myFileName.latin1() ) ); + if ( !pixmap.isNull() ) + myResult = QIconSet( pixmap ); + } + } + } +}; +QIconSet SalomePyQt::loadIcon( const QString& module, const QString& filename ) +{ + return ProcessEvent( new TLoadIconEvent( module, filename ) ); +} + /*! SalomePyQt::helpContext Opens external browser to display 'context help' information diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 576db0564..ef26ad3ad 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -125,6 +126,8 @@ public: static QStringList getOpenFileNames ( QWidget*, const QString&, const QStringList&, const QString& ); static QString getExistingDirectory( QWidget*, const QString&, const QString& ); + static QIconSet 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 65f280e46..1a95e68f1 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -123,6 +123,7 @@ public: static QStringList getOpenFileNames ( QWidget*, const QString&, const QStringList&, const QString& ); static QString getExistingDirectory( QWidget*, const QString&, const QString& ); + static QIcoSet 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_v4.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip index e6d6d494d..83209528a 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip @@ -129,6 +129,7 @@ public: static QStringList getOpenFileNames ( QWidget*, const QString&, const QStringList&, const QString& ) /ReleaseGIL/ ; static QString getExistingDirectory( QWidget*, const QString&, const QString& ) /ReleaseGIL/ ; + static QIconSet loadIcon( const QString&, const QString& ) /ReleaseGIL/ ; static void helpContext( const QString&, const QString& ) /ReleaseGIL/ ; static bool dumpView( const QString& ) /ReleaseGIL/ ; -- 2.39.2