From: vsr Date: Tue, 2 Sep 2014 14:48:53 +0000 (+0400) Subject: 0022614: [CEA 1146] SalomePyQt python API tabifyDockWidgets and findDockByWT X-Git-Tag: V7_5_0a1~18^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d8153c20d70f5163b18685f674a883fd3bd3e783;p=modules%2Fgui.git 0022614: [CEA 1146] SalomePyQt python API tabifyDockWidgets and findDockByWT --- diff --git a/src/GUI_PY/CMakeLists.txt b/src/GUI_PY/CMakeLists.txt index 496f5fa05..0c034e0d8 100755 --- a/src/GUI_PY/CMakeLists.txt +++ b/src/GUI_PY/CMakeLists.txt @@ -41,12 +41,17 @@ SET(_other_SCRIPTS helper.py mytestdialog.py selectvars.py + dockwidgets.py +) +SET(_bin_SCRIPTS + test_dockwidgets.py ) -# scritps / to install +# scripts / to install SET(_all_SCRIPTS ${_other_SCRIPTS} ${_pyuic_SCRIPTS}) # --- rules --- SALOME_INSTALL_SCRIPTS("${_all_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/salome/gui) +SALOME_INSTALL_SCRIPTS("${_bin_SCRIPTS}" ${SALOME_INSTALL_SCRIPT_DATA}) diff --git a/src/GUI_PY/dockwidgets.py b/src/GUI_PY/dockwidgets.py new file mode 100644 index 000000000..8bd579758 --- /dev/null +++ b/src/GUI_PY/dockwidgets.py @@ -0,0 +1,82 @@ +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +import SalomePyQt + +_dockWidgetNames = { + SalomePyQt.WT_ObjectBrowser : "objectBrowserDock", + SalomePyQt.WT_PyConsole : "pythonConsoleDock", + SalomePyQt.WT_LogWindow : "logWindowDock", + SalomePyQt.WT_NoteBook : "noteBookDock", +} + +def findDockWidgetByTitle( title ): + """ + Find and return dock widget by its window title. + Returns None if dock widget does not exist or is not created yet. + + WARNING: this function is language-dependant as the title of the + dock widget is normally internationalized according to the currently + used language. + + Example: + # get object browser + findDockWidgetByTitle( "Object Browser" ) + """ + sg = SalomePyQt.SalomePyQt() + dwl = sg.getDesktop().findChildren( QDockWidget ) + dw = filter(lambda a: a.windowTitle() == QString( title ), dwl) + if dw: return dw[0] + return None + +def findDockWidgetByName( dwName ): + """ + Find and return dock widget by its internal name + Returns None if dock widget does not exist or is not created yet + + Note: this function is language-independant: internal name + of the dock widget does not depend on the currently used language. + + Example: + # get object browser + findDockWidgetByName( "objectBrowserDock" ) + """ + sg = SalomePyQt.SalomePyQt() + return sg.getDesktop().findChild( QDockWidget, dwName ) + +def findDockWidgetById( dwId ): + """ + Find and return dock widget by its id + Returns None if dock widget does not exist or is not created yet + + WARNING: this function works only with dock widget ids + specified in SalomePyQt interface. + + Example: + # get object browser + findDockWidgetById( SalomePyQt.WT_ObjectBrowser ) + """ + try: + return findDockWidgetByName( _dockWidgetNames[ dwId ] ) + except: + pass + return None + +def getAllDockWindows(): + """ + Get all dock widgets. + + WARNING: this function searches all dock widgets starting from the + top-level main window; thus, resulting list contains also dock windows + that belong to the lower-level windows (e.g. view windows). + """ + sg = SalomePyQt.SalomePyQt() + return sg.getDesktop().findChildren( QDockWidget ) + +def tabifyDockWidgets( dw1, dw2 ): + """ + Tabify two dock widgets. + """ + sg = SalomePyQt.SalomePyQt() + if dw1 and dw2: sg.getDesktop().tabifyDockWidget( dw1, dw2 ) + pass diff --git a/src/GUI_PY/test_dockwidgets.py b/src/GUI_PY/test_dockwidgets.py new file mode 100644 index 000000000..d51d52344 --- /dev/null +++ b/src/GUI_PY/test_dockwidgets.py @@ -0,0 +1,45 @@ +from salome.gui.dockwidgets import * + +print "-- Search dock windows by title" +ob = findDockWidgetByTitle( "Object Browser" ) +if ob: + print "object browser:", ob +else: + print "object browser was not found" + +pc = findDockWidgetByTitle( "Python Console" ) +if pc: + print "python console:", pc +else: + print "python console was not found" +print + +print "-- Search dock windows by name" +ob = findDockWidgetByName( "objectBrowserDock" ) +if ob: + print "object browser:", ob +else: + print "object browser was not found" +pc = findDockWidgetByName( "pythonConsoleDock" ) +if pc: + print "python console:", pc +else: + print "python console was not found" +print + +print "-- Search dock windows by id" +ob = findDockWidgetById( SalomePyQt.WT_ObjectBrowser ) +if ob: + print "object browser:", ob +else: + print "object browser was not found" +pc = findDockWidgetById( SalomePyQt.WT_PyConsole ) +if pc: + print "python console:", pc +else: + print "python console was not found" +print + +print "-- Tabify dock windows" +tabifyDockWidgets( findDockWidgetById( SalomePyQt.WT_ObjectBrowser ), + findDockWidgetById( SalomePyQt.WT_PyConsole ) )