dock_widget_container.py
Go to the documentation of this file.
00001 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
00002 # All rights reserved.
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 #   * Redistributions of source code must retain the above copyright
00009 #     notice, this list of conditions and the following disclaimer.
00010 #   * Redistributions in binary form must reproduce the above
00011 #     copyright notice, this list of conditions and the following
00012 #     disclaimer in the documentation and/or other materials provided
00013 #     with the distribution.
00014 #   * Neither the name of the TU Darmstadt nor the names of its
00015 #     contributors may be used to endorse or promote products derived
00016 #     from this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00028 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029 # POSSIBILITY OF SUCH DAMAGE.
00030 
00031 from python_qt_binding.QtGui import QMainWindow
00032 
00033 from .dock_widget import DockWidget
00034 
00035 
00036 class DockWidgetContainer(DockWidget):
00037 
00038     """`DockWidget` containing a main window acting as a container for other dock widgets."""
00039 
00040     def __init__(self, container_manager, serial_number):
00041         super(DockWidgetContainer, self).__init__(container_manager)
00042         self._serial_number = serial_number
00043         self._settings = None
00044 
00045         self.main_window = QMainWindow()
00046         self.main_window.setDockNestingEnabled(True)
00047         self.setWidget(self.main_window)
00048 
00049     def serial_number(self):
00050         return self._serial_number
00051 
00052     def setObjectName(self, name):
00053         super(DockWidget, self).setObjectName(name)
00054         self.main_window.setObjectName(name + '__MainWindow')
00055 
00056     def save_settings(self, settings):
00057         mw_settings = settings.get_settings('mainwindow')
00058         self._save_geometry(mw_settings)
00059         self._save_state(mw_settings)
00060         super(DockWidgetContainer, self).save_settings(settings)
00061 
00062     def _save_geometry(self, settings):
00063         # unmaximizing widget before saveGeometry works around bug to restore dock-widgets
00064         # still the non-maximized size can not correctly be restored
00065         maximized = self.isMaximized()
00066         if maximized:
00067             self.showNormal()
00068         settings.set_value('geometry', self.main_window.saveGeometry())
00069         if maximized:
00070             self.showMaximized()
00071 
00072     def _save_state(self, settings):
00073         if self._settings is not None:
00074             self._settings.set_value('state', self.main_window.saveState())
00075 
00076     def restore_settings(self, settings):
00077         super(DockWidgetContainer, self).restore_settings(settings)
00078         mw_settings = settings.get_settings('mainwindow')
00079         self._settings = mw_settings
00080         # only restore geometry, restoring state is triggered after PluginManager has been updated
00081         self._restore_geometry(mw_settings)
00082 
00083     def _restore_geometry(self, settings):
00084         if settings.contains('geometry'):
00085             self.main_window.restoreGeometry(settings.value('geometry'))
00086 
00087     def restore_state(self):
00088         if self._settings.contains('state'):
00089             self.main_window.restoreState(self._settings.value('state'))


qt_gui
Author(s): Dirk Thomas
autogenerated on Fri Jan 3 2014 11:44:00