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 make_apply_common_button_layout(input_spinbox, tooltip, on_clicked): # Wrapper to invoke the clicked handler without the boolean arg that's # passed from QPushButton.clicked(). def _on_clicked(): on_clicked() button = QtWidgets.QPushButton(clicked=_on_clicked) button.setIcon(QtGui.QIcon(":/arrow-bottom.png")) button.setMaximumHeight(input_spinbox.sizeHint().height()) button.setMaximumWidth(16) button.setToolTip(tooltip) layout = QtWidgets.QHBoxLayout() layout.addWidget(input_spinbox) layout.addWidget(button) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(1) return (layout, button)
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 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_()
finally: self.setTextColor(self._original_text_color) def contextMenuEvent(self, event): pos = event.globalPos() menu = self.createStandardContextMenu(pos) menu.addAction("Clear").triggered.connect(self.clear) menu.exec_(pos) if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG, format='[%(asctime)-15s] [%(name)s.%(levelname)s] %(message)s') qapp = QtGui.QApplication(sys.argv) log_view = LogView() log_view.resize(400, 400) log_view.show() qt_logger = util.QtLogEmitter() qt_logger.log_record.connect(log_view.handle_log_record) logging.getLogger().addHandler(qt_logger.get_handler()) logger = logging.getLogger(__name__) def on_button_clicked(): logging.getLogger("testlogger").debug("Hello World!") button = QtWidgets.QPushButton("Log!", clicked=on_button_clicked) button.show() sys.exit(qapp.exec_())