minimized_dock_widgets_toolbar.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.QtCore import QSignalMapper, Qt
00032 from python_qt_binding.QtGui import QAction, QIcon, QToolBar, QWidget
00033 
00034 
00035 class MinimizedDockWidgetsToolbar(QToolBar):
00036 
00037     max_label_length = 15
00038 
00039     def __init__(self, container_manager, parent=None):
00040         super(MinimizedDockWidgetsToolbar, self).__init__(parent=parent)
00041         self.setWindowTitle(self.tr('Minimized dock widgets'))
00042         self.setObjectName('MinimizedDockWidgetsToolbar')
00043         self.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
00044         self._container_manager = container_manager
00045         self._signal_mapper = QSignalMapper(self)
00046         self._signal_mapper.mapped[QWidget].connect(self._on_action_triggered)
00047         self._dock_widgets = {}
00048 
00049         self.hide()
00050 
00051     def addDockWidget(self, dock_widget):
00052         # remove action for same dock widget if exists
00053         self.removeDockWidget(dock_widget)
00054 
00055         icon = dock_widget.windowIcon()
00056         if icon.isNull():
00057             icon = QIcon.fromTheme('folder')
00058         title = dock_widget.windowTitle()
00059         action = QAction(icon, title, self)
00060         # truncate label if necessary
00061         if len(title) > MinimizedDockWidgetsToolbar.max_label_length:
00062             action.setToolTip(title)
00063             action.setIconText(title[0:MinimizedDockWidgetsToolbar.max_label_length] + '...')
00064         self._signal_mapper.setMapping(action, dock_widget)
00065         action.triggered.connect(self._signal_mapper.map)
00066         self._dock_widgets[dock_widget] = action
00067         self.addAction(action)
00068 
00069         self.show()
00070 
00071     def removeDockWidget(self, dock_widget):
00072         if dock_widget in self._dock_widgets:
00073             action = self._dock_widgets[dock_widget]
00074             self.removeAction(action)
00075             del self._dock_widgets[dock_widget]
00076             self._signal_mapper.removeMappings(action)
00077 
00078         if not self._dock_widgets:
00079             self.hide()
00080 
00081     def _on_action_triggered(self, dock_widget):
00082         # if the dock widget is nested inside a container also show the container
00083         # do this recursively for nested containers
00084         while True:
00085             parent = self._container_manager.get_container_of_dock_widget(dock_widget)
00086             if parent is None:
00087                 break
00088             dock_widget.show()
00089             dock_widget = parent
00090         dock_widget.show()


qt_gui
Author(s): Dirk Thomas
autogenerated on Thu Jun 6 2019 18:07:34