Salome HOME
Fix a bug : popup menus do not work for Python modules when XML menu description...
authorvsr <vsr@opencascade.com>
Fri, 9 Sep 2005 12:06:04 +0000 (12:06 +0000)
committervsr <vsr@opencascade.com>
Fri, 9 Sep 2005 12:06:04 +0000 (12:06 +0000)
src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx
src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.h

index ee69552233787eee0017b707149c272d7da354ec..1d79e16fa3d541137f94d07b87fe3906c7c95010 100644 (file)
@@ -344,6 +344,37 @@ void SALOME_PYQT_Module::onGUIEvent()
   PyInterp_Dispatcher::Get()->Exec( new GUIEvent( myInterp, this, id ) );
 }
 
+/*!
+ * Processes GUI action (from context popup menu, only for XML-based actions!)
+ */
+void SALOME_PYQT_Module::onGUIEvent( int id ) 
+{
+  // perform synchronous request to Python event dispatcher
+  class GUIEvent : public PyInterp_LockRequest
+  {
+  public:
+    GUIEvent( PyInterp_base*      _py_interp, 
+             SALOME_PYQT_Module* _obj,
+             int                 _id ) 
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myId    ( _id  ),
+        myObj   ( _obj ) {}
+    
+  protected:
+    virtual void execute()
+    {
+      myObj->guiEvent( myId );
+    }
+
+  private:
+    int                 myId;
+    SALOME_PYQT_Module* myObj;
+  };
+
+  // Posting the request
+  PyInterp_Dispatcher::Get()->Exec( new GUIEvent( myInterp, this, id ) );
+}
+
 /*! 
   Context popup menu request.
   Called when user activates popup menu in some window (view, object browser, etc).
@@ -1245,7 +1276,7 @@ void SALOME_PYQT_XmlHandler::insertPopupItems( QDomNode& parentNode, QPopupMenu*
        // -1 action ID is not allowed : it means that <item-id> attribute is missed in the XML file!
        // also check if the action with given ID is already created
        if ( id != -1 ) {
-         menu->insertItem( anIcon, label, myModule, SLOT( onGUIEvent() ), QKeySequence( accel ), id, pos );
+         menu->insertItem( anIcon, label, myModule, SLOT( onGUIEvent(int) ), QKeySequence( accel ), id, pos );
        }
       }
       else if ( aTagName == "submenu" ) {
index 530e70faa943154dd2f920095905e0f5cb4aaded..5377c29690db38767fffc0e1015f6cc73e1799bb 100644 (file)
@@ -138,8 +138,9 @@ public slots:
    ******************************/
 
 public slots:
-  /* GUI action processing slot */
+  /* GUI action processing slots */
   void            onGUIEvent();
+  void            onGUIEvent( int );
 
 private:
   /* internal initizalition */