def embed_toolbar(self, pid, toolbar_object_name): toolbar = QToolBar() toolbar.setObjectName(toolbar_object_name) embed_container = QX11EmbedContainer(toolbar) toolbar.addWidget(embed_container) #embed_container.clientClosed.connect(self._emit_close_signal) self._add_toolbar(toolbar) self._embed_containers[toolbar_object_name] = embed_container # setup mapping to signal change of orientation to client self._embed_toolbars[toolbar_object_name] = toolbar self._signal_mapper_toolbars.setMapping(toolbar, toolbar_object_name) toolbar.orientationChanged.connect(self._signal_mapper_toolbars.map) return embed_container.winId()
def embed_toolbar(self, pid, toolbar_object_name): toolbar = QToolBar() toolbar.setObjectName(toolbar_object_name) embed_container = QX11EmbedContainer(toolbar) toolbar.addWidget(embed_container) #embed_container.clientClosed.connect(self._emit_close_signal) self._add_toolbar(toolbar) self._embed_containers[toolbar_object_name] = embed_container # setup mapping to signal change of orientation to client self._embed_toolbars[toolbar_object_name] = toolbar self._signal_mapper_toolbars.setMapping(toolbar, toolbar_object_name) toolbar.orientationChanged.connect(self._signal_mapper_toolbars.map) return embed_container.winId()
class Dashboard(Plugin): """ Base class from which dashboards should inherit. :param context: the plugin context :type context: qt_gui.plugin.Plugin """ def __init__(self, context): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): self.name = 'Dashboard' if not hasattr(self, 'max_icon_size'): self.max_icon_size = QSize(50, 30) self._main_widget = QToolBar() self._main_widget.setIconSize(self.max_icon_size) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) if context.serial_number() > 1: self._main_widget.setWindowTitle(self._main_widget.windowTitle() + (' (%d)' % context.serial_number())) widgets = self.get_widgets() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise Exception("All widgets must be a subclass of QWidget!") self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget) def setup(self, context): """ Called during ``__init__`` Subclasses should do initialization here. NOTE when overriding this method you should provide a ``self.name`` to avoid naming conflicts. :param context: The plugin context :type context: qt_gui.plugin.Plugin """ pass def shutdown_plugin(self): """ Called when the toolbar is closed by Qt. """ for widget in self._widgets: if hasattr(widget, 'shutdown_widget'): widget.shutdown_widget() if hasattr(widget, 'close'): widget.close() self.shutdown_dashboard() def shutdown_dashboard(self): """ Called after shutdown plugin, subclasses should do cleanup here, not in shutdown_plugin """ pass def get_widgets(self): """ Most of the dashboard customization should be done here. If this function is not overriden the dashboard will display nothing. :returns: List of lists containing dashboard widgets. """ return []
#!/usr/bin/env python import sys from python_qt_binding.QtCore import QSettings, Qt from python_qt_binding.QtGui import QAction, QApplication, QDockWidget, QToolBar, QMainWindow app = QApplication(sys.argv) settings = QSettings(QSettings.IniFormat, QSettings.UserScope, 'test', 'test') mw = QMainWindow() mw.resize(800, 600) mw.show() tb = QToolBar() tb.setObjectName('toolbar') mw.addToolBar(tb) count_dock_widgets = 0 def add_dock_widget(orientation): global count_dock_widgets count_dock_widgets += 1 dw = QDockWidget('dockwidget%d' % count_dock_widgets, mw) dw.setObjectName('dockwidget%d' % count_dock_widgets) mw.addDockWidget(Qt.BottomDockWidgetArea, dw, orientation) def add_horizontal(self): add_dock_widget(Qt.Horizontal) def add_vertical(self):
class Dashboard(Plugin): """ Base class from which dashboards should inherit. :param context: the plugin context :type context: qt_gui.plugin.Plugin """ def __init__(self, context): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): self.name = 'Dashboard' if not hasattr(self, 'max_icon_size'): self.max_icon_size = QSize(50, 30) self._main_widget = QToolBar() self._main_widget.setIconSize(self.max_icon_size) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) if context.serial_number() > 1: self._main_widget.setWindowTitle(self._main_widget.windowTitle() + (' (%d)' % context.serial_number())) widgets = self.get_widgets() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise Exception( "All widgets must be a subclass of QWidget!") self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget) def setup(self, context): """ Called during ``__init__`` Subclasses should do initialization here. NOTE when overriding this method you should provide a ``self.name`` to avoid naming conflicts. :param context: The plugin context :type context: qt_gui.plugin.Plugin """ pass def shutdown_plugin(self): """ Called when the toolbar is closed by Qt. """ for widget in self._widgets: if hasattr(widget, 'shutdown_widget'): widget.shutdown_widget() if hasattr(widget, 'close'): widget.close() self.shutdown_dashboard() def shutdown_dashboard(self): """ Called after shutdown plugin, subclasses should do cleanup here, not in shutdown_plugin """ pass def get_widgets(self): """ Most of the dashboard customization should be done here. If this function is not overriden the dashboard will display nothing. :returns: List of lists containing dashboard widgets. """ return []
class Dashboard(Plugin): """Base class from which dashboards should inherit.""" def __init__(self, context, name = None): super(Dashboard, self).__init__(context) self.context = context self.setup(context) if not hasattr(self, 'name'): if not name: self.name = 'Dashboard' else: self.name = name self._main_widget = QToolBar() self._main_widget.setIconSize(QSize(80, 80)) self._main_widget.setObjectName(self.name) self._main_widget.setWindowTitle(self.name) widgets = self.get_widgets() layout = QHBoxLayout() self._widgets = [] for v in widgets: for i in v: try: self._main_widget.addWidget(i) self._widgets.append(i) except: raise(Exception("All widgets must be a subclass of QWidget!")) self._main_widget.addSeparator() # Display the dashboard context.add_toolbar(self._main_widget) def setup(self, context): """Called during ``__init__`` Subclasses should do initialization here. .. note:: If this method is overriden it is important to call ``self.setObjectName()`` so that object names do not conflict. :param context: The plugin context :type context: qt_gui.plugin.Plugin """ pass def shutdown_plugin(self): """Called when the toolbar is closed by Qt. """ for widget in self._widgets: if hasattr(widget, 'close'): widget.close() self.shutdown_dashboard() def shutdown_dashboard(self): """Called after shutdown plugin, subclasses should do cleanup here, not in shutdown_plugin """ pass def get_widgets(self): """ Most of the dashboard customization should be done here. If this function is not overriden the dashboard will display nothing. :returns: List of lists containing dashboard widgets. """ return []