summarylogtreecommitdiffstats
path: root/sip-4.19.patch
blob: 29fc1f8ab720fba00937e54bf1280dd01fb04b92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
diff -Naur -i GUI_SRC_8.3.0.orig/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx GUI_SRC_8.3.0/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx
--- GUI_SRC_8.3.0.orig/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx	2017-11-30 22:50:14.097716795 +0100
+++ GUI_SRC_8.3.0/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx	2017-11-30 22:51:58.686223163 +0100
@@ -1866,7 +1866,7 @@
 #if SIP_VERSION < 0x040800
   PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget) );
 #else
-  PyObjWrapper pyws( sipBuildResult( 0, "D", aWorkspace, sipType_QWidget , NULL) );
+  PyObjWrapper pyws( sipBuildResult( 0, "D", aWorkspace, sipFindType("QWidget") , NULL) );
 #endif
   // ... and finally call Python module's setWorkSpace() method (obsolete)
   if ( PyObject_HasAttrString( myPyModule, (char*)"setWorkSpace" ) ) {
@@ -2281,7 +2281,7 @@
 #if SIP_VERSION < 0x040800
   PyObjWrapper sipList(sipBuildResult(0, "M", theList, sipClass_QStringList));
 #else
-  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
+  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipFindType("QStringList"), NULL ) );
 #endif
   if (PyObject_HasAttrString(myPyModule, (char*) "onSelectionUpdated"))
     {
@@ -2354,7 +2354,7 @@
 #if SIP_VERSION < 0x040800
   PyObjWrapper sipPopup( sipBuildResult( 0, "M", menu, sipClass_QMenu ) );
 #else
-  PyObjWrapper sipPopup( sipBuildResult( 0, "D", menu, sipType_QMenu, NULL ) );
+  PyObjWrapper sipPopup( sipBuildResult( 0, "D", menu, sipFindType("QMenu"), NULL ) );
 #endif
 
   // then call Python module's createPopupMenu() method (for new modules)
@@ -2574,7 +2574,7 @@
 #if SIP_VERSION < 0x040800
   PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList ) );
 #else
-  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
+  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipFindType("QStringList"), NULL ) );
 #endif
   if ( PyObject_HasAttrString(myPyModule , (char*)"openFiles") ) {
 
@@ -2737,7 +2737,7 @@
 #if SIP_VERSION < 0x040800
   PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList) );
 #else
