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 QIcon
00032 
00033 from .dock_widget import DockWidget
00034 from .dockable_main_window import DockableMainWindow
00035 
00036 
00037 class DockWidgetContainer(DockWidget):
00038 
00039     """`DockWidget` containing a main window acting as a container for other dock widgets."""
00040 
00041     def __init__(self, container_manager, serial_number):
00042         super(DockWidgetContainer, self).__init__(container_manager)
00043         self._serial_number = serial_number
00044         self._settings = None
00045 
00046         self.main_window = DockableMainWindow()
00047         self.setWidget(self.main_window)
00048         self.setWindowIcon(QIcon.fromTheme('folder'))
00049 
00050     def serial_number(self):
00051         return self._serial_number
00052 
00053     def setObjectName(self, name):
00054         super(DockWidget, self).setObjectName(name)
00055         self.main_window.setObjectName(name + '__MainWindow')
00056 
00057     def save_settings(self, settings):
00058         mw_settings = settings.get_settings('mainwindow')
00059         self._save_geometry(mw_settings)
00060         self._save_state(mw_settings)
00061         super(DockWidgetContainer, self).save_settings(settings)
00062 
00063     def _save_geometry(self, settings):
00064         # unmaximizing widget before saveGeometry works around bug to restore dock-widgets
00065         # still the non-maximized size can not correctly be restored
00066         maximized = self.isMaximized()
00067         if maximized:
00068             self.showNormal()
00069         settings.set_value('geometry', self.main_window.saveGeometry())
00070         if maximized:
00071             self.showMaximized()
00072 
00073     def _save_state(self, settings):
00074         if self._settings is not None:
00075             self._settings.set_value('state', self.main_window.saveState())
00076 
00077     def restore_settings(self, settings):
00078         super(DockWidgetContainer, self).restore_settings(settings)
00079         mw_settings = settings.get_settings('mainwindow')
00080         self._settings = mw_settings
00081         # only restore geometry, restoring state is triggered after PluginManager has been updated
00082         self._restore_geometry(mw_settings)
00083 
00084     def _restore_geometry(self, settings):
00085         if settings.contains('geometry'):
00086             self.main_window.restoreGeometry(settings.value('geometry'))
00087 
00088     def restore_state(self):
00089         if self._settings.contains('state'):
00090             self.main_window.restoreState(self._settings.value('state'))


qt_gui
Author(s): Dirk Thomas
autogenerated on Fri Aug 28 2015 12:15:40