Salome HOME
Fix a bug : popup menus do not work for Python modules when XML menu description...
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUI / SALOME_PYQT_Module.h
1 //=============================================================================
2 // File      : SALOME_PYQT_Module.h
3 // Created   : 25/04/05
4 // Author    : Vadim SANDLER
5 // Project   : SALOME
6 // Copyright : 2003-2005 CEA/DEN, EDF R&D
7 // $Header   : $
8 //=============================================================================
9
10 #ifndef SALOME_PYQT_MODULE_H
11 #define SALOME_PYQT_MODULE_H
12
13 #include "SALOME_PYQT_GUI.h"
14
15 #include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_base.h)!
16 #include "SalomeApp_Module.h"
17 #include <map>
18 #include <qaction.h>
19 #include <qptrlist.h>
20 #include <qstringlist.h>
21 #include <qmap.h>
22
23 #include <SALOMEconfig.h>
24 #include CORBA_CLIENT_HEADER(SALOME_Component)
25
26 class SALOME_PYQT_XmlHandler;
27
28 class SALOME_PYQT_EXPORT SALOME_PYQT_Module: public SalomeApp_Module
29 {
30   Q_OBJECT;
31
32   /******************************
33    * Data
34    ******************************/
35
36 private:
37   typedef std::map<int, SALOME_PYQT_PyInterp*> InterpMap;
38
39   /* study-to-subinterpreter map */
40   static InterpMap                 myInterpMap;
41   /* current Python subinterpreter */
42   SALOME_PYQT_PyInterp*            myInterp;
43   /* Python GUI module loaded */
44   PyObjWrapper                     myModule;
45   /* Pytho GUI being initialized (not zero only during the initialization)*/
46   static SALOME_PYQT_Module* myInitModule;
47
48   typedef QPtrList<QAction> ActionList;
49   
50   /* own actions list */
51   ActionList                       myMenuActionList;
52   ActionList                       myPopupActionList;
53   ActionList                       myToolbarActionList;
54  
55   enum PyQtGUIAction { PYQT_ACTION_MENU    = 10000000,
56                        PYQT_ACTION_TOOLBAL = 20000000,
57                        PYQT_ACTION_POPUP   = 30000000 };
58
59   /* XML resource file parser */
60   SALOME_PYQT_XmlHandler*          myXmlHandler;  
61   /* windows map*/
62   QMap<int, int>                   myWindowsMap;
63   /* compatible view managers list */
64   QStringList                      myViewMgrList;
65   
66   /******************************
67    * Construction/destruction
68    ******************************/
69
70 public:
71   /* constructor */
72   SALOME_PYQT_Module();
73   /* destructor */
74   ~SALOME_PYQT_Module();
75
76   /* get module engine */
77   Engines::Component_var getEngine() const;
78
79   /******************************
80    * Inherited from SalomeApp_Module 
81    ******************************/
82
83 public:
84   /* little trick : provide an access to being activated Python module from outside;
85      needed by the SalomePyQt library :(
86   */
87   static SALOME_PYQT_Module* getInitModule();
88
89   /* initialization */
90   void            initialize  ( CAM_Application* );
91
92   /* getting windows list */
93   void            windows     ( QMap<int, int>& ) const;
94   /* getting compatible viewer managers list */
95   void            viewManagers( QStringList& ) const;
96
97   /* context popup menu request */
98   void            contextMenuPopup( const QString&, QPopupMenu*, QString& );
99
100   /* get module engine IOR */
101   virtual QString engineIOR() const;
102
103   /* called when study desktop is activated */
104   virtual void    studyActivated();
105
106   /* working with toolbars : open protected methods */
107   int                    createTool( const QString& );
108   int                    createTool( const int, const int, const int = -1 );
109   int                    createTool( const int, const QString&, const int = -1 );
110   int                    createTool( QAction*, const int, const int = -1, const int = -1 );
111   int                    createTool( QAction*, const QString&, const int = -1, const int = -1 );
112
113   /* working with menus : open protected methods */
114   int                    createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
115   int                    createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
116   int                    createMenu( const int, const int, const int = -1, const int = -1 );
117   int                    createMenu( const int, const QString&, const int = -1, const int = -1 );
118   int                    createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
119   int                    createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );
120
121   /* create separator : open protected method */
122   QAction*               createSeparator();
123
124   /* working with actions : open protected methods */
125   QAction*               action( const int ) const;
126   int                    actionId( const QAction* ) const;
127   QAction*               createAction( const int, const QString&, const QString&, const QString&,
128                                        const QString&, const int, const bool = false );
129
130 public slots:
131   /* activation */
132   virtual bool    activateModule( SUIT_Study* );
133   /* deactivation */
134   virtual bool    deactivateModule( SUIT_Study* );
135
136   /******************************
137    * Internal methods
138    ******************************/
139
140 public slots:
141   /* GUI action processing slots */
142   void            onGUIEvent();
143   void            onGUIEvent( int );
144
145 private:
146   /* internal initizalition */ 
147   void            init        ( CAM_Application* );
148   /* internal activation */ 
149   void            activate    ( SUIT_Study* );
150   /* internal deactivation */ 
151   void            deactivate  ( SUIT_Study* );
152   /* study activation */ 
153   void            studyChanged( SUIT_Study* );
154   /* context popup menu processing */
155   void            contextMenu( const QString&, QPopupMenu* );
156   /* GUI event processing */
157   void            guiEvent( const int );
158
159   /* add action to the private action map */ 
160   void            addAction   ( const PyQtGUIAction, QAction* );
161
162   /* initialize a Python subinterpreter */
163   void            initInterp  ( int );
164   /* import a Python GUI module */
165   void            importModule();
166   /* set workspace to Python GUI module */
167   void            setWorkSpace();
168
169   friend class SALOME_PYQT_XmlHandler;
170 };
171
172 #endif // SALOME_PYQT_MODULE_H