Salome HOME
44ae845646b5abde6069adae85a4b4e7330a7414
[modules/gui.git] / src / GUI_PY / dockwidgets.py
1 # Copyright (C) 2014-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from qtsalome import *
21
22 import SalomePyQt
23
24 _dockWidgetNames = {
25     SalomePyQt.WT_ObjectBrowser : "objectBrowserDock",
26     SalomePyQt.WT_PyConsole     : "pythonConsoleDock",
27     SalomePyQt.WT_LogWindow     : "logWindowDock",
28     SalomePyQt.WT_NoteBook      : "noteBookDock",
29 }
30
31 def findDockWidgetByTitle( title ):
32     """
33     Find and return dock widget by its window title.
34     Returns None if dock widget does not exist or is not created yet.
35     
36     WARNING: this function is language-dependant as the title of the
37     dock widget is normally internationalized according to the currently
38     used language.
39
40     Example:
41       # get object browser
42       findDockWidgetByTitle( "Object Browser" )
43     """
44     sg = SalomePyQt.SalomePyQt()
45     dwl = sg.getDesktop().findChildren( QDockWidget )
46     dw = [a for a in dwl if a.windowTitle() == str( title )]
47     if dw: return dw[0]
48     return None
49
50 def findDockWidgetByName( dwName ):
51     """
52     Find and return dock widget by its internal name
53     Returns None if dock widget does not exist or is not created yet
54     
55     Note: this function is language-independant: internal name
56     of the dock widget does not depend on the currently used language.
57
58     Example:
59       # get object browser
60       findDockWidgetByName( "objectBrowserDock" )
61     """
62     sg = SalomePyQt.SalomePyQt()
63     return sg.getDesktop().findChild( QDockWidget, dwName )
64
65 def findDockWidgetById( dwId ):
66     """
67     Find and return dock widget by its id
68     Returns None if dock widget does not exist or is not created yet
69
70     WARNING: this function works only with dock widget ids
71     specified in SalomePyQt interface.
72     
73     Example:
74       # get object browser
75       findDockWidgetById( SalomePyQt.WT_ObjectBrowser )
76     """
77     try:
78         return findDockWidgetByName( _dockWidgetNames[ dwId ] )
79     except:
80         pass
81     return None
82
83 def getAllDockWindows():
84     """
85     Get all dock widgets.
86     
87     WARNING: this function searches all dock widgets starting from the
88     top-level main window; thus, resulting list contains also dock windows
89     that belong to the lower-level windows (e.g. view windows).
90     """
91     sg = SalomePyQt.SalomePyQt()
92     return sg.getDesktop().findChildren( QDockWidget )
93
94 def tabifyDockWidgets( dw1, dw2 ):
95     """
96     Tabify two dock widgets.
97     """
98     sg = SalomePyQt.SalomePyQt()
99     if dw1 and dw2: sg.getDesktop().tabifyDockWidget( dw1, dw2 )
100     pass