Salome HOME
Copyright update: 2016
[modules/gui.git] / src / GUI_PY / dockwidgets.py
1 # Copyright (C) 2014-2016  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 PyQt4.QtCore import *
21 from PyQt4.QtGui import *
22
23 import SalomePyQt
24
25 _dockWidgetNames = {
26     SalomePyQt.WT_ObjectBrowser : "objectBrowserDock",
27     SalomePyQt.WT_PyConsole     : "pythonConsoleDock",
28     SalomePyQt.WT_LogWindow     : "logWindowDock",
29     SalomePyQt.WT_NoteBook      : "noteBookDock",
30 }
31
32 def findDockWidgetByTitle( title ):
33     """
34     Find and return dock widget by its window title.
35     Returns None if dock widget does not exist or is not created yet.
36     
37     WARNING: this function is language-dependant as the title of the
38     dock widget is normally internationalized according to the currently
39     used language.
40
41     Example:
42       # get object browser
43       findDockWidgetByTitle( "Object Browser" )
44     """
45     sg = SalomePyQt.SalomePyQt()
46     dwl = sg.getDesktop().findChildren( QDockWidget )
47     dw = filter(lambda a: a.windowTitle() == QString( title ), dwl)
48     if dw: return dw[0]
49     return None
50
51 def findDockWidgetByName( dwName ):
52     """
53     Find and return dock widget by its internal name
54     Returns None if dock widget does not exist or is not created yet
55     
56     Note: this function is language-independant: internal name
57     of the dock widget does not depend on the currently used language.
58
59     Example:
60       # get object browser
61       findDockWidgetByName( "objectBrowserDock" )
62     """
63     sg = SalomePyQt.SalomePyQt()
64     return sg.getDesktop().findChild( QDockWidget, dwName )
65
66 def findDockWidgetById( dwId ):
67     """
68     Find and return dock widget by its id
69     Returns None if dock widget does not exist or is not created yet
70
71     WARNING: this function works only with dock widget ids
72     specified in SalomePyQt interface.
73     
74     Example:
75       # get object browser
76       findDockWidgetById( SalomePyQt.WT_ObjectBrowser )
77     """
78     try:
79         return findDockWidgetByName( _dockWidgetNames[ dwId ] )
80     except:
81         pass
82     return None
83
84 def getAllDockWindows():
85     """
86     Get all dock widgets.
87     
88     WARNING: this function searches all dock widgets starting from the
89     top-level main window; thus, resulting list contains also dock windows
90     that belong to the lower-level windows (e.g. view windows).
91     """
92     sg = SalomePyQt.SalomePyQt()
93     return sg.getDesktop().findChildren( QDockWidget )
94
95 def tabifyDockWidgets( dw1, dw2 ):
96     """
97     Tabify two dock widgets.
98     """
99     sg = SalomePyQt.SalomePyQt()
100     if dw1 and dw2: sg.getDesktop().tabifyDockWidget( dw1, dw2 )
101     pass