33 from python_qt_binding
import loadUi
34 from python_qt_binding.QtCore
import QEvent, QObject, Qt, qWarning
35 from python_qt_binding.QtGui
import QIcon
36 from python_qt_binding.QtWidgets
import QDockWidget, QMenu, QWidget
40 """Title bar for dock widgets providing custom actions.""" 42 def __init__(self, dock_widget, qtgui_path, hide_title=False):
43 super(DockWidgetTitleBar, self).
__init__(dock_widget)
46 ui_file = os.path.join(qtgui_path,
'resource',
'dock_widget_title_bar.ui')
49 'configuration': self.configuration_button,
50 'reload': self.reload_button,
51 'help': self.help_button,
52 'close': self.close_button,
55 icon = QIcon.fromTheme(
'emblem-system')
57 self.configuration_button.setIcon(icon)
58 self.configuration_button.setText(
'')
59 icon = QIcon.fromTheme(
'view-refresh')
61 self.reload_button.setIcon(icon)
62 self.reload_button.setText(
'')
63 icon = QIcon.fromTheme(
'help-browser')
65 self.help_button.setIcon(icon)
66 self.help_button.setText(
'')
68 icon = QIcon.fromTheme(
'window-close')
70 self.close_button.setIcon(icon)
71 self.close_button.setText(
'')
91 self.title_label.installEventFilter(self)
92 self.title_edit.hide()
98 self.icon_label.hide()
99 self.title_label.hide()
100 self.dockable_button.hide()
101 self.reload_button.hide()
102 self.help_button.hide()
103 self.minimize_button.hide()
104 self.float_button.hide()
105 self.close_button.hide()
110 qWarning(
'DockWidgetTitleBar.connect_button(): unknown button_id: %s' % button_id)
112 button.clicked.connect(callback)
119 callback(self.parent())
124 qWarning(
'DockWidgetTitleBar.show_button(): unknown button_id: %s' % button_id)
126 button.setVisible(visibility)
134 if ret_val
is not None:
136 if event.type() == event.ContextMenu
and obj == self.title_label:
138 rename_action = menu.addAction(self.tr(
'Rename dock widget'))
139 action = menu.exec_(self.mapToGlobal(event.pos()))
140 if action == rename_action:
141 self.title_label.hide()
142 self.title_edit.setText(self.title_label.text())
143 self.title_edit.show()
144 self.title_edit.setFocus()
146 return QObject.eventFilter(self, obj, event)
150 if self.parentWidget().windowIcon():
151 pixmap = self.parentWidget().windowIcon().pixmap(self.close_button.iconSize())
152 self.icon_label.setPixmap(pixmap)
155 self.title_label.setText(self.parentWidget().windowTitle())
158 dock_widget = self.parentWidget()
160 dock_widget.setAllowedAreas(Qt.AllDockWidgetAreas)
162 dock_widget.setAllowedAreas(Qt.NoDockWidgetArea)
165 dock_widget = self.parentWidget()
166 dock_widget.setFloating(
not dock_widget.isFloating())
169 dock_widget = self.parentWidget()
174 features = self.parentWidget().features()
176 closable = bool(features & QDockWidget.DockWidgetClosable)
177 self.close_button.setVisible(closable)
178 self.reload_button.setVisible(closable)
180 movable = bool(features & QDockWidget.DockWidgetMovable)
181 self.dockable_button.setChecked(movable)
183 self.dockable_button.setVisible(movable)
184 self.float_button.setVisible(movable)
185 self.minimize_button.setVisible(movable)
188 settings.set_value(
'dock_widget_title', self.
_dock_widget.windowTitle())
191 movable = bool(self.parentWidget().features() & QDockWidget.DockWidgetMovable)
193 settings.set_value(
'dockable', self.dockable_button.isChecked())
196 dock_widget_title = settings.value(
'dock_widget_title',
None)
197 if dock_widget_title
is not None:
198 self.title_label.setText(dock_widget_title)
201 dockable = settings.value(
'dockable',
True)
in [
True,
'true']
203 movable = bool(self.parentWidget().features() & QDockWidget.DockWidgetMovable)
204 self.dockable_button.setChecked(dockable
and movable)
208 self.title_edit.hide()
209 self.title_label.show()
212 if self.title_edit.text():
213 self.title_label.setText(self.title_edit.text())
214 self.
_dock_widget.setWindowTitle(self.title_edit.text())
217 if __name__ ==
'__main__':
219 from python_qt_binding.QtGui
import QApplication
222 app = QApplication(sys.argv)
226 dock1 = QDockWidget(
'dockwidget1', win)
227 win.addDockWidget(Qt.LeftDockWidgetArea, dock1)
229 dock1.setTitleBarWidget(title_bar)
231 dock2 = QDockWidget(
'dockwidget2')
232 win.addDockWidget(Qt.RightDockWidgetArea, dock2)
234 dock2.setTitleBarWidget(title_bar)