def setupUi(self, *a): self.l = l = QFormLayout(self) self.opt_docx_page_size = QComboBox(self) l.addRow(_('Paper si&ze:'), self.opt_docx_page_size) self.opt_docx_custom_page_size = w = QLineEdit(self) w.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) l.addRow(_('&Custom size:'), w) for i, text in enumerate( (_('Page &left margin'), _('Page &top margin'), _('Page &right margin'), _('Page &bottom margin'))): m = 'left top right bottom'.split()[i] w = QDoubleSpinBox(self) w.setRange(-100, 500), w.setSuffix(' pt'), w.setDecimals(1) setattr(self, 'opt_docx_page_margin_' + m, w) l.addRow(text + ':', w) self.opt_docx_no_toc = QCheckBox( _('Do not insert the &Table of Contents as a page at the start of the document' )) l.addRow(self.opt_docx_no_toc) self.opt_docx_no_cover = QCheckBox( _('Do not insert &cover as image at start of document')) l.addRow(self.opt_docx_no_cover) self.opt_preserve_cover_aspect_ratio = QCheckBox( _('Preserve the aspect ratio of the image inserted as cover')) l.addRow(self.opt_preserve_cover_aspect_ratio)
class LockSeriesDialog(SizePersistedDialog): def __init__(self, parent, title, initial_value): SizePersistedDialog.__init__( self, parent, 'Manage Series plugin:lock series dialog') self.initialize_controls(title, initial_value) # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() def initialize_controls(self, title, initial_value): self.setWindowTitle('Lock Series Index') layout = QVBoxLayout(self) self.setLayout(layout) title_layout = ImageTitleLayout(self, 'images/lock32.png', 'Lock Series Index') layout.addLayout(title_layout) layout.addSpacing(10) self.title_label = QLabel('Series index for book: \'%s\'' % title, self) layout.addWidget(self.title_label) hlayout = QHBoxLayout() layout.addLayout(hlayout) self.value_spinbox = QDoubleSpinBox(self) self.value_spinbox.setRange(0, 99000000) self.value_spinbox.setDecimals(2) if initial_value is not None: self.value_spinbox.setValue(initial_value) self.value_spinbox.selectAll() hlayout.addWidget(self.value_spinbox, 0) hlayout.addStretch(1) self.assign_same_checkbox = QCheckBox( '&Assign this index value to all remaining books', self) layout.addWidget(self.assign_same_checkbox) layout.addStretch(1) # Dialog buttons button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject) layout.addWidget(button_box) def get_value(self): return float(unicode(self.value_spinbox.value())) def assign_same_value(self): return self.assign_same_checkbox.isChecked()
def setupUi(self, *a): self.l = l = QFormLayout(self) self.opt_docx_page_size = QComboBox(self) l.addRow(_('Paper si&ze:'), self.opt_docx_page_size) self.opt_docx_custom_page_size = w = QLineEdit(self) w.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) l.addRow(_('&Custom size:'), w) for i, text in enumerate((_('Page &left margin'), _('Page &top margin'), _('Page &right margin'), _('Page &bottom margin'))): m = 'left top right bottom'.split()[i] w = QDoubleSpinBox(self) w.setRange(-100, 500), w.setSuffix(' pt'), w.setDecimals(1) setattr(self, 'opt_docx_page_margin_' + m, w) l.addRow(text + ':', w) self.opt_docx_no_toc = QCheckBox(_('Do not insert the &Table of Contents as a page at the start of the document')) l.addRow(self.opt_docx_no_toc) self.opt_docx_no_cover = QCheckBox(_('Do not insert &cover as image at start of document')) l.addRow(self.opt_docx_no_cover)
def margin(which): w = QDoubleSpinBox(self) w.setRange(-100, 500), w.setSuffix(' pt'), w.setDecimals(1) setattr(self, 'opt_pdf_page_margin_' + which, w) return w
class TimeInputLine(QFrame): WIDTH = 396 HEIGHT = 43 FRAME_WIDTH = 1 FRAME_MARGIN = 2 ICON_SIZE = 35 ICON_BUTTON_WIDTH = 60 LABEL_SIZE_X = 174 INPUT_SIZE_X = 100 BUTTON_BLOCK_X = 278 STEP = 0.5 MIN_VALUE = 0.1 MAX_VALUE = 10 DECIMAL_COUNT = 1 def __init__(self, parent): super().__init__(parent) self.initUI() def initUI(self): self.resize(TimeInputLine.WIDTH + TimeInputLine.FRAME_MARGIN*2, TimeInputLine.HEIGHT + TimeInputLine.FRAME_MARGIN*2) self.setFrameStyle(QFrame.StyledPanel) self.setLineWidth(TimeInputLine.FRAME_WIDTH) component_stylesheet = """ .QPushButton { font-weight: bold; font-size: 13px; background-color:#E0E0E0; } .QPushButton:pressed { background-color:#CCCCCC; } .QDoubleSpinBox { font-weight: bold; font-size: 23px; } .QLabel { font-weight: bold; font-size: 23px; } """ self.label = QLabel("", self) self.label.resize(TimeInputLine.LABEL_SIZE_X, TimeInputLine.HEIGHT) self.label.move(TimeInputLine.FRAME_MARGIN, TimeInputLine.FRAME_MARGIN) self.label.setStyleSheet(component_stylesheet) self.label.setAlignment(Qt.AlignCenter) self.label.show() self.spinbox = QDoubleSpinBox(self) self.spinbox.setRange(TimeInputLine.MIN_VALUE, TimeInputLine.MAX_VALUE) self.spinbox.setValue(TimeInputLine.STEP) self.spinbox.setSingleStep(TimeInputLine.STEP) self.spinbox.setDecimals(TimeInputLine.DECIMAL_COUNT) self.spinbox.resize(TimeInputLine.INPUT_SIZE_X, TimeInputLine.HEIGHT) self.spinbox.move(TimeInputLine.LABEL_SIZE_X + TimeInputLine.FRAME_MARGIN, TimeInputLine.FRAME_MARGIN) self.spinbox.setStyleSheet(component_stylesheet) self.spinbox.show() self.enter = QPushButton("", self) self.enter.setIcon(assets.enter) self.enter.setIconSize(QSize(TimeInputLine.ICON_SIZE, TimeInputLine.ICON_SIZE)) self.enter.resize(TimeInputLine.ICON_BUTTON_WIDTH, TimeInputLine.HEIGHT) self.enter.move(TimeInputLine.BUTTON_BLOCK_X, TimeInputLine.FRAME_MARGIN) self.enter.setStyleSheet(component_stylesheet) self.enter.show() self.cancel = QPushButton("", self) self.cancel.setIcon(assets.exit) self.cancel.setIconSize(QSize(TimeInputLine.ICON_SIZE, TimeInputLine.ICON_SIZE)) self.cancel.resize(TimeInputLine.ICON_BUTTON_WIDTH, TimeInputLine.HEIGHT) self.cancel.move(TimeInputLine.BUTTON_BLOCK_X + TimeInputLine.ICON_BUTTON_WIDTH, TimeInputLine.FRAME_MARGIN) self.cancel.setStyleSheet(component_stylesheet) self.cancel.show() """ listeners which control what happens on accept and on cancel button presses """ def addAcceptListener(self, onAcceptListener): self.enter.clicked.connect(onAcceptListener) def addCancelListener(self, onCancelListener): self.cancel.clicked.connect(onCancelListener)
def createPcCalibrationControls(): gb = QGroupBox("PC Calibration") #------------------------------------------- layout = QHBoxLayout() label = QLabel("Calibration offset for 180:") global offAt180_sb offAt180_sb = QDoubleSpinBox() offAt180_sb.setRange(-4.0, 0.0) offAt180_sb.setSingleStep(0.5) offAt180_sb.setValue(-3.5) offAt180_sb.setMaximumWidth(60) layout.addWidget(label) layout.addWidget(offAt180_sb) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) upper = QWidget() upper.setLayout(layout) #------------------------------------------- layout = QHBoxLayout() btn2p5 = QPushButton("2.5") btn2p5.clicked.connect(lambda: offAt180_sb.setValue(-2.5)) btn3 = QPushButton("3.0") btn3.clicked.connect(lambda: offAt180_sb.setValue(-3.0)) btn3p5 = QPushButton("3.5") btn3p5.clicked.connect(lambda: offAt180_sb.setValue(-3.5)) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(btn2p5) layout.addWidget(btn3) layout.addWidget(btn3p5) middle = QWidget() middle.setLayout(layout) #------------------------------------------- layout = QHBoxLayout() label = QLabel("Running Angle offset:") global runningAngleOffset_sb runningAngleOffset_sb = QSpinBox() runningAngleOffset_sb.setToolTip( "offset in degrees to add to the angle reported by arduino") runningAngleOffset_sb.setRange(0, 5) runningAngleOffset_sb.setValue(2) runningAngleOffset_sb.setMaximumWidth(60) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(label) layout.addWidget(runningAngleOffset_sb) lower = QWidget() lower.setLayout(layout) #------------------------------------------- vbox = QVBoxLayout() vbox.addWidget(upper) vbox.addWidget(middle) vbox.addWidget(lower) vbox.addStretch(1) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) gb.setLayout(vbox) return gb
class SliderWidget(QDialog): ''' class SliderWidget ''' valueChanged = QtCore.pyqtSignal(float) def __init__(self, title, parent = None): super(SliderWidget, self).__init__(parent, Qt.FramelessWindowHint) self._mousePressed = False self._orgPos = QPoint(0, 0) self.setObjectName('SliderWidget') self.resize(500, 150) # self.stylize() # main layout labelTitle = QLabel(title, self) buttonClose = JCloseButton(self) buttonClose.setObjectName('buttonClose') buttonClose.setToolTip('关闭') horiLayoutTitle = QHBoxLayout() horiLayoutTitle.setContentsMargins(6, 0, 6, 6) horiLayoutTitle.addWidget(labelTitle, 0, Qt.AlignTop) horiLayoutTitle.addStretch() horiLayoutTitle.addWidget(buttonClose, 0, Qt.AlignTop) self.doubleSpinBox = QDoubleSpinBox(self) self.doubleSpinBox.setObjectName('doubleSpinBox') self.doubleSpinBox.setMinimumWidth(200) self.doubleSpinBox.setRange(0, 6000) self.doubleSpinBox.setDecimals(2) self.doubleSpinBox.setSingleStep(0.01) self.slider = QSlider(Qt.Horizontal, self) self.slider.setObjectName('slider') self.slider.setRange(self.doubleSpinBox.minimum(), self.doubleSpinBox.maximum()) vertLayoutMain = QVBoxLayout(self) vertLayoutMain.addLayout(horiLayoutTitle) vertLayoutMain.addWidget(self.doubleSpinBox, 0, Qt.AlignHCenter) vertLayoutMain.addSpacing(5) vertLayoutMain.addWidget(self.slider) self.slider.rangeChanged.connect(self.doubleSpinBox.setRange) self.doubleSpinBox.valueChanged.connect(self.doubleSpinBoxValueChanged) self.slider.valueChanged.connect(self.setValue) buttonClose.clicked.connect(self.close) def setRange(self, minValue, maxValue): self.slider.setRange(minValue, maxValue) def setDecimals(self, prec): self.doubleSpinBox.setDecimals(prec) def setSingleStep(self, value): self.doubleSpinBox.setSingleStep(value) def setPrefix(self, prefix): self.doubleSpinBox.setPrefix(prefix) def setSuffix(self, suffix): self.doubleSpinBox.setSuffix(suffix) def doubleSpinBoxValueChanged(self, value): self.slider.setValue(value) self.valueChanged.emit(value) @QtCore.pyqtSlot(float) def setValue(self, value): self.doubleSpinBox.setValue(value) @QtCore.pyqtSlot() def stylize(self): styles.stylize(self) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self._mousePressed = True self._orgPos = event.pos() self.setCursor(Qt.ClosedHandCursor) def mouseMoveEvent(self, event): if self._mousePressed: curPos = event.pos() curGeom = self.geometry() self.move(curGeom.topLeft() + curPos - self._orgPos) def mouseReleaseEvent(self, event): self._mousePressed = False self.setCursor(Qt.ArrowCursor)