def __init__(self, gui_app, parent=None): super(TutorialWidget, self).__init__(parent) self.gui_app = gui_app #self.setStyleSheet('background: lightyellow;') self.text_doc = QtGui.QTextDocument(self) f = QtCore.QFile(":/quickstart.html") if f.open(QtCore.QIODevice.ReadOnly): s = QtCore.QTextStream(f) html = s.readAll() else: html = "quickstart.html not found!" self.text_doc.setHtml(html) self.text_browser = TutorialTextBrowser(openLinks=False) self.text_browser.setDocument(self.text_doc) self.text_browser.href_hover.connect(self._on_href_hover) layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.text_browser) self.flasher = UIFlasher(widget=self)
def __init__(self, specialized_device, display_mode, write_mode, parent=None): """Construct a device specific widget. * specialized_device should be a DeviceBase subclass tailored to the specific device. * display_mode and write_mode are the display and write modes to use with the device. """ super(DeviceWidgetBase, self).__init__(parent) self.log = util.make_logging_source_adapter(__name__, self) self.device = specialized_device self._display_mode = display_mode self._write_mode = write_mode self.make_settings = None self.device.hardware_set.connect(self._on_device_hardware_set) self._on_device_hardware_set(self.device, None, self.device.hw) self.notes_widget = gui_util.DeviceNotesWidget(specialized_device) self.hide_notes_button = QtWidgets.QPushButton( clicked=self._toggle_hide_notes) self.set_notes_visible(False) self.tab_widget = QtWidgets.QTabWidget() self.tab_widget.setCornerWidget(self.hide_notes_button, Qt.TopRightCorner) layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.notes_widget) layout.addWidget(self.tab_widget) layout.setStretch(1, 1)
def __init__(self, orientation=Qt.Horizontal, parent=None): super(SimpleToolBar, self).__init__(parent) self.orientation = orientation if orientation == Qt.Horizontal: self.setLayout(QtWidgets.QHBoxLayout()) else: self.setLayout(QtWidgets.QVBoxLayout()) self.layout().setSpacing(2) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().addStretch(1)
def __init__(self, device, parent=None): super(DeviceNotesWidget, self).__init__(parent) self.device = device device.read_mode_changed.connect(self._on_device_read_mode_changed) device.write_mode_changed.connect(self._on_device_write_mode_changed) device.extension_changed.connect(self._on_device_extension_changed) self.text_edit = NotesTextEdit() self.text_edit.setReadOnly(True) self.text_edit.modificationChanged.connect( self._on_text_edit_modification_changed) fm = self.text_edit.fontMetrics() rh = fm.lineSpacing() + DeviceNotesWidget.ADD_PIXELS_PER_ROW self.text_edit.setFixedHeight(DeviceNotesWidget.DISPLAY_ROWS * rh) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(self.text_edit) self.edit_button = QtWidgets.QPushButton(util.make_icon(":/edit.png"), str(), clicked=self._on_edit_button_clicked) self.edit_button.setToolTip("Edit Device Notes") self.edit_button.setStatusTip(self.edit_button.toolTip()) button_layout = QtWidgets.QVBoxLayout() button_layout.setContentsMargins(0, 0, 0, 0) button_layout.addWidget(self.edit_button, 0, Qt.AlignHCenter) button_layout.addStretch(1) layout.addLayout(button_layout) self._populate()
def __init__(self, parent=None): super(FixedWidthVerticalToolBar, self).__init__(parent) self.setLayout(QtWidgets.QVBoxLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().addStretch(1)
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
# -*- coding: utf-8 -*- import random import sys from mesycontrol.qt import Qt from mesycontrol.qt import QtCore from mesycontrol.qt import QtGui from mesycontrol.qt import QtWidgets from mesycontrol.qt import PySide2 if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) centerWidget = QtWidgets.QWidget() centerLayout = QtWidgets.QVBoxLayout(centerWidget) for i in range(10): letterCount = random.randint(0, 10) buttonText = f"Button {i}" + "z" * letterCount button = QtWidgets.QToolButton() button.setText(buttonText) button.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) centerLayout.addWidget(button) centerLayout.addStretch(1) centerWidget.setFixedWidth(centerWidget.sizeHint().width()) leftTree = QtWidgets.QTreeView() rightTree = QtWidgets.QTreeView()
def __init__(self, device, display_mode=util.COMBINED, write_mode=util.COMBINED, parent=None): super(DeviceTableWidget, self).__init__(parent) self.log = util.make_logging_source_adapter(__name__, self) settings = util.loadUi(":/ui/device_tableview_settings.ui") self.log.debug("display_mode=%d, write_mode=%d", display_mode, write_mode) model = DeviceTableModel(device, display_mode=display_mode, write_mode=write_mode) self.view = DeviceTableView(model=model) sort_model = self.view.sort_model self.view.display_mode_changed.connect(self.display_mode_changed) self.view.write_mode_changed.connect(self.write_mode_changed) menu = QtWidgets.QMenu('Filter options', self) action = menu.addAction("Hide unknown") action.setCheckable(True) action.setChecked(sort_model.filter_unknown) action.triggered.connect(sort_model.set_filter_unknown) action = menu.addAction("Hide read-only") action.setCheckable(True) action.setChecked(sort_model.filter_readonly) action.triggered.connect(sort_model.set_filter_readonly) action = menu.addAction("Hide volatile") action.setCheckable(True) action.setChecked(sort_model.filter_volatile) action.triggered.connect(sort_model.set_filter_volatile) action = menu.addAction("Hide static") action.setCheckable(True) action.setChecked(sort_model.filter_static) action.triggered.connect(sort_model.set_filter_static) menu.addSeparator() action = menu.addAction("Ignore param ranges on edit") action.setCheckable(True) action.triggered.connect(model.set_editing_ignore_parameter_ranges) action = menu.addAction("Hexadecimal values") action.setCheckable(True) action.triggered.connect(model.set_display_hex_values) menu.addSeparator() action = menu.addAction("Resize table cells") action.triggered.connect(self.view.resizeColumnsToContents) action.triggered.connect(self.view.resizeRowsToContents) settings.pb_settings.setMenu(menu) settings.le_filter.textChanged.connect(sort_model.setFilterWildcard) layout = QtWidgets.QVBoxLayout() layout.addWidget(settings) layout.addWidget(self.view) self.setLayout(layout)
def on_actionAbout_triggered(self): try: from . import mc_version version = mc_version.version except ImportError: version = "devel version" d = QtWidgets.QDialog(self) d.setWindowTitle("About mesycontrol") license = QtWidgets.QTextBrowser(parent=d) license.setWindowFlags(Qt.Window) license.setWindowTitle("mesycontrol license") license.setText("") try: f = QtCore.QFile(":/gpl-notice.txt") if not f.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text): return license.setPlainText(str(f.readAll(), 'utf-8')) finally: f.close() l = QtWidgets.QVBoxLayout(d) logo = QtWidgets.QLabel() logo.setPixmap( QtGui.QPixmap(":/mesytec-logo.png").scaledToWidth( 300, Qt.SmoothTransformation)) l.addWidget(logo) t = "mesycontrol - %s" % version label = QtWidgets.QLabel(t) font = label.font() font.setPointSize(15) font.setBold(True) label.setFont(font) l.addWidget(label) l.addWidget(QtWidgets.QLabel("Remote control for mesytec devices.")) l.addWidget(QtWidgets.QLabel("© 2014-2022 mesytec GmbH & Co. KG")) t = '<a href="mailto:[email protected]">[email protected]</a> - <a href="http://www.mesytec.com">www.mesytec.com</a>' label = QtWidgets.QLabel(t) label.setOpenExternalLinks(True) l.addWidget(label) t = 'Running on Python %s using PySide2 %s with Qt %s.' % ( platform.python_version(), PySide2.__version__, PySide2.QtCore.__version__) l.addWidget(QtWidgets.QLabel(t)) l.addSpacing(20) bl = QtWidgets.QHBoxLayout() def license_button_clicked(): sz = license.size() sz = sz.expandedTo(QtCore.QSize(500, 300)) license.resize(sz) license.show() license.raise_() b = QtWidgets.QPushButton("&License", clicked=license_button_clicked) bl.addWidget(b) b = QtWidgets.QPushButton("&Close", clicked=d.close) b.setAutoDefault(True) b.setDefault(True) bl.addWidget(b) l.addLayout(bl) for item in (l.itemAt(i) for i in range(l.count())): item.setAlignment(Qt.AlignHCenter) w = item.widget() if isinstance(w, QtWidgets.QLabel): w.setTextInteractionFlags(Qt.TextBrowserInteraction) d.exec_()