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