PyInterp_Dispatcher::Get()->Exec( new PopupMenuEvent( myInterp, this, theContext, thePopupMenu ) );
}
+/*!
+ * Export preferences for the Python module.
+ * Called only once when the first instance of the module is created.
+ */
+void SALOME_PYQT_Module::createPreferences()
+{
+ MESSAGE( "SALOME_PYQT_Module::createPr eferences");
+ // perform synchronous request to Python event dispatcher
+ class Event : public PyInterp_LockRequest
+ {
+ public:
+ Event( PyInterp_base* _py_interp,
+ SALOME_PYQT_Module* _obj )
+ : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+ myObj ( _obj ) {}
+
+ protected:
+ virtual void execute()
+ {
+ myObj->initPreferences();
+ }
+
+ private:
+ SALOME_PYQT_Module* myObj;
+ };
+
+ // Posting the request only if dispatcher is not busy!
+ // Executing the request synchronously
+ if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+ PyInterp_Dispatcher::Get()->Exec( new Event( myInterp, this ) );
+}
+
/*!
* Defines the dockable window associated with the module.
* To fill the list of windows the correspondind Python module's windows()
}
}
+/*!
+ * Initialises preferences for the module
+ * - calls Python module's createPreferences() method
+ */
+void SALOME_PYQT_Module::initPreferences()
+{
+ // Python interpreter should be initialized and Python module should be
+ // import first
+ if ( !myInterp || !myModule )
+ return;
+
+ // temporary set myInitModule because createPreferences() method
+ // might be called during the module intialization process
+ myInitModule = this;
+
+ if ( PyObject_HasAttrString(myModule , "createPreferences") ) {
+ PyObjWrapper res( PyObject_CallMethod( myModule, "createPreferences", "" ) );
+ if( !res ) {
+ PyErr_Print();
+ }
+ }
+
+ myInitModule = 0;
+}
+
/*!
* Initialises python subinterpreter (one per study)
*/
}
return a;
}
+
/*!
* Load icon from resource file
*/
return false;
}
+/*!
+ * The next methods call the parent implementation.
+ * This is done to open protected methods from LightApp_Module class.
+ */
+
+int SALOME_PYQT_Module::addPreference( const QString& label )
+{
+ return SalomeApp_Module::addPreference( label );
+}
+
+int SALOME_PYQT_Module::addPreference( const QString& label,
+ const int pId, const int type,
+ const QString& section,
+ const QString& param )
+{
+ return SalomeApp_Module::addPreference( label, pId, type, section, param );
+}
+
+QVariant SALOME_PYQT_Module::preferenceProperty( const int id,
+ const QString& prop ) const
+{
+ QVariant v = SalomeApp_Module::preferenceProperty( id, prop );
+ return v;
+}
+
+void SALOME_PYQT_Module::setPreferenceProperty( const int id,
+ const QString& prop,
+ const QVariant& var )
+{
+ SalomeApp_Module::setPreferenceProperty( id, prop, var );
+}
+
// SALOME_PYQT_XmlHandler class implementation
// gets an tag name for the dom element [ static ]
/* context popup menu request */
void contextMenuPopup( const QString&, QPopupMenu*, QString& );
+ /* create preferences */
+ void createPreferences();
+
/* get module engine IOR */
virtual QString engineIOR() const;
/* load icon from resource file */
QIconSet loadIcon( const QString& fileName );
+ /* working with preferences : open protected methods */
+ int addPreference( const QString& );
+ int addPreference( const QString&, const int, const int = -1,
+ const QString& = QString::null,
+ const QString& = QString::null );
+ QVariant preferenceProperty( const int, const QString& ) const;
+ void setPreferenceProperty( const int, const QString&, const QVariant& );
+
/* Show/hide menus/toolbars */
void setMenuShown( const bool );
void setToolShown( const bool );
void guiEvent( const int );
/* Menu highlight processing */
void menuHighlight( const int, const int );
+ /* Init preferences */
+ void initPreferences();
/* initialize a Python subinterpreter */
void initInterp ( int );
return ProcessEvent( new TClearMenuEvent( id, menu, removeActions ) );
}
+/*!
+ SalomePyQt::addPreference
+ Adds preference
+ */
+class TAddPrefEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ QString myLabel;
+ TAddPrefEvent( const QString& label )
+ : myResult( -1 ), myLabel( label ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->addPreference( myLabel );
+ }
+ }
+};
+int SalomePyQt::addPreference( const QString& label )
+{
+ return ProcessEvent( new TAddPrefEvent( label ) );
+}
+
+/*!
+ SalomePyQt::addPreference
+ Adds preference
+ */
+class TAddPrefParamEvent: public SALOME_Event {
+public:
+ typedef int TResult;
+ TResult myResult;
+ QString myLabel;
+ int myPId;
+ int myType;
+ QString mySection;
+ QString myParam;
+ TAddPrefParamEvent( const QString& label,
+ const int pId, const int type,
+ const QString& section,
+ const QString& param )
+ : myResult( -1 ),
+ myLabel( label ), myPId( pId ), myType( type ),
+ mySection( section ), myParam ( param ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->addPreference( myLabel, myPId, myType, mySection, myParam );
+ }
+ }
+};
+int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
+ const QString& section, const QString& param )
+{
+ return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
+}
+
+/*!
+ SalomePyQt::preferenceProperty
+ Gets the property value for the given (by id) preference
+ */
+class TPrefPropEvent: public SALOME_Event {
+public:
+ typedef QVariant TResult;
+ TResult myResult;
+ int myId;
+ QString myProp;
+ TPrefPropEvent( const int id, const QString& prop )
+ : myId( id ), myProp( prop )
+ {
+ myResult = QVariant();
+ }
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ myResult = module->preferenceProperty( myId, myProp );
+ }
+ }
+};
+QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
+{
+ return ProcessEvent( new TPrefPropEvent( id, prop ) );
+}
+
+/*!
+ SalomePyQt::setPreferenceProperty
+ Sets the property value for the given (by id) preference
+ */
+void SalomePyQt::setPreferenceProperty( const int id,
+ const QString& prop,
+ const QVariant& var )
+{
+ class TEvent: public SALOME_Event {
+ int myId;
+ QString myProp;
+ QVariant myVar;
+ public:
+ TEvent( const int id, const QString& prop, const QVariant& var )
+ : myId( id ), myProp( prop ), myVar( var ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module )
+ module->setPreferenceProperty( myId, myProp, myVar );
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent( id, prop, var) );
+}
+
+/*!
+ SalomePyQt::addPreferenceProperty
+ Adds the property value to the list of values
+ for the given (by id) preference
+
+ This method allows creating properties which are QValueList<QVariant>
+ - there is no way to pass such values directly to QVariant parameter
+ from Python
+ */
+void SalomePyQt::addPreferenceProperty( const int id,
+ const QString& prop,
+ const int idx,
+ const QVariant& var )
+{
+ class TEvent: public SALOME_Event {
+ int myId;
+ QString myProp;
+ int myIdx;
+ QVariant myVar;
+ public:
+ TEvent( const int id, const QString& prop, const int idx, const QVariant& var )
+ : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
+ virtual void Execute() {
+ if ( SalomeApp_Application* anApp = getApplication() ) {
+ SALOME_PYQT_Module* module = SALOME_PYQT_Module::getInitModule();
+ if ( !module )
+ module = dynamic_cast<SALOME_PYQT_Module*>( anApp->activeModule() );
+ if ( module ) {
+ QVariant var = module->preferenceProperty( myId, myProp );
+ if ( var.isValid() ) {
+ if ( var.type() == QVariant::StringList ) {
+ QStringList sl = var.asStringList();
+ if ( myIdx >= 0 && myIdx < sl.count() )
+ sl[myIdx] = myVar.asString();
+ else
+ sl.append( myVar.asString() );
+ module->setPreferenceProperty( myId, myProp, sl );
+ }
+ else if ( var.type() == QVariant::List ) {
+ QValueList<QVariant> vl = var.asList();
+ if ( myIdx >= 0 && myIdx < vl.count() )
+ vl[myIdx] = myVar;
+ else
+ vl.append( myVar );
+ module->setPreferenceProperty( myId, myProp, vl );
+ }
+ }
+ else {
+ QValueList<QVariant> vl;
+ vl.append( myVar );
+ module->setPreferenceProperty( myId, myProp, vl );
+ }
+ }
+ }
+ }
+ };
+ ProcessVoidEvent( new TEvent( id, prop, idx, var) );
+}
#include <qcolor.h>
#include <LightApp_Application.h>
+#include <LightApp_Preferences.h>
class LightApp_SelectionMgr;
class SalomeApp_Application;
WT_User = LightApp_Application::WT_User
};
+enum {
+ PT_Space = LightApp_Preferences::Space,
+ PT_Bool = LightApp_Preferences::Bool,
+ PT_Color = LightApp_Preferences::Color,
+ PT_String = LightApp_Preferences::String,
+ PT_Selector = LightApp_Preferences::Selector,
+ PT_DblSpin = LightApp_Preferences::DblSpin,
+ PT_IntSpin = LightApp_Preferences::IntSpin,
+ PT_Double = LightApp_Preferences::Double,
+ PT_Integer = LightApp_Preferences::Integer,
+ PT_GroupBox = LightApp_Preferences::GroupBox,
+ PT_Font = LightApp_Preferences::Font,
+ PT_DirList = LightApp_Preferences::DirList,
+ PT_File = LightApp_Preferences::File,
+ PT_User = LightApp_Preferences::User
+};
+
class SalomePyQt
{
public:
static void addDoubleSetting( const QString&, const double, bool = true );
static void removeSettings ( const QString& );
static QString getSetting ( const QString& );
+
+ static int addPreference( const QString& );
+ static int addPreference( const QString&,
+ const int, const int = -1,
+ const QString& = QString::null,
+ const QString& = QString::null );
+ static QVariant preferenceProperty( const int, const QString& );
+ static void setPreferenceProperty( const int,
+ const QString&,
+ const QVariant& );
+ static void addPreferenceProperty( const int,
+ const QString&,
+ const int,
+ const QVariant& );
};
#endif // SALOME_PYQT_H
WT_User
};
+enum PrefType {
+ PT_Space,
+ PT_Bool,
+ PT_Color,
+ PT_String,
+ PT_Selector,
+ PT_DblSpin,
+ PT_IntSpin,
+ PT_Double,
+ PT_Integer,
+ PT_GroupBox,
+ PT_Font,
+ PT_DirList,
+ PT_File,
+ PT_User
+};
+
class QtxAction : QAction
{
%TypeHeaderCode
static void addDoubleSetting( const QString&, const double, bool = true );
static void removeSettings ( const QString& );
static QString getSetting ( const QString& );
+
+ static int addPreference( const QString& );
+ static int addPreference( const QString&, const int, int = -1,
+ const QString& = QString::null,
+ const QString& = QString::null );
+ static QVariant preferenceProperty( const int, const QString& );
+ static void setPreferenceProperty( const int,
+ const QString&,
+ const QVariant& );
+ static void addPreferenceProperty( const int,
+ const QString&,
+ const int,
+ const QVariant& );
};
WT_User
};
+enum PrefType {
+ PT_Space,
+ PT_Bool,
+ PT_Color,
+ PT_String,
+ PT_Selector,
+ PT_DblSpin,
+ PT_IntSpin,
+ PT_Double,
+ PT_Integer,
+ PT_GroupBox,
+ PT_Font,
+ PT_DirList,
+ PT_File,
+ PT_User
+};
+
class QtxAction : QAction
{
%TypeHeaderCode
static void addDoubleSetting( const QString&, const double, bool = true ) /ReleaseGIL/ ;
static void removeSettings ( const QString& ) /ReleaseGIL/ ;
static QString getSetting ( const QString& ) /ReleaseGIL/ ;
+
+ static int addPreference( const QString& ) /ReleaseGIL/ ;
+ static int addPreference( const QString&,
+ const int, const int = -1,
+ const QString& = QString::null,
+ const QString& = QString::null ) /ReleaseGIL/ ;
+ static QVariant preferenceProperty( const int, const QString& ) /ReleaseGIL/ ;
+ static void setPreferenceProperty( const int,
+ const QString&,
+ const QVariant& ) /ReleaseGIL/ ;
+ static void addPreferenceProperty( const int,
+ const QString&,
+ const int,
+ const QVariant& ) /ReleaseGIL/ ;
};