dock_widget_container.py
Go to the documentation of this file.
1 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution.
14 # * Neither the name of the TU Darmstadt nor the names of its
15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 from python_qt_binding.QtGui import QIcon
32 
33 from qt_gui.dock_widget import DockWidget
34 from qt_gui.dockable_main_window import DockableMainWindow
35 
36 
38  """`DockWidget` containing a main window acting as a container for other dock widgets."""
39 
40  def __init__(self, container_manager, serial_number):
41  super(DockWidgetContainer, self).__init__(container_manager)
42  self._serial_number = serial_number
43  self._settings = None
44 
46  self.setWidget(self.main_window)
47  self.setWindowIcon(QIcon.fromTheme('folder'))
48 
49  def serial_number(self):
50  return self._serial_number
51 
52  def setObjectName(self, name):
53  super(DockWidget, self).setObjectName(name)
54  self.main_window.setObjectName(name + '__MainWindow')
55 
56  def save_settings(self, settings):
57  mw_settings = settings.get_settings('mainwindow')
58  self._save_geometry(mw_settings)
59  self._save_state(mw_settings)
60  super(DockWidgetContainer, self).save_settings(settings)
61 
62  def _save_geometry(self, settings):
63  # unmaximizing widget before saveGeometry works around bug to restore dock-widgets
64  # still the non-maximized size can not correctly be restored
65  maximized = self.isMaximized()
66  if maximized:
67  self.showNormal()
68  settings.set_value('geometry', self.main_window.saveGeometry())
69  if maximized:
70  self.showMaximized()
71 
72  def _save_state(self, settings):
73  if self._settings is not None:
74  self._settings.set_value('state', self.main_window.saveState())
75 
76  def restore_settings(self, settings):
77  super(DockWidgetContainer, self).restore_settings(settings)
78  mw_settings = settings.get_settings('mainwindow')
79  self._settings = mw_settings
80  # only restore geometry, restoring state is triggered after PluginManager has been updated
81  self._restore_geometry(mw_settings)
82 
83  def _restore_geometry(self, settings):
84  if settings.contains('geometry'):
85  self.main_window.restoreGeometry(settings.value('geometry'))
86 
87  def restore_state(self):
88  if self._settings.contains('state'):
89  self.main_window.restoreState(self._settings.value('state'))
qt_gui.dock_widget_container.DockWidgetContainer.restore_settings
def restore_settings(self, settings)
Definition: dock_widget_container.py:76
qt_gui.dock_widget_container.DockWidgetContainer._save_geometry
def _save_geometry(self, settings)
Definition: dock_widget_container.py:62
qt_gui.dock_widget_container.DockWidgetContainer.save_settings
def save_settings(self, settings)
Definition: dock_widget_container.py:56
qt_gui.dock_widget_container.DockWidgetContainer._serial_number
_serial_number
Definition: dock_widget_container.py:42
qt_gui.dock_widget
Definition: dock_widget.py:1
qt_gui.dock_widget_container.DockWidgetContainer._save_state
def _save_state(self, settings)
Definition: dock_widget_container.py:72
qt_gui.dock_widget_container.DockWidgetContainer.serial_number
def serial_number(self)
Definition: dock_widget_container.py:49
qt_gui.dock_widget_container.DockWidgetContainer.__init__
def __init__(self, container_manager, serial_number)
Definition: dock_widget_container.py:40
qt_gui.dock_widget_container.DockWidgetContainer.main_window
main_window
Definition: dock_widget_container.py:45
qt_gui.dock_widget_container.DockWidgetContainer.setObjectName
def setObjectName(self, name)
Definition: dock_widget_container.py:52
qt_gui.dock_widget_container.DockWidgetContainer.restore_state
def restore_state(self)
Definition: dock_widget_container.py:87
qt_gui.dockable_main_window
Definition: dockable_main_window.py:1
qt_gui.dock_widget_container.DockWidgetContainer
Definition: dock_widget_container.py:37
qt_gui.dockable_main_window.DockableMainWindow
Definition: dockable_main_window.py:37
qt_gui.dock_widget_container.DockWidgetContainer._restore_geometry
def _restore_geometry(self, settings)
Definition: dock_widget_container.py:83
qt_gui.dock_widget.DockWidget
Definition: dock_widget.py:39
qt_gui.dock_widget_container.DockWidgetContainer._settings
_settings
Definition: dock_widget_container.py:43


qt_gui
Author(s): Dirk Thomas
autogenerated on Sat Jun 25 2022 02:15:05