minimized_dock_widgets_toolbar.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.QtCore import QSignalMapper, Qt
32 from python_qt_binding.QtGui import QIcon
33 from python_qt_binding.QtWidgets import QAction, QToolBar, QWidget
34 
35 
37 
38  max_label_length = 15
39 
40  def __init__(self, container_manager, parent=None):
41  super(MinimizedDockWidgetsToolbar, self).__init__(parent=parent)
42  self.setWindowTitle(self.tr('Minimized dock widgets'))
43  self.setObjectName('MinimizedDockWidgetsToolbar')
44  self.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
45  self._container_manager = container_manager
46  self._signal_mapper = QSignalMapper(self)
47  self._signal_mapper.mapped[QWidget].connect(self._on_action_triggered)
48  self._dock_widgets = {}
49 
50  self.hide()
51 
52  def addDockWidget(self, dock_widget):
53  # remove action for same dock widget if exists
54  self.removeDockWidget(dock_widget)
55 
56  icon = dock_widget.windowIcon()
57  if icon.isNull():
58  icon = QIcon.fromTheme('folder')
59  title = dock_widget.windowTitle()
60  action = QAction(icon, title, self)
61  # truncate label if necessary
62  if len(title) > MinimizedDockWidgetsToolbar.max_label_length:
63  action.setToolTip(title)
64  action.setIconText(title[0:MinimizedDockWidgetsToolbar.max_label_length] + '...')
65  self._signal_mapper.setMapping(action, dock_widget)
66  action.triggered.connect(self._signal_mapper.map)
67  self._dock_widgets[dock_widget] = action
68  self.addAction(action)
69 
70  self.show()
71 
72  def removeDockWidget(self, dock_widget):
73  if dock_widget in self._dock_widgets:
74  action = self._dock_widgets[dock_widget]
75  self.removeAction(action)
76  del self._dock_widgets[dock_widget]
77  self._signal_mapper.removeMappings(action)
78 
79  if not self._dock_widgets:
80  self.hide()
81 
82  def _on_action_triggered(self, dock_widget):
83  # if the dock widget is nested inside a container also show the container
84  # do this recursively for nested containers
85  while True:
86  parent = self._container_manager.get_container_of_dock_widget(dock_widget)
87  if parent is None:
88  break
89  dock_widget.show()
90  dock_widget = parent
91  dock_widget.show()
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar._dock_widgets
_dock_widgets
Definition: minimized_dock_widgets_toolbar.py:48
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar
Definition: minimized_dock_widgets_toolbar.py:36
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar._on_action_triggered
def _on_action_triggered(self, dock_widget)
Definition: minimized_dock_widgets_toolbar.py:82
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar._container_manager
_container_manager
Definition: minimized_dock_widgets_toolbar.py:45
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar.removeDockWidget
def removeDockWidget(self, dock_widget)
Definition: minimized_dock_widgets_toolbar.py:72
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar.addDockWidget
def addDockWidget(self, dock_widget)
Definition: minimized_dock_widgets_toolbar.py:52
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar._signal_mapper
_signal_mapper
Definition: minimized_dock_widgets_toolbar.py:46
qt_gui.minimized_dock_widgets_toolbar.MinimizedDockWidgetsToolbar.__init__
def __init__(self, container_manager, parent=None)
Definition: minimized_dock_widgets_toolbar.py:40


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