Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
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
00083
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()