-  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL) );
+  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipFindType("QStringList"), NULL) );
 #endif
   if ( PyObject_HasAttrString(myPyModule, (char*)"dropObjects") ) {
       PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"dropObjects", (char*)"Osii",
diff -Naur -i GUI_SRC_8.3.0.orig/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx.orig GUI_SRC_8.3.0/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx.orig
--- GUI_SRC_8.3.0.orig/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx.orig	1970-01-01 01:00:00.000000000 +0100
+++ GUI_SRC_8.3.0/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx.orig	2017-11-30 22:50:02.594551445 +0100
@@ -0,0 +1,2881 @@
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// File   : SALOME_PYQT_PyModule.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+//
+
+#include "SALOME_PYQT_PyModule.h"
+#include "SALOME_PYQT_PyInterp.h"
+
+#include "LightApp_Application.h"
+#include "LightApp_DataObject.h"
+#include "LightApp_Module.h"
+#include "LightApp_Study.h"
+#include "PyInterp_Dispatcher.h"
+#include "QtxActionMenuMgr.h"
+#include "QtxWorkspace.h"
+#include "QtxWorkstack.h"
+#include "STD_MDIDesktop.h"
+#include "STD_TabDesktop.h"
+#include "SUITApp_init_python.hxx"
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_ViewManager.h"
+#include "SUIT_ViewModel.h"
+#include "SUIT_ViewWindow.h"
+
+#include <QApplication>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QDomNode>
+#include <QFile>
+#include <QMenu>
+#include <QMutex>
+
+#include <utilities.h>
+
+#include "sipAPISalomePyQtGUILight.h"
+
+/*!
+  \brief Default menu group number.
+  \internal
+*/
+const int DEFAULT_GROUP = 40;
+
+/*!
+  \brief Mutex used to lock access from several threads to the shared
+  (static) data
+  \internal
+*/
+QMutex myInitMutex;
+
+/*! DEBUG mode */
+const bool DEBUG = false;
+
+/*!
+  \var IsCallOldMethods
+  \brief Allow calling obsolete callback methods.
+  \internal
+  
+  If the macro CALL_OLD_METHODS is not defined, the invoking
+  of obsolete Python module's methods like setSetting(), definePopup(), 
+  etc. is blocked.
+
+  CALL_OLD_METHODS macro can be defined, for example, by adding 
+  -DCALL_OLD_METHODS compilation option to the CMakeLists.txt.
+*/
+#ifdef CALL_OLD_METHODS
+const bool IsCallOldMethods = true;
+#else
+const bool IsCallOldMethods = false;
+#endif
+
+/*!
+  \brief Get tag name for the DOM element.
+  \internal
+  \param element DOM element
+  \return tag name or empty string if the element does not have tag name
+*/
+static QString tagName( const QDomElement& element )
+{
+  return element.tagName().trimmed();
+}
+
+/*!
+  \brief Get value of DOM element's attribute.
+  \internal
+  \param element DOM element
+  \param attName attribute name
+  \return attribute value or empty string if the element does not have such attribute
+*/
+static QString attribute( const QDomElement& element, const QString& attName )
+{
+  return element.attribute( attName ).trimmed();
+}
+
+/*!
+  \brief Inspect specified string for the boolean value.
+  \internal
+  
+  This function returns \c true if string represents boolean value: 
+  - "true", "yes" or "1" for \c true
+  - "false", "no" or "0" for \c false
+  Second parameter allows to specify what boolean value is expected:
+  - 1: \c true
+  - 0: \c false
+  - other value is not taken into account (return represented value)
+
+  \param value inspected string
+  \param check expected boolean value
+  \return boolean value represented by the string (\a check is not 1 or 0)
+          or \c true if value correspond to the specified \a check
+*/
+static bool checkBool( const QString& value, const int check = -1 )
+{
+  QString v = value.toLower();
+  if ( ( v == "true"  || v == "yes" || v == "1" ) && ( check != 0 ) )
+    return true;
+  if ( ( v == "false" || v == "no"  || v == "0" ) && ( check == 0 ) )
+    return true;
+  return false;
+}
+
+/*!
+  \brief Inspect specified string for the integer value.
+  \internal
+  
+  This function returns returns -1 if item is empty or represents
+  an invalid number.
+  \param value inspected string
+  \param def default value
+  \param shift shift value (it is added to the integer value to produce shifted result)
+*/
+static int checkInt( const QString& value, const int def = -1, const int shift = -1 )
+{
+  bool bOk;
+  int val = value.toInt( &bOk );
+  if ( !bOk ) val = def;
+  if ( shift > 0 && bOk && val < 0 )
+    val += shift;
+  return val;
+}
+
+/*!
+  \class FuncMsg
+  \brief Function call in/out tracer.
+  \internal
+*/
+
+class FuncMsg
+{
+public:
+  FuncMsg( const QString& funcName )
+  {
+    myName = funcName;
+    if ( DEBUG )
+      MESSAGE( qPrintable( myName ) << " [ begin ]" );
+  }
+  ~FuncMsg()
+  {
+    if ( DEBUG )
+      MESSAGE( qPrintable( myName ) << " [ end ]" );
+  }
+  void message( const QString& msg )
+  {
+    if ( DEBUG )
+      MESSAGE( qPrintable( myName ) << " : " << qPrintable( msg ) );
+  }
+private:
+  QString myName;
+};
+
+/*!
+  \class PyModuleHelper::InitLocker
+  \brief Initialization locker
+  \internal
+*/
+
+class PyModuleHelper::InitLocker
+{
+public:
+  InitLocker( LightApp_Module* );
+  ~InitLocker();
+};
+
+/*!
+  \brief Constructor
+  \internal
+*/
+PyModuleHelper::InitLocker::InitLocker( LightApp_Module* module )
+{
+  QMutexLocker ml( &myInitMutex );
+  myInitModule = module;
+}
+
+/*!
+  \brief Destructor
+  \internal
+*/
+PyModuleHelper::InitLocker::~InitLocker()
+{
+  QMutexLocker ml( &myInitMutex );
+  myInitModule = 0;
+}
+
+/*!
+  \class PyModuleHelper::XmlHandler
+  \brief XML resource files parser.
+  \internal
+
+  This class is used to provide backward compatibility with
+  existing Python modules in which obsolete menu definition system
+  (via XML files) is used.
+*/
+
+class PyModuleHelper::XmlHandler
+{
+public:
+  XmlHandler( PyModuleHelper* helper, const QString& fileName );
+  void             createActions();
+  void             createPopup( QMenu* menu,
+                                const QString& context,
+                                const QString& parent,
+                                const QString& object );
+  void             activateMenus( bool );
+
+private:
+  LightApp_Module* module() const;
+  QIcon            loadIcon( const QString& fileName );
+
+  void             createMenu( QDomNode& parentNode,
+                               const int parentMenuId = -1,
+                               QMenu* parentPopup = 0 );
+  void             createToolBar( QDomNode& parentNode );
+  void             insertPopupItems( QDomNode& parentNode,
+                                     QMenu* menu );
+
+private:
+  PyModuleHelper*  myHelper;
+  QDomDocument     myDoc;
+  QList<int>       myMenuItems;
+};
+
+
+/*!
+  \brief Constructor
+  \internal
+  \param module pointer to the GUI module
+  \param fileName path to the XML menu description file 
+*/
+PyModuleHelper::XmlHandler::XmlHandler( PyModuleHelper*  helper,
+                                        const QString&   fileName )
+: myHelper( helper )
+{
+  if ( !fileName.isEmpty() ) { 
+    QFile aFile( fileName );
+    if ( aFile.open( QIODevice::ReadOnly ) ) {
+      myDoc.setContent( &aFile );
+    }
+  }
+}
+
+/*!
+  \brief Parse XML file and create actions.
+  \internal
+  
+  Called by PyModuleHelper::initialize() in order to create actions
+  (menus, toolbars).
+*/
+void PyModuleHelper::XmlHandler::createActions()
+{
+  // get document element
+  QDomElement aDocElem = myDoc.documentElement();
+
+  // create main menu actions
+  QDomNodeList aMenuList = aDocElem.elementsByTagName( "menu-item" );
+  for ( int i = 0; i < aMenuList.count(); i++ ) {
+    QDomNode n = aMenuList.item( i );
+    createMenu( n );
+  }
+
+  // create toolbars actions
+  QDomNodeList aToolsList = aDocElem.elementsByTagName( "toolbar" );
+  for ( int i = 0; i < aToolsList.count(); i++ ) {
+    QDomNode n = aToolsList.item( i );
+    createToolBar( n );
+  }
+}
+
+/*!
+  \brief Create popup menu.
+  \internal
+  \param menu popup menu
+  \param context popup menu context
+  \param context popup menu parent object name
+  \param context popup menu object name
+*/
+void PyModuleHelper::XmlHandler::createPopup( QMenu*         menu,
+                                              const QString& context,
+                                              const QString& parent,
+                                              const QString& object )
+{
+  // get document element
+  QDomElement aDocElem = myDoc.documentElement();
+
+  // get popup menus actions
+  QDomNodeList aPopupList = aDocElem.elementsByTagName( "popupmenu" );
+  for ( int i = 0; i < aPopupList.count(); i++ ) {
+    QDomNode n = aPopupList.item( i );
+    if ( !n.isNull() && n.isElement() ) {
+      QDomElement e = n.toElement();
+      // QString lab = attribute( e, "label-id" ); // not used // 
+      QString ctx = attribute( e, "context-id" );
+      QString prt = attribute( e, "parent-id"  );
+      QString obj = attribute( e, "object-id"  );
+      if ( ctx == context && prt == parent && obj == object )  {
+        insertPopupItems( n, menu );
+        break;
+      }
+    }
+  }
+}
+
+/*!
+  \brief Activate/deactivate menus
+  \internal
+  \param enable if \c true menus are activated, otherwise menus are deactivated
+*/
+void PyModuleHelper::XmlHandler::activateMenus( bool enable )
+{
+  if ( module() ) {
+    QtxActionMenuMgr* mgr = module()->menuMgr();
+    foreach( int id, myMenuItems ) mgr->setEmptyEnabled( id, enable );
+  }
+}
+
+/*!
+  \brief Get owner module
+*/
+LightApp_Module* PyModuleHelper::XmlHandler::module() const
+{
+  return myHelper->module();
+}
+
+/*!
+  \brief Load an icon from the module resources by the specified file name.
+  \param fileName icon file name
+  \return icon object
+*/
+
+QIcon PyModuleHelper::XmlHandler::loadIcon( const QString& fileName )
+{
+  QIcon icon;
+
+  if ( module() && !fileName.isEmpty() ) {
+      SUIT_ResourceMgr* resMgr = module()->getApp()->resourceMgr();
+      QPixmap pixmap = resMgr->loadPixmap( module()->name(),
+          QApplication::translate( module()->name().toLatin1().data(),
+                                   fileName.toLatin1().data() ) );
+      if ( !pixmap.isNull() )
+        icon = QIcon( pixmap );
+  }
+
+  return icon;
+}
+
+/*!
+  \brief Create main menu item and insert actions to it.
+  \internal
+  \param parentNode XML node with menu description
+  \param parentMenuId parent menu ID (-1 for top-level menu)
+  \param parentPopup parent popup menu (0 for top-level menu)
+*/
+void PyModuleHelper::XmlHandler::createMenu( QDomNode& parentNode, 
+                                             const int parentMenuId,
+                                             QMenu*    parentPopup )
+{
+  if ( !module() || parentNode.isNull() )
+    return;
+  
+  QDomElement parentElement = parentNode.toElement();
+  if ( !parentElement.isNull() ) {
+    QString plabel = attribute( parentElement, "label-id" );
+    int     pid    = checkInt( attribute( parentElement, "item-id" ) );
+    int     ppos   = checkInt( attribute( parentElement, "pos-id" ) );
+    int     group  = checkInt( attribute( parentElement, "group-id" ), 
+                               PyModuleHelper::defaultMenuGroup() );
+    if ( !plabel.isEmpty() ) {
+      QMenu* popup = 0;
+      int menuId = -1;
+      // create menu
+      menuId = module()->createMenu( plabel,         // label
+                                     parentMenuId,   // parent menu ID, -1 for top-level menu
+                                     pid,            // ID
+                                     group,          // group ID
+                                     ppos );         // position
+      myMenuItems.append( menuId );
+      QDomNode node = parentNode.firstChild();
+      while ( !node.isNull() ) {
+        if ( node.isElement() ) {
+          QDomElement elem = node.toElement();
+          QString aTagName = tagName( elem );
+          if ( aTagName == "popup-item" ) {
+            int     id      = checkInt( attribute( elem, "item-id" ) );
+            int     pos     = checkInt( attribute( elem, "pos-id" ) );
+            int     group   = checkInt( attribute( elem, "group-id" ), 
+                                        PyModuleHelper::defaultMenuGroup() );
+            QString label   = attribute( elem, "label-id" );
+            QIcon   icon    = loadIcon( attribute( elem, "icon-id" ) );
+            QString tooltip = attribute( elem, "tooltip-id" );
+            QString accel   = attribute( elem, "accel-id" );
+            bool    toggle  = checkBool( attribute( elem, "toggle-id" ) );
+
+            // -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 ) {
+              // create menu action
+              QAction* action = module()->createAction( id,                     // ID
+                                                        tooltip,                // tooltip
+                                                        icon,                   // icon
+                                                        label,                  // menu text
+                                                        tooltip,                // status-bar text
+                                                        QKeySequence( accel ),  // keyboard accelerator
+                                                        module(),               // action owner
+                                                        toggle );               // toogled action
+              myHelper->connectAction( action );
+              module()->createMenu( action,   // action
+                                    menuId,   // parent menu ID
+                                    id,       // ID (same as for createAction())
+                                    group,    // group ID
+                                    pos );    // position
+            }
+          }
+          else if ( aTagName == "submenu" ) {
+            // create sub-menu
+            createMenu( node, menuId, popup );
+          }
+          else if ( aTagName == "separator" ) {
+            // create menu separator
+            int id    = checkInt( attribute( elem, "item-id" ) ); // separator can have ID
+            int pos   = checkInt( attribute( elem, "pos-id" ) );
+            int group = checkInt( attribute( elem, "group-id" ), 
+                                  PyModuleHelper::defaultMenuGroup() );
+            QAction* action = module()->separator();
+            module()->createMenu( action,  // separator action
+                                  menuId,  // parent menu ID
+                                  id,      // ID
+                                  group,   // group ID
+                                  pos );   // position
+          }
+        }
+        node = node.nextSibling();
+      }
+    }
+  }
+}
+
+/*!
+  \brief Create a toolbar and insert actions to it.
+  \param parentNode XML node with toolbar description
+*/
+void PyModuleHelper::XmlHandler::createToolBar( QDomNode& parentNode )
+{
+  if ( !module() || parentNode.isNull() )
+    return;
+
+  QDomElement parentElement = parentNode.toElement();
+  if ( !parentElement.isNull() ) {
+    QString aLabel = attribute( parentElement, "label-id" );
+    QString aName  = attribute( parentElement, "name-id" );
+    if ( !aLabel.isEmpty() ) {
+      // create toolbar
+      int tbId = module()->createTool( aLabel, aName );
+      QDomNode node = parentNode.firstChild();
+      while ( !node.isNull() ) {
+        if ( node.isElement() ) {
+          QDomElement elem = node.toElement();
+          QString aTagName = tagName( elem );
+          if ( aTagName == "toolbutton-item" ) {
+            int     id      = checkInt( attribute( elem, "item-id" ) );
+            int     pos     = checkInt( attribute( elem, "pos-id" ) );
+            QString label   = attribute( elem, "label-id" );
+            QIcon   icon    = loadIcon( attribute( elem, "icon-id" ) );
+            QString tooltip = attribute( elem, "tooltip-id" );
+            QString accel   = attribute( elem, "accel-id" );
+            bool    toggle  = checkBool( attribute( elem, "toggle-id" ) );
+
+            // -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 ) {
+                // create toolbar action
+                QAction* action = module()->createAction( id,                     // ID
+                                                          tooltip,                // tooltip
+                                                          icon,                   // icon
+                                                          label,                  // menu text
+                                                          tooltip,                // status-bar text
+                                                          QKeySequence( accel ),  // keyboard accelerator
+                                                          module(),               // action owner
+                                                          toggle );               // toogled action
+                myHelper->connectAction( action );
+                module()->createTool( action, tbId, -1, pos );
+            }
+          }
+          else if ( aTagName == "separatorTB" || aTagName == "separator" ) {
+            // create toolbar separator
+            int pos = checkInt( attribute( elem, "pos-id" ) );
+            QAction* action = module()->separator();
+            module()->createTool( action, tbId, -1, pos );
+          }
+        }
+        node = node.nextSibling();
+      }
+    }
+  }
+}
+
+/*!
+  \brief Fill popup menu with the items.
+  \param parentNode XML node with popup menu description
+  \param menu popup menu
+*/
+void PyModuleHelper::XmlHandler::insertPopupItems( QDomNode& parentNode, QMenu* menu )
+{
+  if ( !module() && parentNode.isNull() )
+    return;
+
+  // we create popup menus without help of QtxPopupMgr
+  QDomNode node = parentNode.firstChild();
+  while ( !node.isNull() ) { 
+    if ( node.isElement() ) {
+      QDomElement elem = node.toElement();
+      QString aTagName = tagName( elem );
+      QList<QAction*> actions = menu->actions();
+      if ( aTagName == "popup-item" ) {
+        // insert a command item
+        int     id      = checkInt( attribute( elem, "item-id" ) );
+        int     pos     = checkInt( attribute( elem, "pos-id" ) );
+        QString label   = attribute( elem, "label-id" );
+        QIcon   icon    = loadIcon( attribute( elem, "icon-id" ) );
+        QString tooltip = attribute( elem, "tooltip-id" );
+        QString accel   = attribute( elem, "accel-id" );
+        bool    toggle  = checkBool( attribute( elem, "toggle-id" ) );
+
+        // -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 ) {
+          QAction* action = module()->createAction( id,                     // ID
+                                                    tooltip,                // tooltip
+                                                    icon,                   // icon
+                                                    label,                  // menu text
+                                                    tooltip,                // status-bar text
+                                                    QKeySequence( accel ),  // keyboard accelerator
+                                                    module(),               // action owner
+                                                    toggle );               // toogled action
+          myHelper->connectAction( action );
+          QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
+          menu->insertAction( before, action );
+        }
+      }
+      else if ( aTagName == "submenu" ) {
+        // create sub-menu
+        ////int     id    = checkInt( attribute( elem, "item-id" ) ); // not used //
+        int     pos   = checkInt( attribute( elem, "pos-id" ) );
+        QString label = attribute( elem, "label-id" );
+        QString icon  = attribute( elem, "icon-id" );
+
+        QIcon anIcon;
+        if ( !icon.isEmpty() ) {
+          QPixmap pixmap  = module()->getApp()->resourceMgr()->loadPixmap( module()->name(), icon );
+          if ( !pixmap.isNull() )
+            anIcon = QIcon( pixmap );
+        }
+
+        QMenu* newPopup = menu->addMenu( anIcon, label );
+        QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
+        menu->insertMenu( before, newPopup );
+        insertPopupItems( node, newPopup );
+      }
+      else if ( aTagName == "separator" ) {
+        // create menu separator
+        int pos = checkInt( attribute( elem, "pos-id" ) );
+        QAction* action = module()->separator();
+        QAction* before = ( pos >= 0 && pos < actions.count() ) ? actions[ pos ] : 0;
+        menu->insertAction( before, action );
+      }
+    }
+    node = node.nextSibling();
+  }
+}
+
+/*!
+  \class PyModuleHelper
+  \brief This class implements API helper for all the Python-based 
+  SALOME GUI modules.
+*/
+
+PyModuleHelper::InterpMap PyModuleHelper::myInterpMap;
+LightApp_Module*          PyModuleHelper::myInitModule = 0;
+
+/*!
+  \brief Constructor
+  \param module owner module
+*/
+PyModuleHelper::PyModuleHelper( LightApp_Module* module ) :
+  QObject( module ),
+  myModule( module ),
+  myPyModule( 0 ), 
+  myInterp( 0 ),
+  myXmlHandler ( 0 ),
+  myLastActivateStatus( true )
+{
+  setObjectName( "python_module_helper" );
+}
+
+/*!
+  \brief Destructor
+*/
+PyModuleHelper::~PyModuleHelper()
+{
+  delete myXmlHandler;
+  if ( myInterp && myPyModule ) {
+    PyLockWrapper aLock; // Acquire GIL
+    Py_XDECREF( myPyModule );
+  }
+}
+
+/*!
+  \brief Get the module being initialized.
+  
+  This is a little trick :) needed to provide an access from Python
+  (SalomePyQt) to the module being currently activated. The problem
+  that during the process of module initialization (initialize() 
+  function) it is not yet available via application->activeModule()
+  call.
+  
+  This method returns valid pointer only if called in scope of
+  initialize() function or in several other specific cases.
+
+  \return the module being currently initialized
+*/
+LightApp_Module* PyModuleHelper::getInitModule()
+{
+  QMutexLocker ml( &myInitMutex );
+  return myInitModule;
+}
+
+/*!
+  \brief Get default menu group identifier
+  \return menu group ID (40 by default)
+*/
+int PyModuleHelper::defaultMenuGroup()
+{
+  return DEFAULT_GROUP; 
+}
+
+/*!
+  \brief Get owner module
+  \return owner module
+*/
+LightApp_Module* PyModuleHelper::module() const
+{
+  return myModule;
+}
+
+/*!
+  \brief Get Python GUI module object
+  \return python module
+*/
+PyObject* PyModuleHelper::pythonModule() const
+{
+  return myPyModule;
+}
+
+/*!
+  \brief Connect action to the internal actionActivated() slot.
+
+  Actions connected to internal actionActivated(), when activated, will
+  be forwarded to the Python GUI module OnGUIEvent() function.
+
+  \param a action being connected
+*/
+void PyModuleHelper::connectAction( QAction* a )
+{
+  if ( myModule && a )
+    QObject::connect( a, SIGNAL( triggered( bool ) ), 
+                      this, SLOT( actionActivated() ),
+                      Qt::UniqueConnection );
+}
+
+/*!
+  \brief Get the dockable windows associated with the module.
+  
+  To fill the list of windows the correspondind Python module's windows()
+  method is called during the module initialization.
+
+  By default, ObjectBrowser, PythonConsole and LogWindow windows are 
+  associated to the module.
+
+  Allowed dockable windows:
+  - LightApp_Application::WT_ObjectBrowser : object browser
+  - LightApp_Application::WT_PyConsole : python console
+  - LightApp_Application::WT_LogWindow : log messages output window
+
+  Dock area is defined by Qt::DockWidgetArea enumeration:
+  - Qt::TopDockWidgetArea : top dock area
+  - Qt::BottomDockWidgetArea : bottom dock area
+  - Qt::LeftDockWidgetArea : left dock area
+  - Qt::RightDockWidgetArea : right dock area
+
+  \return map of dockable windows in form { <window_type> : <dock_area> }
+*/
+QMap<int, int> PyModuleHelper::windows() const
+{
+  FuncMsg fmsg( "PyModuleHelper::windows()" );
+
+  return myWindowsMap;
+}
+
+/*!
+  \brief Define the compatible view windows associated with the module.
+
+  The associated view windows are opened automatically when the module
+  is activated.
+
+  To fill the list of views the correspondind Python module's views()
+  method is called during the module initialization.
+  By default, the list of view types is empty.
+
+  \return list of view windows types
+*/
+QStringList PyModuleHelper::viewManagers() const
+{
+  FuncMsg fmsg( "PyModuleHelper::viewManagers()" );
+
+  return myViewMgrList;
+}
+
+/*!
+  \brief Initialization of the Python-based SALOME module.
+  
+  This method can be used for creation of the menus, toolbars and 
+  other such stuff.
+  
+  There are two ways to do this:
+  1) for obsolete modules, the implementation of this method first tries to read
+  the <module>_<language>.xml resource file which contains a menu,
+  toolbars and popup menus description;
+  2) new modules can create menus by direct calling of the
+  corresponding methods of SalomePyQt Python API in the Python
+  module's initialize() method which is called from here.
+
+  \note SALOME supports two modes of modules loading:
+  - immediate (all the modules are created and initialized 
+  immediately when the application object is created);
+  - postponed modules loading (used currently); in this mode
+  the module is loaded only by explicit request.
+  If postponed modules loading is not used, the active
+  study might be not yet defined at this stage, so initialize()
+  method should not perform any study-based initialization.
+  Such actions can be better done in activate() function.
+
+  \param app parent application object
+*/
+void PyModuleHelper::initialize( CAM_Application* app )
+{
+  FuncMsg fmsg( "PyModuleHelper::initialize()" );
+
+  // temporarily store module being currently activated
+  // in the global variable to make it accessible from
+  // Python API
+  InitLocker lock( myModule );
+
+  // try to get XML resource file name
+  SUIT_ResourceMgr* resMgr = myModule->getApp()->resourceMgr();
+  if ( !myXmlHandler && resMgr ) {
+    // get current language
+    QString lang = resMgr->stringValue( "language", "language", "en" );
+    // get menu description file name
+    QString aFileName = QString( "%1_%2.xml" ).arg( myModule->name() ).arg( lang );
+    aFileName = resMgr->path( "resources", myModule->name(), aFileName );
+    if ( !aFileName.isEmpty() && QFile::exists( aFileName ) ) {
+      // create XML handler instance
+      myXmlHandler = new XmlHandler( this, aFileName );
+      // ask XML handler to create actions
+      myXmlHandler->createActions();
+    }
+  }
+
+  class InitializeReq : public PyInterp_Request
+  {
+  public:
+    InitializeReq( PyModuleHelper*  _helper,
+                   CAM_Application* _app )
+      : PyInterp_Request( 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ),
+        myApp( _app )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalInitialize( myApp );
+    }
+  private:
+    PyModuleHelper*  myHelper;
+    CAM_Application* myApp;
+  };
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new InitializeReq( this, app ) );
+}
+
+/*!
+  \brief Activation of the module.
+
+  This function is usually used in order to show the module's 
+  specific menus and toolbars, update actions state and perform
+  other such actions required when the module is activated.
+  
+  \note Returning \c false from this function prevents the 
+  module activation.
+
+  \param study parent study
+  \return \c true if activation is successful and \c false otherwise
+*/
+bool PyModuleHelper::activate( SUIT_Study* study )
+{
+  FuncMsg fmsg( "PyModuleHelper::activate()" );
+
+  // reset the activation status to the default value
+  myLastActivateStatus = true;
+
+  class ActivateReq : public PyInterp_Request
+  {
+  public:
+    ActivateReq( PyModuleHelper* _helper,
+                 SUIT_Study*     _study,
+                 bool            _customize )
+  : PyInterp_Request( 0, true ), // this request should be processed synchronously (sync == true)
+    myHelper( _helper ),
+    myStudy ( _study ),
+    myCustomize( _customize )
+  {}
+  protected:
+    virtual void execute()
+      {
+        if ( !myCustomize )
+          myHelper->internalActivate( myStudy );  // first activation stage
+        else
+          myHelper->internalCustomize( myStudy ); // second activation stage
+      }
+  private:
+    PyModuleHelper* myHelper;
+    SUIT_Study*     myStudy;
+    bool            myCustomize;
+  };
+
+  // post request for activation (customize=false)
+  PyInterp_Dispatcher::Get()->Exec( new ActivateReq( this, study, false ) );
+
+  // check activation status (can be set to false by internalActivate())
+  if ( myLastActivateStatus ) {
+    // activate menus, toolbars, etc
+    if ( myXmlHandler ) myXmlHandler->activateMenus( true );
+
+    // show menus / toolbars
+    myModule->setMenuShown( true );
+    myModule->setToolShown( true );
+
+    // post request for customization (customize=true)
+    PyInterp_Dispatcher::Get()->Exec( new ActivateReq( this, study, true ) );
+
+    // check activation status (can be set to false by internalCustomize())
+    if ( myLastActivateStatus ) {
+      // connect preferences changing signal
+      connect( myModule->getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ),
+               this,               SLOT(   preferenceChanged( const QString&, const QString&, const QString& ) ) );
+      
+      // connect active view change signal
+      SUIT_Desktop* d = study->application()->desktop();
+      connect( d,     SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
+               this,  SLOT( activeViewChanged( SUIT_ViewWindow* ) ) );
+      // if active window exists, call activeViewChanged() function;
+      // temporary solution: if a getActiveView() in SalomePyQt available
+      // we no longer need this 
+      SUIT_ViewWindow* view = d->activeWindow();
+      if ( view ) activeViewChanged( view );
+      // get all view currently opened in the study and connect their signals to 
+      // the corresponding slots of the class.
+      foreach ( view, d->windows() ) connectView( view );
+    }
+    else {
+      // hide menus / toolbars in case of error
+      myModule->setMenuShown( false );
+      myModule->setToolShown( false );
+    }
+  }
+
+  return myLastActivateStatus;
+}
+
+/*!
+  \brief Deactivation of the module.
+
+  This function is usually used in order to hide the module's 
+  specific menus and toolbars and perform other such actions
+  required when the module is deactivated.
+
+  \param study parent study
+  \return \c true if deactivation is successful and \c false otherwise
+*/
+bool PyModuleHelper::deactivate( SUIT_Study* study )
+{
+  FuncMsg fmsg( "PyModuleHelper::deactivate()" );
+
+  class DeactivateReq : public PyInterp_LockRequest
+  {
+  public:
+    DeactivateReq( PyInterp_Interp* _py_interp,
+                   PyModuleHelper*  _helper,
+                   SUIT_Study*      _study )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ),
+        myStudy ( _study )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalDeactivate( myStudy );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    SUIT_Study*     myStudy;
+  };
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new DeactivateReq( myInterp, this, study ) );
+
+  // disconnect preferences changing signal
+  disconnect( myModule->getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ),
+              this,               SLOT(   preferenceChanged( const QString&, const QString&, const QString& ) ) );
+  
+  // disconnect the SUIT_Desktop signal windowActivated()
+  SUIT_Desktop* d = study->application()->desktop();
+  disconnect( d,     SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
+              this,  SLOT( activeViewChanged( SUIT_ViewWindow* ) ) );
+
+  // deactivate menus, toolbars, etc
+  if ( myXmlHandler ) myXmlHandler->activateMenus( false );
+
+  // hide menus / toolbars
+  myModule->setMenuShown( false );
+  myModule->setToolShown( false );
+
+  return true;
+}
+
+/*!
+  \brief Close of the module.
+
+  This function is usually used in order to close the module's 
+  specific menus and toolbars and perform other such actions
+  required when the module is closed.
+*/
+void PyModuleHelper::modelClosed( SUIT_Study* study )
+{
+  FuncMsg fmsg( "PyModuleHelper::modelClosed()" );
+
+  class StudyClosedReq : public PyInterp_LockRequest
+  {
+  public:
+    StudyClosedReq( PyInterp_Interp* _py_interp,
+                   PyModuleHelper*  _helper,
+                   SUIT_Study*      _study )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ),
+        myStudy ( _study )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalClosedStudy( myStudy );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    SUIT_Study*     myStudy;
+  };
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new StudyClosedReq( myInterp, this, study ) );
+
+  // disconnect preferences changing signal
+  disconnect( myModule->getApp(), SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ),
+              this,               SLOT(   preferenceChanged( const QString&, const QString&, const QString& ) ) );
+  
+  // disconnect the SUIT_Desktop signal windowActivated()
+  SUIT_Desktop* d = study->application()->desktop();
+  disconnect( d,     SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
+	      this,  SLOT( activeViewChanged( SUIT_ViewWindow* ) ) );
+
+  // deactivate menus, toolbars, etc
+  if ( myXmlHandler ) myXmlHandler->activateMenus( false );
+
+  // hide menus / toolbars
+  myModule->setMenuShown( false );
+  myModule->setToolShown( false );
+}
+
+
+/*!
+  \brief Process module's preferences changing.
+
+  Called when the module's own preferences are changed.
+  
+  \param section preference resources section
+  \param parameter preference resources parameter name
+*/
+void PyModuleHelper::preferencesChanged( const QString& section, 
+                                         const QString& parameter )
+{
+  FuncMsg fmsg( "PyModuleHelper::preferencesChanged()" );
+
+  class PrefChangeReq : public PyInterp_LockRequest
+  {
+  public:
+    PrefChangeReq( PyInterp_Interp* _py_interp,
+                   PyModuleHelper*  _helper,
+                   const QString&   _section,
+                   const QString&   _parameter )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper ( _helper ),
+        mySection( _section ),
+        myParameter( _parameter ) 
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalPreferencesChanged( mySection, myParameter );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    QString         mySection, myParameter;
+  };
+
+  // post the request only if dispatcher is not busy!
+  // execute request synchronously
+  if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+    PyInterp_Dispatcher::Get()->Exec( new PrefChangeReq( myInterp, this, section, parameter ) );
+}
+
+/*!
+  \brief Process application preferences changing.
+
+  Called when any application setting is changed.
+
+  \param module preference module
+  \param section preference resources section
+  \param parameter preference resources parameter name
+*/
+void PyModuleHelper::preferenceChanged( const QString& module, 
+                                        const QString& section,
+                                        const QString& parameter )
+{
+  FuncMsg fmsg( "PyModuleHelper::preferenceChanged()" );
+
+  // module's own preferences are processed by other preferencesChanged() method
+  if ( module != myModule->moduleName() ) {
+    // call helper
+    preferencesChanged( section, parameter );
+  }
+}
+
+/*!
+  \brief Process study activation.
+  
+  Called when study desktop is activated. Used for notifying the Python
+  module about changing of the active study.
+
+  \param study study being activated
+*/
+void PyModuleHelper::studyActivated( SUIT_Study* study )
+{
+  FuncMsg fmsg( "PyModuleHelper::studyActivated()" );
+
+  // StudyChangedReq: request class for internal studyChanged() operation
+  class StudyChangedReq : public PyInterp_Request
+  {
+  public:
+    StudyChangedReq( PyModuleHelper* _helper,
+                     SUIT_Study*     _study )
+      : PyInterp_Request(0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ), 
+        myStudy ( _study )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalStudyChanged( myStudy );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    SUIT_Study*     myStudy;
+  };
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new StudyChangedReq( this, study ) );
+}
+
+/*!
+  \brief Process action activation.
+  
+  Called when action is activated. Used for notifying the Python
+  module about any related action activation.
+
+  \sa connectAction()
+*/
+void PyModuleHelper::actionActivated()
+{
+  FuncMsg fmsg( "PyModuleHelper::actionActivated()" );
+
+  // perform synchronous request to Python event dispatcher
+  class ActionReq : public PyInterp_LockRequest
+  {
+  public:
+    ActionReq( PyInterp_Interp* _py_interp,
+               PyModuleHelper*  _helper,
+               int              _id )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ),
+        myId    ( _id  )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalActionActivated( myId );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    int             myId;
+  };
+
+  // get sender action
+  QAction* action = qobject_cast<QAction*>( sender() );
+  if ( !action )
+    return;
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new ActionReq( myInterp, this, myModule->actionId( action ) ) );
+}
+
+/*!
+  \brief update selection from other views or modules.
+
+  Called when selection is modified outside.
+*/
+void PyModuleHelper::selectionUpdated(const QStringList& entries)
+{
+  FuncMsg fmsg( "PyModuleHelper::selectionUpdated()" );
+  MESSAGE("selectionUpdated");
+
+  // perform synchronous request to Python event dispatcher
+  class SelectionReq : public PyInterp_LockRequest
+  {
+  public:
+    SelectionReq( PyInterp_Interp* _py_interp,
+                  PyModuleHelper*  _helper,
+                  const QStringList& _entries )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ),
+        myEntries( _entries  )
+    {
+      MESSAGE("SelectionReq");
+    }
+  protected:
+    virtual void execute()
+    {
+      MESSAGE("execute");
+      myHelper->internalSelectionUpdated( myEntries );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    const QStringList& myEntries;
+  };
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new SelectionReq( myInterp, this, entries ) );
+}
+
+/*!
+  \brief Process context popup menu request.
+  
+  Called when user activates popup menu in some window
+  (view, object browser, etc).
+
+  \param context popup menu context (e.g. "ObjectBrowser")
+  \param menu popup menu
+*/
+void PyModuleHelper::contextMenu( const QString& context, QMenu* menu )
+{
+  FuncMsg fmsg( "PyModuleHelper::contextMenu()" );
+
+  class ContextMenuReq : public PyInterp_LockRequest
+  {
+  public:
+    ContextMenuReq( PyInterp_Interp* _py_interp,
+                    PyModuleHelper*  _helper,
+                    const QString&   _context,
+                    QMenu*           _menu )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper ( _helper ),
+        myContext( _context ),
+        myMenu   ( _menu )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalContextMenu( myContext, myMenu );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    QString         myContext;
+    QMenu*          myMenu;
+  };
+
+  // post request only if dispatcher is not busy!
+  // execute request synchronously
+  if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+    PyInterp_Dispatcher::Get()->Exec( new ContextMenuReq( myInterp, this, context, menu ) );
+}
+
+/*!
+  \brief Export preferences for the Python module.
+  Called only once when the first instance of the module is created or
+  when common Preferences dialog box is first time invoked.
+*/
+void PyModuleHelper::createPreferences()
+{
+  FuncMsg fmsg( "PyModuleHelper::createPreferences()" );
+
+  // temporary set myInitModule because createPreferences() method
+  // might be called during the module intialization process
+  InitLocker lock( myModule );
+
+  class CreatePrefReq : public PyInterp_LockRequest
+  {
+  public:
+    CreatePrefReq( PyInterp_Interp* _py_interp,
+                   PyModuleHelper*  _helper )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalCreatePreferences();
+    }
+  private:
+    PyModuleHelper* myHelper;
+  };
+
+  // post request only if dispatcher is not busy!
+  // execute request synchronously
+  if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+    PyInterp_Dispatcher::Get()->Exec( new CreatePrefReq( myInterp, this ) );
+}
+
+/*!
+  \brief Signal handler windowActivated(SUIT_ViewWindow*) of SUIT_Desktop
+
+  Used to notify Python module that active view has been changed by the user.
+
+  \param view view being activated
+*/
+void PyModuleHelper::activeViewChanged( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "PyModuleHelper::activeViewChanged()" );
+
+  // perform synchronous request to Python event dispatcher
+  class ActiveViewChangeReq : public PyInterp_LockRequest
+  {
+  public:
+    ActiveViewChangeReq( PyInterp_Interp* _py_interp,
+                         PyModuleHelper*  _helper,
+                         SUIT_ViewWindow* _view )
+      : PyInterp_LockRequest( _py_interp, 0, true ),
+        myHelper( _helper ),
+        myView( _view )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalActiveViewChanged( myView );
+    }
+  private:
+    PyModuleHelper*  myHelper;
+    SUIT_ViewWindow* myView;
+  };
+
+  // connect view (if it is not connected yet)
+  connectView( view );
+  
+  PyInterp_Dispatcher::Get()->Exec( new ActiveViewChangeReq( myInterp, this, view ) ); 
+}
+
+/*!
+  \brief Signal handler tryClose(SUIT_ViewWindow*) of a view
+  \param view view being closed
+*/
+void PyModuleHelper::tryCloseView( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "PyModuleHelper::tryCloseView()" );
+
+  class TryCloseViewReq : public PyInterp_LockRequest
+  {
+  public:
+    TryCloseViewReq( PyInterp_Interp* _py_interp,
+                     PyModuleHelper*  _helper,
+                     SUIT_ViewWindow* _view )
+      : PyInterp_LockRequest( _py_interp, 0, true ),
+        myHelper( _helper ), 
+        myView( _view )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalTryCloseView( myView );
+    }
+  private:
+    PyModuleHelper*  myHelper;
+    SUIT_ViewWindow* myView;    
+  };
+
+  PyInterp_Dispatcher::Get()->Exec( new TryCloseViewReq( myInterp, this, view ) );
+}
+
+/*!
+  \brief Signal handler closing(SUIT_ViewWindow*) of a view
+  \param view view being closed
+*/
+void PyModuleHelper::closeView( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "PyModuleHelper::closeView()" );
+
+  class CloseViewReq : public PyInterp_LockRequest
+  {
+  public:
+    CloseViewReq( PyInterp_Interp* _py_interp,
+                  PyModuleHelper*  _helper,
+                  SUIT_ViewWindow* _view )
+      : PyInterp_LockRequest( _py_interp, 0, true ),
+        myHelper( _helper ),
+	myView( _view )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalCloseView( myView );
+    }
+  private:
+    PyModuleHelper*  myHelper;
+    SUIT_ViewWindow* myView;    
+  };
+
+  PyInterp_Dispatcher::Get()->Exec( new CloseViewReq( myInterp, this, view ) );
+}
+
+/*!
+  \brief Signal handler cloneView() of OCCViewer_ViewWindow
+  \param view view being cloned
+*/
+void PyModuleHelper::cloneView( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "PyModuleHelper::cloneView()" );
+
+  class CloneViewReq : public PyInterp_LockRequest
+  {
+  public:
+    CloneViewReq( PyInterp_Interp* _py_interp,
+                  PyModuleHelper*  _helper,
+                  SUIT_ViewWindow* _view )
+      : PyInterp_LockRequest( _py_interp, 0, true ),
+        myHelper( _helper ),
+        myView( _view )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalCloneView( myView );
+    }
+  private:
+    PyModuleHelper*  myHelper;
+    SUIT_ViewWindow* myView;
+  };
+  
+  PyInterp_Dispatcher::Get()->Exec( new CloneViewReq( myInterp, this, view ) );
+}
+
+/*!
+  \brief Save module data. Called when user saves study.
+  \param files output list of files where module stores data
+  \param url study URL
+*/
+void PyModuleHelper::save( QStringList& files, const QString& url )
+{
+  FuncMsg fmsg( "PyModuleHelper::save()" );
+
+  // temporary set myInitModule because save() method
+  // might be called by the framework when this module is inactive,
+  // but still it should be possible to access this module's data
+  // from Python
+  InitLocker lock( myModule );
+
+  // perform synchronous request to Python event dispatcher
+  class SaveReq: public PyInterp_LockRequest
+  {
+  public:     
+    SaveReq( PyInterp_Interp* _py_interp,
+             PyModuleHelper*  _helper,
+             QStringList&     _files,
+             const QString&   _url )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ) ,
+        myFiles( _files ),
+        myUrl( _url )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalSave( myFiles, myUrl );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    QStringList&    myFiles;
+    QString         myUrl;
+  };
+  
+  // Posting the request only if dispatcher is not busy!
+  // Executing the request synchronously
+  if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+    PyInterp_Dispatcher::Get()->Exec( new SaveReq( myInterp, this, files, url ) );
+}
+
+/*
+  \brief Load module data. Called when user opens study 
+  and activates module.
+  \param files list of files where module data is stored
+  \param url study URL
+  \return \c true if loading has been finished successfully or \c false otherwise
+*/
+bool PyModuleHelper::load( const QStringList& files, const QString& url )
+{
+  FuncMsg fmsg( "PyModuleHelper::load()" );
+
+  bool loaded = false;
+
+  class LoadReq: public PyInterp_LockRequest
+  {
+  public:
+    LoadReq( PyInterp_Interp* _py_interp,
+             PyModuleHelper*  _helper,
+             QStringList      _files,
+             const QString&   _url,
+             bool&            _loaded )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ) ,
+        myFiles( _files ),
+        myUrl( _url ),
+        myLoaded( _loaded )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalLoad( myFiles, myUrl, myLoaded );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    QStringList     myFiles;
+    QString         myUrl;
+    bool&           myLoaded;
+  };
+  
+  // Posting the request only if dispatcher is not busy!
+  // Executing the request synchronously
+  if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+    PyInterp_Dispatcher::Get()->Exec( new LoadReq( myInterp, this, files, url, loaded ) );
+
+  return loaded;
+}
+
+/*!
+  \brief Dump module data to the Python script. 
+  Called when user activates dump study operation.
+  \param files output list of files where module stores python script
+*/
+void PyModuleHelper::dumpPython( QStringList& files )
+{
+  FuncMsg fmsg( "PyModuleHelper::dumpPython()" );
+
+  // temporary set myInitModule because dumpPython() method
+  // might be called by the framework when this module is inactive,
+  // but still it should be possible to access this module's data
+  // from Python
+  InitLocker lock( myModule );
+
+  class DumpPythonReq: public PyInterp_LockRequest
+  {
+  public:     
+    DumpPythonReq( PyInterp_Interp* _py_interp,
+                   PyModuleHelper*  _helper,
+                   QStringList&     _files )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ) ,
+        myFiles( _files )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalDumpPython( myFiles );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    QStringList&    myFiles;
+  };
+  
+  // Posting the request only if dispatcher is not busy!
+  // Executing the request synchronously
+  if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+    PyInterp_Dispatcher::Get()->Exec( new DumpPythonReq( myInterp, this, files ) );
+}
+
+/*!
+  \brief Test if object \a what can be dragged by the user.
+  \param what data object being tested
+  \return \c true if object can be dragged or \c false otherwise
+*/
+bool PyModuleHelper::isDraggable( const SUIT_DataObject* what ) const
+{
+  FuncMsg fmsg( "PyModuleHelper::isDraggable()" );
+
+  bool draggable = false;
+
+  // perform synchronous request to Python event dispatcher
+  class IsDraggableReq: public PyInterp_LockRequest
+  {
+  public:
+    IsDraggableReq( PyInterp_Interp*     _py_interp,
+                    PyModuleHelper*      _helper,
+                    LightApp_DataObject* _data_object,
+                    bool&                _is_draggable )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ) ,
+        myDataObject( _data_object ),
+        myIsDraggable( _is_draggable )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myIsDraggable = myHelper->internalIsDraggable( myDataObject );
+    }
+  private:
+    PyModuleHelper*      myHelper;
+    LightApp_DataObject* myDataObject;
+    bool&                myIsDraggable;
+  };
+
+  const LightApp_DataObject* data_object = dynamic_cast<const LightApp_DataObject*>( what );
+  if ( data_object ) {
+    // Posting the request only if dispatcher is not busy!
+    // Executing the request synchronously
+    if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+      PyInterp_Dispatcher::Get()->Exec( new IsDraggableReq( myInterp,
+                                        const_cast<PyModuleHelper*>( this ),
+                                        const_cast<LightApp_DataObject*>( data_object ),
+                                        draggable ) );
+  }
+  
+  return draggable;
+}
+
+/*!
+  \brief Test if drop operation can be done on the \a where object.
+  \param where data object being tested
+  \return \c true if if drop operation is supported by object or \c false otherwise
+*/
+bool PyModuleHelper::isDropAccepted( const SUIT_DataObject* where ) const
+{
+  FuncMsg fmsg( "PyModuleHelper::isDropAccepted()" );
+
+  bool dropAccepted = false;
+
+  // perform synchronous request to Python event dispatcher
+  class IsDropAcceptedReq: public PyInterp_LockRequest
+  {
+  public:
+    IsDropAcceptedReq( PyInterp_Interp*     _py_interp,
+                       PyModuleHelper*      _helper,
+                       LightApp_DataObject* _data_object,
+                       bool&                _is_drop_accepted )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ) ,
+        myDataObject( _data_object ),
+        myIsDropAccepted( _is_drop_accepted )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myIsDropAccepted = myHelper->internalIsDropAccepted( myDataObject );
+    }
+  private:
+    PyModuleHelper*      myHelper;
+    LightApp_DataObject* myDataObject;
+    bool&                myIsDropAccepted;
+  };
+  
+  const LightApp_DataObject* data_object = dynamic_cast<const LightApp_DataObject*>( where );
+  if ( data_object ) {
+    // Posting the request only if dispatcher is not busy!
+    // Executing the request synchronously
+    if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+      PyInterp_Dispatcher::Get()->Exec( new IsDropAcceptedReq( myInterp,
+                                         const_cast<PyModuleHelper*>( this ),
+                                         const_cast<LightApp_DataObject*>( data_object ),
+                                         dropAccepted ) );
+  }
+
+  return dropAccepted;
+}
+
+/*!
+  \brief Perform drop operation
+  \param what list of data objects being dropped
+  \param where target data object for drop operation
+  \param row line (child item index) where drop operation is performed to
+  \param action current drop action (copy or move)
+*/
+void PyModuleHelper::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
+                                  const int row, Qt::DropAction action )
+{
+  FuncMsg fmsg( "PyModuleHelper::dropObjects()" );
+
+  // perform synchronous request to Python event dispatcher
+  class DropObjectsReq: public PyInterp_LockRequest
+  {
+  public:
+    DropObjectsReq( PyInterp_Interp*      _py_interp,
+                    PyModuleHelper*       _helper,
+                    const DataObjectList& _what,
+                    SUIT_DataObject*      _where,
+                    const int             _row,
+                    Qt::DropAction        _action )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ) ,
+        myWhat( _what ),
+        myWhere( _where ),
+        myRow( _row ),
+        myAction ( _action )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalDropObjects( myWhat, myWhere, myRow, myAction );
+    }
+  private:
+    PyModuleHelper*  myHelper;
+    DataObjectList   myWhat;
+    SUIT_DataObject* myWhere;
+    int              myRow;
+    Qt::DropAction   myAction;
+  };
+  
+  // Posting the request only if dispatcher is not busy!
+  // Executing the request synchronously
+  if ( !PyInterp_Dispatcher::Get()->IsBusy() )
+    PyInterp_Dispatcher::Get()->Exec( new DropObjectsReq( myInterp, this, what, where, row, action ) );
+}
+
+/*!
+  \brief Get module engine IOR
+  \return engine IOR as it is supplied by GUI Python module
+ */
+QString PyModuleHelper::engineIOR() const
+{
+  FuncMsg fmsg( "PyModuleHelper::engineIOR()" );
+
+  class EngineIORReq : public PyInterp_LockRequest
+  {
+  public:
+    EngineIORReq( PyInterp_Interp* _py_interp,
+                  PyModuleHelper*  _helper,
+                  QString&         _ior )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ),
+        myIOR( _ior )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myIOR = myHelper->internalEngineIOR();
+    }
+  private:
+    PyModuleHelper* myHelper;
+    QString&        myIOR;
+  };
+
+  static QString anIOR;
+
+  if ( anIOR.isEmpty() ) {
+    // post request
+    PyInterp_Dispatcher::Get()->Exec( new EngineIORReq( myInterp, 
+                                      const_cast<PyModuleHelper*>( this ),
+                                      anIOR ) );
+  }
+
+  return anIOR;
+}
+
+/*!
+  \brief Initialize python subinterpreter (one per study).
+  \internal
+  \param studyId study ID
+*/
+void PyModuleHelper::initInterp( int studyId )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::initInterp()" );
+
+  // check study Id
+  if ( !studyId ) {
+    // Error! Study Id must not be 0!
+    myInterp = 0;
+    return;
+  }
+
+  QMutexLocker ml( &myInitMutex );
+
+  // try to find the subinterpreter
+  if ( myInterpMap.contains( studyId ) ) {
+    // found!
+    myInterp = myInterpMap[ studyId ];
+    return;
+  }
+
+  myInterp = new SALOME_PYQT_PyInterp();
+  myInterp->initialize();
+  myInterpMap[ studyId ] = myInterp;
+  
+#ifndef GUI_DISABLE_CORBA
+  if ( !SUIT_PYTHON::initialized ) {
+    // import 'salome' module and call 'salome_init' method;
+    // do it only once on interpreter creation
+    // ... first get python lock
+    PyLockWrapper aLock; // Acquire GIL
+    // ... then import a module
+    PyObjWrapper aMod = PyImport_ImportModule( "salome" );
+    if ( !aMod ) {
+      // Error!
+      PyErr_Print();
+      return;
+    }
+    // ... then call a method
+    int embedded = 1;
+    PyObjWrapper aRes( PyObject_CallMethod( aMod, (char*)"salome_init", (char*)"ii", studyId, embedded ) );
+    if ( !aRes ) {
+      // Error!
+      PyErr_Print();
+      return;
+    }
+  }
+#endif 
+}
+
+/*!
+  \brief Import Python GUI module and store reference to the module.
+  \internal
+
+  Warning! initInterp() should be called first!!!
+*/
+void PyModuleHelper::importModule()
+{
+  FuncMsg fmsg( "--- PyModuleHelper::importModule()" );
+
+  // check if the subinterpreter is initialized
+  if ( !myInterp ) {
+    // Error! Python subinterpreter should be initialized first!
+    myPyModule = 0;
+    return;
+  }
+
+  // import Python GUI module and put it in <myPyModule> attribute
+  // ... first get python lock
+  PyLockWrapper aLock; // Acquire GIL
+  // ... then import a module
+  QString aMod = QString( "%1GUI" ).arg( myModule->name() );
+  try {
+    myPyModule = PyImport_ImportModule( aMod.toLatin1().data() );
+  }
+  catch (...) {
+  }
+
+  if ( !myPyModule ) {
+    // Error!
+    PyErr_Print();
+    return;
+  }
+}
+
+/*!
+  \brief Set study workspace to the Python module.
+  \internal
+
+  Calls setWorkSpace() method of the Python module with 
+  PyQt QWidget object to use with interpreter.
+
+  Attention! initInterp() and importModule() should be called first!!!
+*/
+void PyModuleHelper::setWorkSpace()
+{
+  FuncMsg fmsg( "--- PyModuleHelper::setWorkSpace()" );
+
+  if ( !IsCallOldMethods ) 
+    return;
+
+  // check if the subinterpreter is initialized and Python module is imported
+  if ( !myInterp || !myPyModule ) {
+    // Error! Python subinterpreter should be initialized and module should be imported first!
+    return;
+  }
+
+  // call setWorkSpace() method
+  // ... first get python lock
+  PyLockWrapper aLock; // Acquire GIL
+
+  // ... then try to import SalomePyQt module. If it's not possible don't go on.
+  PyObjWrapper aQtModule( PyImport_ImportModule( "SalomePyQt" ) );
+  if( !aQtModule ) {
+    // Error!
+    PyErr_Print();
+    return;
+  }
+
+  // ... then get workspace object
+  QWidget* aWorkspace = 0;
+  if ( myModule->getApp()->desktop()->inherits( "STD_MDIDesktop" ) ) {
+    STD_MDIDesktop* d = dynamic_cast<STD_MDIDesktop*>( myModule->getApp()->desktop() );
+    if ( d )
+      aWorkspace = d->workspace();
+  }
+  else if ( myModule->getApp()->desktop()->inherits( "STD_TabDesktop" ) ) {
+    STD_TabDesktop* d = dynamic_cast<STD_TabDesktop*>( myModule->getApp()->desktop() );
+    if ( d )
+      aWorkspace = d->workstack();
+  }
+#if SIP_VERSION < 0x040800
+  PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget) );
+#else
+  PyObjWrapper pyws( sipBuildResult( 0, "D", aWorkspace, sipType_QWidget , NULL) );
+#endif
+  // ... and finally call Python module's setWorkSpace() method (obsolete)
+  if ( PyObject_HasAttrString( myPyModule, (char*)"setWorkSpace" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"setWorkSpace", (char*)"O", pyws.get() ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief Initialization callback function
+  \internal
+
+  Performs the following actions:
+  - initialize or get the Python interpreter (one per study)
+  - import the Python module
+  - pass the workspace widget to the Python module
+  - call Python module's initialize() method
+  - call Python module's windows() method
+  - call Python module's views() method
+
+  \param app parent application object
+*/
+void PyModuleHelper::internalInitialize( CAM_Application* app )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalInitialize()" );
+
+  // reset interpreter to NULL
+  myInterp = 0;
+
+  // get study Id
+  LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( app );
+  if ( !anApp )
+    return;
+  LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( app->activeStudy() );
+  if ( !aStudy )
+    return;
+  int aStudyId = aStudy ? aStudy->id() : 0;
+
+  // initialize Python subinterpreter (on per study) and put it in <myInterp> variable
+  initInterp( aStudyId );
+  if ( !myInterp )
+    return; // Error
+
+  // import Python GUI module
+  importModule();
+  if ( !myPyModule )
+    return; // Error
+
+  // then call Python module's initialize() method
+  // ... first get python lock
+  PyLockWrapper aLock; // Acquire GIL
+
+  // ... (the Python module is already imported)
+  // ... finally call Python module's initialize() method
+  if ( PyObject_HasAttrString( myPyModule, (char*)"initialize" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"initialize", (char*)"" ) );
+    if ( !res ) {
+      PyErr_Print();
+    }
+  }
+
+  // get required dockable windows list from the Python module 
+  // by calling windows() method
+  // ... first put default values
+  myWindowsMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
+  myWindowsMap.insert( LightApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
+  myWindowsMap.insert( LightApp_Application::WT_LogWindow,     Qt::BottomDockWidgetArea );
+
+  if ( PyObject_HasAttrString( myPyModule , (char*)"windows" ) ) {
+    PyObjWrapper res1( PyObject_CallMethod( myPyModule, (char*)"windows", (char*)"" ) );
+    if ( !res1 ) {
+      PyErr_Print();
+    }
+    else {
+      myWindowsMap.clear();
+      if ( PyDict_Check( res1 ) ) {
+        PyObject* key;
+        PyObject* value;
+        Py_ssize_t pos = 0;
+        while ( PyDict_Next( res1, &pos, &key, &value ) ) {
+          // parse the return value
+          // it should be a map: {integer:integer}
+          int aKey, aValue;
+          if( key && PyInt_Check( key ) && value && PyInt_Check( value ) ) {
+            aKey   = PyInt_AsLong( key );
+            aValue = PyInt_AsLong( value );
+            myWindowsMap[ aKey ] = aValue;
+          }
+        }
+      }
+    }
+  }
+
+  // get compatible view windows types from the Python module 
+  // by calling views() method
+  if ( PyObject_HasAttrString( myPyModule , (char*)"views" ) ) {
+    PyObjWrapper res2( PyObject_CallMethod( myPyModule, (char*)"views", (char*)"" ) );
+    if ( !res2 ) {
+      PyErr_Print();
+    }
+    else {
+      // parse the return value
+      // result can be one string...
+      if ( PyString_Check( res2 ) ) {
+        myViewMgrList.append( PyString_AsString( res2 ) );
+      }
+      // ... or list of strings
+      else if ( PyList_Check( res2 ) ) {
+        int size = PyList_Size( res2 );
+        for ( int i = 0; i < size; i++ ) {
+          PyObject* value = PyList_GetItem( res2, i );
+          if( value && PyString_Check( value ) ) {
+            myViewMgrList.append( PyString_AsString( value ) );
+          }
+        }
+      }
+    }
+  }
+}
+
+/*!
+  \brief Activation callback function
+  \internal
+
+  Performs the following actions:
+  - initialize or get the Python interpreter (one per study)
+  - import the Python GUI module
+  - call Python module's activate() method
+
+  \param study parent study
+*/
+void PyModuleHelper::internalActivate( SUIT_Study* study )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalActivate()" );
+
+  // get study Id
+  LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( study );
+  int aStudyId = aStudy ? aStudy->id() : 0;
+
+  // initialize Python subinterpreter (on per study) and put it in <myInterp> variable
+  initInterp( aStudyId );
+  if ( !myInterp ) {
+    myLastActivateStatus = false;
+    return; // Error
+  }
+
+  // import Python GUI module
+  importModule();
+  if ( !myPyModule ) {
+    myLastActivateStatus = false;
+    return; // Error
+  }
+
+  // get python lock
+  PyLockWrapper aLock; // Acquire GIL
+
+  // call Python module's activate() method (for the new modules)
+  if ( PyObject_HasAttrString( myPyModule , (char*)"activate" ) ) {
+    PyObject* res1 = PyObject_CallMethod( myPyModule, (char*)"activate", (char*)"" );
+    if ( !res1 || !PyBool_Check( res1 ) ) {
+      PyErr_Print();
+      // always true for old modules (no return value)
+      myLastActivateStatus = true;
+    }
+    else {
+      // detect return status
+      myLastActivateStatus = PyObject_IsTrue( res1 );
+    }
+  } 
+}
+
+/*!
+  \brief Additional menu customization callback function
+  \internal
+
+  Performs the following actions:
+  - get the Python interpreter (one per study)
+  - import the Python GUI module
+  - call Python module's setSettings() method (obsolete function, 
+  used for compatibility with old code)
+
+  \param study parent study
+*/
+void PyModuleHelper::internalCustomize( SUIT_Study* study )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalCustomize()" );
+
+  // get study Id
+  LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( study );
+  int aStudyId = aStudy ? aStudy->id() : 0;
+
+  // initialize Python subinterpreter (on per study) and put it in <myInterp> variable
+  initInterp( aStudyId );
+  if ( !myInterp ) {
+    myLastActivateStatus = false;
+    return; // Error
+  }
+
+  // import Python GUI module
+  importModule();
+  if ( !myPyModule ) {
+    myLastActivateStatus = false;
+    return; // Error
+  }
+
+  // call Python module's setWorkSpace() method (obsolete)
+  setWorkSpace();
+
+  // get python lock
+  PyLockWrapper aLock; // Acquire GIL
+
+  if ( IsCallOldMethods ) {
+    // call Python module's setSettings() method (obsolete)
+    if ( PyObject_HasAttrString( myPyModule , (char*)"setSettings" ) ) {
+      PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"setSettings", (char*)"" ) );
+      if( !res ) {
+        PyErr_Print();
+      }
+      myLastActivateStatus = myLastActivateStatus && true;
+    }
+  }
+}
+
+/*!
+  \brief Deactivation callback function
+  \internal
+
+  Performs the following actions:
+  - call Python module's deactivate() method
+
+  \param study parent study
+*/
+void PyModuleHelper::internalDeactivate( SUIT_Study* study )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalDeactivate()" );
+
+  // check that Python subinterpreter is initialized and Python module is imported
+  if ( !myInterp || !myPyModule ) {
+    // Error! Python subinterpreter should be initialized and module should be imported first!
+    return;
+  }
+  // then call Python module's deactivate() method
+  if ( PyObject_HasAttrString( myPyModule , (char*)"deactivate" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"deactivate", (char*)"" ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief Internal closure:
+
+  Performs the following actions:
+  - call Python module's closeStudy() method
+
+  \param theStudy parent study object
+*/
+void PyModuleHelper::internalClosedStudy( SUIT_Study* theStudy )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalClosedStudy()" );
+
+  // Get study Id
+  // get study Id
+  LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( theStudy );
+  int aStudyId = aStudy ? aStudy->id() : 0;
+
+  // check that Python subinterpreter is initialized and Python module is imported
+  if ( !myInterp || !myPyModule ) {
+    // Error! Python subinterpreter should be initialized and module should be imported first!
+    return;
+  }
+  // then call Python module's deactivate() method
+  if ( PyObject_HasAttrString( myPyModule , (char*)"closeStudy" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"closeStudy", (char*)"i", aStudyId ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+
+
+/*!
+  \brief Preference changing callback function.
+  \internal
+
+  Performs the following actions:
+  - call Python module's preferenceChanged() method
+
+  \param section resources section name
+  \param setting resources parameter name
+*/
+void PyModuleHelper::internalPreferencesChanged( const QString& section, const QString& setting )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalPreferencesChanged()" );
+
+  // check that Python subinterpreter is initialized and Python module is imported
+  if ( !myInterp || !myPyModule ) {
+    // Error! Python subinterpreter should be initialized and module should be imported first!
+    return;
+  }
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"preferenceChanged" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule,
+                                           (char*)"preferenceChanged", 
+                                           (char*)"ss", 
+                                           section.toLatin1().constData(), 
+                                           setting.toLatin1().constData() ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief Active study change callback function.
+  \internal
+
+  Called when active the study is actived (user brings its 
+  desktop to top):
+  - initialize or get the Python interpreter (one per study)
+  - import the Python GUI module
+  - call Python module's activeStudyChanged() method
+
+  \param study study being activated
+*/
+void PyModuleHelper::internalStudyChanged( SUIT_Study* study )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalStudyChanged()" );
+
+  // get study Id
+  LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( study );
+  int id = aStudy ? aStudy->id() : 0;
+
+  fmsg.message( QString( "study id = %1" ).arg( id ) );
+
+  // initialize Python subinterpreter (on per study) and put it in <myInterp> variable
+  initInterp( id );
+  if ( !myInterp )
+    return; // Error
+
+  // import Python GUI module
+  importModule();
+  if ( !myPyModule )
+    return; // Error
+
+  // call Python module's setWorkSpace() method
+  setWorkSpace();
+
+  // get python lock
+  PyLockWrapper aLock; // Acquire GIL
+
+  // call Python module's activeStudyChanged() method
+  if ( PyObject_HasAttrString( myPyModule, (char*)"activeStudyChanged" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"activeStudyChanged", (char*)"i", id ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief GUI event handling callback function
+  \internal 
+
+  Performs the following actions:
+  - calls Python module's OnGUIEvent() method
+
+  \param id GUI action ID
+*/
+void PyModuleHelper::internalActionActivated( int id )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalActionActivated()" );
+  fmsg.message( QString( "action id = %1" ).arg( id ) );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule )
+    return; // Error
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"OnGUIEvent" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"OnGUIEvent", (char*)"i", id ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief update selection from other views or modules
+  \internal
+
+  Performs the following actions:
+  - calls Python module's onSelectionpdated(entries) method
+
+  \param list of entries
+*/
+void PyModuleHelper::internalSelectionUpdated(const QStringList& entries)
+{
+  FuncMsg fmsg("--- PyModuleHelper::internalSelectionUpdated()");
+  MESSAGE("internalSelectionUpdated");
+
+  // Python interpreter should be initialized and Python module should be imported first
+  if (!myInterp || !myPyModule)
+    return; // Error
+
+  QStringList* theList = new QStringList(entries);
+
+#if SIP_VERSION < 0x040800
+  PyObjWrapper sipList(sipBuildResult(0, "M", theList, sipClass_QStringList));
+#else
+  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
+#endif
+  if (PyObject_HasAttrString(myPyModule, (char*) "onSelectionUpdated"))
+    {
+      MESSAGE("call onSelectionUpdated");
+      PyObjWrapper res(PyObject_CallMethod(myPyModule, (char*) "onSelectionUpdated", (char*) "O", sipList.get()));
+
+      if (!res)
+        {
+          PyErr_Print();
+        }
+    }
+}
+
+/*!
+  \brief Context popup menu handling callback function
+  \internal
+
+  Performs the following actions:
+  - calls Python module's definePopup(...) method (obsolete function, 
+  used for compatibility with old code) to define the popup menu context
+  - parses XML resourses file (if exists) and fills the popup menu with the items)
+  - calls Python module's customPopup(...) method (obsolete function, 
+  used for compatibility with old code) to allow module to customize the popup menu
+  - for new modules calls createPopupMenu() function to allow the 
+  modules to build the popup menu by using insertItem(...) Qt functions.
+
+  \param context popup menu context
+  \param menu popup menu
+*/
+void PyModuleHelper::internalContextMenu( const QString& context, QMenu* menu )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalContextMenu()" );
+  fmsg.message( QString( "context: %1" ).arg( context ) );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule )
+    return; // Error
+
+  QString aContext( "" ), aObject( "" ), aParent( context );
+
+  if ( IsCallOldMethods && PyObject_HasAttrString( myPyModule, (char*)"definePopup" ) ) {
+    // call definePopup() Python module's function
+    // this is obsolete function, used only for compatibility reasons
+    PyObjWrapper res( PyObject_CallMethod( myPyModule,
+                                           (char*)"definePopup",
+                                           (char*)"sss",
+                                           context.toLatin1().constData(),
+                                           aObject.toLatin1().constData(),
+                                           aParent.toLatin1().constData() ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+    else {
+      // parse return value
+      char *co, *ob, *pa;
+      if( PyArg_ParseTuple( res, "sss", &co, &ob, &pa ) ) {
+        aContext = co;
+        aObject  = ob;
+        aParent  = pa;
+      }
+    }
+  } // if ( IsCallOldMethods ... )
+
+  // first try to create menu via XML parser:
+  // we create popup menus without help of QtxPopupMgr
+  if ( myXmlHandler )
+    myXmlHandler->createPopup( menu, aContext, aParent, aObject );
+
+#if SIP_VERSION < 0x040800
+  PyObjWrapper sipPopup( sipBuildResult( 0, "M", menu, sipClass_QMenu ) );
+#else
+  PyObjWrapper sipPopup( sipBuildResult( 0, "D", menu, sipType_QMenu, NULL ) );
+#endif
+
+  // then call Python module's createPopupMenu() method (for new modules)
+  if ( PyObject_HasAttrString( myPyModule, (char*)"createPopupMenu" ) ) {
+    PyObjWrapper res1( PyObject_CallMethod( myPyModule,
+                                            (char*)"createPopupMenu",
+                                            (char*)"Os",
+                                            sipPopup.get(),
+                                            context.toLatin1().constData() ) );
+    if( !res1 ) {
+      PyErr_Print();
+    }
+  }
+
+  if ( IsCallOldMethods && PyObject_HasAttrString( myPyModule, (char*)"customPopup" ) ) {
+    // call customPopup() Python module's function
+    // this is obsolete function, used only for compatibility reasons
+    PyObjWrapper res2( PyObject_CallMethod( myPyModule,
+                                            (char*)"customPopup",
+                                            (char*)"Osss",
+                                            sipPopup.get(),
+                                            aContext.toLatin1().constData(),
+                                            aObject.toLatin1().constData(),
+                                            aParent.toLatin1().constData() ) );
+    if( !res2 ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief Preferences initialization callback function.
+  \internal
+
+  Performs the following actions:
+  - calls Python module's createPreferences() method
+*/
+void PyModuleHelper::internalCreatePreferences()
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalCreatePreferences()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule )
+    return; // Error
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"createPreferences" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"createPreferences", (char*)"" ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief Active view changing callback function
+  \internal
+  \param view view being activated
+*/
+void PyModuleHelper::internalActiveViewChanged( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalActiveViewChanged()" );
+
+  if ( !myInterp || !myPyModule || !view ) 
+    return;
+  
+  fmsg.message( QString( "view id: %1" ).arg( view->getId() ) );
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"activeViewChanged" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"activeViewChanged", (char*)"i" , view->getId() ) );
+    if ( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief View closing callback function
+  \internal
+  \param view view user tries to close
+*/
+void PyModuleHelper::internalTryCloseView( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalTryCloseView()" );
+
+  if ( !myInterp || !myPyModule || !view ) 
+    return;  
+
+  fmsg.message( QString( "view id: %1" ).arg( view->getId() ) );
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"viewTryClose" ) ) 
+  {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"viewTryClose", (char*)"i", view->getId() ) );
+    if ( !res )
+    {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief View closing callback function
+  \internal
+  \param view view being closed
+*/
+void PyModuleHelper::internalCloseView( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalCloseView()" );
+
+  if ( !myInterp || !myPyModule || !view ) 
+    return;  
+
+  fmsg.message( QString( "view id: %1" ).arg( view->getId() ) );
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"viewClosed" ) ) 
+  {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"viewClosed", (char*)"i", view->getId() ) );
+    if ( !res )
+    {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief View cloning callback function
+  \internal
+  \param view view being cloned
+*/
+void PyModuleHelper::internalCloneView( SUIT_ViewWindow* view )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalCloneView()" );
+
+  if ( !myInterp || !myPyModule || !view ) 
+    return;  
+
+  fmsg.message( QString( "view id: %1" ).arg( view->getId() ) );
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"viewCloned" ) ) 
+  {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"viewCloned", (char*)"i", view->getId() ) );
+    if( !res )
+      PyErr_Print();
+  }
+}
+
+/*!
+  \brief Module data saving callback function.
+  \internal
+  \param files output list of files where module stores data
+  \param url study URL
+*/
+void PyModuleHelper::internalSave( QStringList& files, const QString& url )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalSave()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import firs
+  // files list should contain a path to the temporary directory as a first entry
+  if ( !myInterp || !myPyModule || files.isEmpty() )
+    return;
+
+  if ( PyObject_HasAttrString(myPyModule, (char*)"saveFiles") ) {
+
+    // try with two parameters (new syntax)
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"saveFiles",
+                                           (char*)"ss",
+                                           files.first().toLatin1().constData(),
+                                           url.toLatin1().constData() ) );
+    if ( !res )
+      // try with single parameter (old syntax)
+      res = PyObject_CallMethod( myPyModule, (char*)"saveFiles",
+                                 (char*)"s", files.first().toLatin1().constData() );
+    
+    if ( !res ) {
+      PyErr_Print();
+    }
+    else {
+      // parse the return value
+      // result can be one string...
+      if ( PyString_Check( res ) ) {
+        QString astr = PyString_AsString( res );
+        files.append( astr );
+      }
+      //also result can be a list...
+      else if ( PyList_Check( res ) ) {
+        int size = PyList_Size( res );
+        for ( int i = 0; i < size; i++ ) {
+          PyObject* value = PyList_GetItem( res, i );
+          if ( value && PyString_Check( value ) ) {
+            files.append( PyString_AsString( value ) );
+          }
+        }
+      }
+    }
+  }
+}
+
+/*!
+  \brief Module data loading callback function.
+  \internal
+  \param files list of files where module data is stored
+  \param url study URL
+  \param opened output success flag
+*/
+void PyModuleHelper::internalLoad( const QStringList& files, const QString& url, bool& opened )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalLoad()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule || files.isEmpty() )
+    return;
+
+  QStringList* theList = new QStringList( files );
+
+#if SIP_VERSION < 0x040800
+  PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList ) );
+#else
+  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
+#endif
+  if ( PyObject_HasAttrString(myPyModule , (char*)"openFiles") ) {
+
+    // try with two parameters (new syntax)
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"openFiles",
+                                           (char*)"Os", sipList.get(),
+                                           url.toLatin1().constData() ) );
+
+    if ( !res )
+      // try with single parameter (old syntax)
+      res = PyObject_CallMethod( myPyModule, (char*)"openFiles",
+                                 (char*)"O", sipList.get() );
+
+    if ( !res || !PyBool_Check( res ) ) {
+      PyErr_Print();
+      opened = false;
+    }
+    else {
+      opened = PyObject_IsTrue( res );
+    }
+  }
+}
+
+/*!
+  \brief Module dump python callback function.
+  \internal
+  \param files output list of files where module stores python script
+*/
+void PyModuleHelper::internalDumpPython( QStringList& files )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalDumpPython()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  // files list should contain a path to the temporary directory
+  if ( !myInterp || !myPyModule || files.isEmpty() )
+    return;
+
+  if ( PyObject_HasAttrString(myPyModule, (char*)"dumpStudy") ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"dumpStudy",
+                                           (char*)"s", files.first().toLatin1().constData()));
+
+    if ( !res ) {
+      PyErr_Print();
+    }
+    else {
+      // parse the return value
+      // result can be one string...
+      if ( PyString_Check( res ) ) {
+        QString astr = PyString_AsString( res );
+        //SCRUTE(astr);
+        files.append(astr);
+      }
+      //also result can be a list...
+      else if ( PyList_Check( res ) ) {
+        int size = PyList_Size( res );
+        for ( int i = 0; i < size; i++ ) {
+          PyObject* value = PyList_GetItem( res, i );
+          if( value && PyString_Check( value ) ) {
+            files.append( PyString_AsString( value ) );
+          }
+        }
+      }
+    }
+  }
+}
+
+/*!
+  \brief Check data object's 'draggable' status callback function.
+  \internal
+  \param what data object being tested
+  \return \c true if object can be dragged or \c false otherwise
+*/
+bool PyModuleHelper::internalIsDraggable( LightApp_DataObject* what )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalIsDraggable()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule || !what )
+    return false;
+
+  bool draggable = false;
+
+  if ( PyObject_HasAttrString(myPyModule , (char*)"isDraggable") ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"isDraggable",
+                      (char*)"s", what->entry().toLatin1().constData() ) );
+    if( !res || !PyBool_Check( res )) {
+      PyErr_Print();
+      draggable = false;
+    }
+    else{
+      draggable = PyObject_IsTrue( res );
+    }
+  }
+
+  return draggable;
+}
+
+/*!
+  \brief Check data object's 'drop allowed' status callback function.
+  \internal
+  \param where data object being tested
+  \return \c true if if drop operation is supported by object or \c false otherwise
+*/
+bool PyModuleHelper::internalIsDropAccepted( LightApp_DataObject* where )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalIsDropAccepted()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule || !where )
+    return false;
+
+  bool dropAccepted = false;
+
+  if ( PyObject_HasAttrString(myPyModule , (char*)"isDropAccepted") ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"isDropAccepted",
+                      (char*)"s", where->entry().toLatin1().constData() ) );
+    if( !res || !PyBool_Check( res )) {
+      PyErr_Print();
+      dropAccepted = false;
+    }
+    else{
+      dropAccepted = PyObject_IsTrue( res );
+    }
+  }
+
+  return dropAccepted;
+}
+
+/*!
+  \brief Data dropping callback function.
+  \internal
+  \param what list of data objects being dropped
+  \param where target data object for drop operation
+  \param row line (child item index) where drop operation is performed to
+  \param action current drop action (copy or move)
+*/
+void PyModuleHelper::internalDropObjects( const DataObjectList& what, SUIT_DataObject* where,
+                                          const int row, Qt::DropAction action )
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalDropObjects()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule || what.isEmpty() || !where )
+    return;
+
+  QStringList* theList = new QStringList();
+
+  LightApp_DataObject* whereObject = dynamic_cast<LightApp_DataObject*>( where );
+  if ( !whereObject ) return;
+  
+  for ( int i = 0; i < what.count(); i++ ) {
+    LightApp_DataObject* dataObject = dynamic_cast<LightApp_DataObject*>( what[i] );
+    if ( dataObject ) theList->append( dataObject->entry() );
+  }
+
+#if SIP_VERSION < 0x040800
+  PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList) );
+#else
+  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL) );
+#endif
+  if ( PyObject_HasAttrString(myPyModule, (char*)"dropObjects") ) {
+      PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"dropObjects", (char*)"Osii",
+                        sipList.get(),
+                        whereObject->entry().toLatin1().constData(),
+                        row, action ) );
+    
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+/*!
+  \brief Get engine IOR callback function
+  \internal
+  
+  Tries to get engine IOR from the Python module using engineIOR() function.
+  That function can load module engine using appropriate container if required.
+
+  \return engine IOR or empty string if it is not provided by Python module 
+*/
+QString PyModuleHelper::internalEngineIOR() const
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalEngineIOR()" );
+
+  QString ior;
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( myInterp && myModule ) {
+    if ( PyObject_HasAttrString( myPyModule , "engineIOR" ) ) {
+      PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"engineIOR", (char*)"" ) );
+      if ( !res ) {
+          PyErr_Print();
+      }
+      else {
+        // parse the return value, result chould be string
+        if ( PyString_Check( res ) ) {
+          ior = PyString_AsString( res );
+        }
+      }
+    }
+  }
+  return ior;
+}
+
+/*!
+  \brief Connects signals about activating and cloning view on internal slots
+  \param view view being connected
+*/
+void PyModuleHelper::connectView( SUIT_ViewWindow* view )
+{
+  SUIT_ViewManager* viewMgr = view->getViewManager();
+  SUIT_ViewModel* viewModel = viewMgr ? viewMgr->getViewModel() : 0;
+      
+  // Connect tryCloseView() and deleteView() signals
+  if ( viewMgr ) {
+    connect( viewMgr, SIGNAL( tryCloseView( SUIT_ViewWindow* ) ),
+             this, SLOT( tryCloseView( SUIT_ViewWindow* ) ),
+             Qt::UniqueConnection );
+    connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
+             this, SLOT( closeView( SUIT_ViewWindow* ) ),
+             Qt::UniqueConnection );
+  }
+  
+  // Connect cloneView() signal of an OCC View
+  if ( view->inherits( "OCCViewer_ViewWindow" ) ) {
+    connect( view, SIGNAL( viewCloned( SUIT_ViewWindow* ) ), 
+             this, SLOT( cloneView( SUIT_ViewWindow* ) ),
+             Qt::UniqueConnection );
+  }
+  // Connect cloneView() signal of Plot2d View 
+  else if ( viewModel && viewModel->inherits( "Plot2d_Viewer" ) ) {
+    connect( viewModel, SIGNAL( viewCloned( SUIT_ViewWindow* ) ), 
+             this, SLOT( cloneView( SUIT_ViewWindow* ) ),
+             Qt::UniqueConnection );
+  }
+}
+
+
+
+void PyModuleHelper::internalOBClickedPython( const QString& theObj, int theColumn)
+{
+  FuncMsg fmsg( "--- PyModuleHelper::internalOBClickedPython()" );
+
+  // Python interpreter should be initialized and Python module should be
+  // import first
+  if ( !myInterp || !myPyModule )
+    return; // Error
+
+  if ( PyObject_HasAttrString( myPyModule, (char*)"onObjectBrowserClicked" ) ) {
+    PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"onObjectBrowserClicked", (char*)"si", theObj.toLatin1().constData(), theColumn ) );
+    if( !res ) {
+      PyErr_Print();
+    }
+  }
+}
+
+
+
+void PyModuleHelper::onObjectBrowserClicked(SUIT_DataObject* theObj, int theColumn)
+{
+  FuncMsg fmsg( "PyModuleHelper::onObjectBrowserClicked()" );
+
+  // temporary set myInitModule because dumpPython() method
+  // might be called by the framework when this module is inactive,
+  // but still it should be possible to access this module's data
+  // from Python
+  InitLocker lock( myModule );
+
+  class PythonReq: public PyInterp_LockRequest
+  {
+  public:     
+    PythonReq( PyInterp_Interp* _py_interp,
+               PyModuleHelper*  _helper,
+               const QString& _entry,
+               int     _column )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ) ,
+        myEntry( _entry ),
+        myColumn( _column )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalOBClickedPython( myEntry, myColumn );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    int    myColumn;
+    QString myEntry;
+  };
+  
+  // Posting the request only if dispatcher is not busy!
+  // Executing the request synchronously
+  const LightApp_DataObject* data_object = dynamic_cast<const LightApp_DataObject*>( theObj );
+  if ( (!PyInterp_Dispatcher::Get()->IsBusy()) && data_object )
+    PyInterp_Dispatcher::Get()->Exec( new PythonReq( myInterp, this, data_object->entry(), theColumn ) );
+}
+