Salome HOME
0022614: [CEA 1146] SalomePyQt python API tabifyDockWidgets and findDockByWT
[modules/gui.git] / src / GUI_PY / dockwidgets.py
1 from PyQt4.QtCore import *
2 from PyQt4.QtGui import *
3
4 import SalomePyQt
5
6 _dockWidgetNames = {
7     SalomePyQt.WT_ObjectBrowser : "objectBrowserDock",
8     SalomePyQt.WT_PyConsole     : "pythonConsoleDock",
9     SalomePyQt.WT_LogWindow     : "logWindowDock",
10     SalomePyQt.WT_NoteBook      : "noteBookDock",
11 }
12
13 def findDockWidgetByTitle( title ):
14     """
15     Find and return dock widget by its window title.
16     Returns None if dock widget does not exist or is not created yet.
17     
18     WARNING: this function is language-dependant as the title of the
19     dock widget is normally internationalized according to the currently
20     used language.
21
22     Example:
23       # get object browser
24       findDockWidgetByTitle( "Object Browser" )
25     """
26     sg = SalomePyQt.SalomePyQt()
27     dwl = sg.getDesktop().findChildren( QDockWidget )
28     dw = filter(lambda a: a.windowTitle() == QString( title ), dwl)
29     if dw: return dw[0]
30     return None
31
32 def findDockWidgetByName( dwName ):
33     """
34     Find and return dock widget by its internal name
35     Returns None if dock widget does not exist or is not created yet
36     
37     Note: this function is language-independant: internal name
38     of the dock widget does not depend on the currently used language.
39
40     Example:
41       # get object browser
42       findDockWidgetByName( "objectBrowserDock" )
43     """
44     sg = SalomePyQt.SalomePyQt()
45     return sg.getDesktop().findChild( QDockWidget, dwName )
46
47 def findDockWidgetById( dwId ):
48     """
49     Find and return dock widget by its id
50     Returns None if dock widget does not exist or is not created yet
51
52     WARNING: this function works only with dock widget ids
53     specified in SalomePyQt interface.
54     
55     Example:
56       # get object browser
57       findDockWidgetById( SalomePyQt.WT_ObjectBrowser )
58     """
59     try:
60         return findDockWidgetByName( _dockWidgetNames[ dwId ] )
61     except:
62         pass
63     return None
64
65 def getAllDockWindows():
66     """
67     Get all dock widgets.
68     
69     WARNING: this function searches all dock widgets starting from the
70     top-level main window; thus, resulting list contains also dock windows
71     that belong to the lower-level windows (e.g. view windows).
72     """
73     sg = SalomePyQt.SalomePyQt()
74     return sg.getDesktop().findChildren( QDockWidget )
75
76 def tabifyDockWidgets( dw1, dw2 ):
77     """
78     Tabify two dock widgets.
79     """
80     sg = SalomePyQt.SalomePyQt()
81     if dw1 and dw2: sg.getDesktop().tabifyDockWidget( dw1, dw2 )
82     pass