def __init__(self, context, parent=None): super(MainWindow, self).__init__(parent) self.log = util.make_logging_source_adapter(__name__, self) self.context = context self.mdiArea = MCMdiArea() self.toolbar = self.addToolBar("toolbar") self.toolbar.setObjectName("toolbar") self.setWindowTitle("mesycontrol") self.setWindowIcon(make_icon(":/window-icon.png")) self.mdiArea.setLayout(QtWidgets.QGridLayout()) self.setCentralWidget(self.mdiArea) self.status_bar = QtWidgets.QStatusBar() self.setStatusBar(self.status_bar) self.actionQuickstart = QtWidgets.QAction("Quickstart") self.actionQuickstart.setShortcut("F1") self.menu_file = QtWidgets.QMenu("&File") self.menu_window = QtWidgets.QMenu("&Window") self.menu_help = QtWidgets.QMenu("&Help") self.menu_help.addAction(self.actionQuickstart) self.menu_help.addSeparator() self.menu_help.addAction("&About", self.on_actionAbout_triggered) self.menu_help.addAction("About &Qt", self.on_actionAbout_Qt_triggered) self.menu_bar = self.menuBar() self.menu_bar.addMenu(self.menu_file) self.menu_bar.addMenu(self.menu_help) # Treeview self.treeview = MCTreeView(app_registry=context.app_registry, device_registry=context.device_registry) dw_tree = QtWidgets.QDockWidget("Device tree", self) dw_tree.setObjectName("dw_treeview") dw_tree.setWidget(self.treeview) dw_tree.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.addDockWidget(Qt.BottomDockWidgetArea, dw_tree) # Log view self.logview = log_view.LogView(parent=self) dw_logview = QtWidgets.QDockWidget("Application Log", self) dw_logview.setObjectName("dw_logview") dw_logview.setWidget(self.logview) dw_logview.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | QtWidgets.QDockWidget.DockWidgetFloatable) self.addDockWidget(Qt.BottomDockWidgetArea, dw_logview)
def __init__(self, app_registry, device_registry, linked_mode_on=False, parent=None): super(MCTreeView, self).__init__(parent) self.log = util.make_logging_source_adapter(__name__, self) self._director = MCTreeDirector(app_registry=app_registry, device_registry=device_registry, linked_mode_on=linked_mode_on) self.cfg_model = self._director.cfg_model self.hw_model = self._director.hw_model self.cfg_view = ConfigTreeView() self.cfg_view.setObjectName('config_tree_view') self.cfg_view.setModel(self.cfg_model) self.cfg_model.rowsInserted.connect(self.cfg_view.expandAll) def on_cfg_rows_removed(parentIndex, start, end): self.log.debug( f"on_cfg_rows_removed parentIndex={parentIndex} start={start} end={end}" ) self.cfg_view.rowsRemoved(parentIndex, start, end) self.cfg_view.resizeColumnToContents(0) self.cfg_model.rowsRemoved.connect(on_cfg_rows_removed) def resize_cfg_cols(): self.cfg_view.resizeColumnToContents(0) self.cfg_model.rowsInserted.connect(resize_cfg_cols) self.cfg_view.customContextMenuRequested.connect( self._cfg_context_menu) self.cfg_view.expanded.connect(self._cfg_expanded) self.cfg_view.collapsed.connect(self._cfg_collapsed) self.cfg_view.setItemDelegate(MCTreeItemDelegate(self._director)) self.cfg_view.selectionModel().selectionChanged.connect( self._cfg_selection_changed) self.cfg_view.doubleClicked.connect(self._cfg_view_double_clicked) self.cfg_view.clicked.connect(self._cfg_view_clicked) self.hw_view = HardwareTreeView() self.hw_view.setObjectName('hardware_tree_view') self.hw_view.setModel(self.hw_model) self.hw_model.rowsInserted.connect(self.hw_view.expandAll) def on_hw_rows_removed(parentIndex, start, end): self.log.debug( f"on_hw_rows_removed parentIndex={parentIndex} start={start} end={end}" ) self.hw_view.rowsRemoved(parentIndex, start, end) self.hw_view.resizeColumnToContents(0) self.hw_model.rowsRemoved.connect(on_hw_rows_removed) def resize_hw_cols(): self.hw_view.resizeColumnToContents(0) self.hw_model.rowsInserted.connect(resize_hw_cols) self.hw_view.customContextMenuRequested.connect(self._hw_context_menu) self.hw_view.expanded.connect(self._hw_expanded) self.hw_view.collapsed.connect(self._hw_collapsed) self.hw_view.setItemDelegate(MCTreeItemDelegate(self._director)) self.hw_view.setFirstColumnSpanned(0, QtCore.QModelIndex(), True) self.hw_view.selectionModel().selectionChanged.connect( self._hw_selection_changed) self.hw_view.doubleClicked.connect(self._hw_view_double_clicked) self.hw_view.clicked.connect(self._hw_view_clicked) self.cfg_view.expandAll() self.hw_view.expandAll() self.splitter_toolbar = util.SimpleToolBar(Qt.Vertical) self.cfg_toolbar = util.SimpleToolBar(Qt.Horizontal) self.cfg_toolbar.layout().setContentsMargins(0, 0, 0, 0) self.hw_toolbar = util.SimpleToolBar(Qt.Horizontal) self.hw_toolbar.layout().setContentsMargins(0, 0, 0, 0) cfg_widget = QtWidgets.QGroupBox("Config") cfg_layout = QtWidgets.QVBoxLayout(cfg_widget) cfg_layout.setContentsMargins(2, 2, 2, 2) cfg_layout.addWidget(self.cfg_toolbar) cfg_layout.addWidget(self.cfg_view) cfg_layout.setStretch(1, 1) hw_widget = QtWidgets.QGroupBox("Hardware") hw_layout = QtWidgets.QVBoxLayout(hw_widget) hw_layout.setContentsMargins(2, 2, 2, 2) hw_layout.addWidget(self.hw_toolbar) hw_layout.addWidget(self.hw_view) hw_layout.setStretch(1, 1) center_widget = QtWidgets.QGroupBox("Actions") center_layout = QtWidgets.QVBoxLayout(center_widget) center_layout.setContentsMargins(2, 2, 2, 2) center_layout.addWidget(self.splitter_toolbar) self.center_widget = center_widget self.splitter = splitter = DoubleClickSplitter() splitter.setChildrenCollapsible(False) splitter.addWidget(hw_widget) splitter.addWidget(center_widget) splitter.addWidget(cfg_widget) def on_handle_double_clicked(): # make hw and cfg views the same size which will result in the # splitter buttons being centered sizes = splitter.sizes() size = (sizes[0] + sizes[2]) / 2 sizes[0], sizes[2] = size, size splitter.setSizes(sizes) splitter.handle(1).doubleClicked.connect(on_handle_double_clicked) splitter.handle(2).doubleClicked.connect(on_handle_double_clicked) layout = QtWidgets.QGridLayout(self) layout.addWidget(splitter, 0, 0) self._ignore_next_selection = False