def __init__(self, mw, names=None, accept=None, title=None, help="studydeck", current=None, cancel=True, parent=None, dyn=False, buttons=None, geomKey="default"): QDialog.__init__(self, parent or mw) if buttons is None: buttons = [] self.mw = mw self.form = aqt.forms.studydeck.Ui_Dialog() self.form.setupUi(self) self.form.filter.installEventFilter(self) self.cancel = cancel addHook('reset', self.onReset) self.geomKey = "studyDeck-" + geomKey restoreGeom(self, self.geomKey) if not cancel: self.form.buttonBox.removeButton( self.form.buttonBox.button(QDialogButtonBox.Cancel)) if buttons: for b in buttons: self.form.buttonBox.addButton(b, QDialogButtonBox.ActionRole) else: b = QPushButton(_("Add")) b.setShortcut(QKeySequence("Ctrl+N")) b.setToolTip(shortcut(_("Add New Deck (Ctrl+N)"))) self.form.buttonBox.addButton(b, QDialogButtonBox.ActionRole) b.clicked.connect(self.onAddDeck) if title: self.setWindowTitle(title) if not names: names = sorted(self.mw.col.decks.allNames(dyn=dyn)) self.nameFunc = None self.origNames = names else: self.nameFunc = names self.origNames = names() self.name = None self.ok = self.form.buttonBox.addButton(accept or _("Study"), QDialogButtonBox.AcceptRole) self.setWindowModality(Qt.WindowModal) self.form.buttonBox.helpRequested.connect(lambda: openHelp(help)) self.form.filter.textEdited.connect(self.redraw) self.form.list.itemDoubleClicked.connect(self.accept) self.show() # redraw after show so position at center correct self.redraw("", current) self.exec_()
def setupUI(self): mainLayout = QVBoxLayout() self.setLayout(mainLayout) # add widgets to set height and width widthLabel = QLabel('width') heightLabel = QLabel('height') self.widthEdit = QLineEdit(self) self.widthValidate = self.validate_label() self.heightValidate = self.validate_label() self.widthEdit.textEdited.connect( lambda i, v=self.widthValidate: self.onchange(i, v)) self.heightEdit = QLineEdit(self) self.heightEdit.textEdited.connect( lambda i, v=self.heightValidate: self.onchange(i, v)) self.attr2qt["width"] = self.widthEdit self.attr2qt["height"] = self.heightEdit wLayout = QHBoxLayout() wLayout.addWidget(widthLabel) wLayout.addWidget(self.widthEdit) hLayout = QHBoxLayout() hLayout.addWidget(heightLabel) hLayout.addWidget(self.heightEdit) sizeInputLayout = QHBoxLayout() sizeInputLayout.addLayout(wLayout) sizeInputLayout.addLayout(hLayout) labelLayout = QHBoxLayout() labelLayout.addWidget(self.widthValidate) labelLayout.addWidget(self.heightValidate) sizeLayout = QVBoxLayout() sizeLayout.addLayout(sizeInputLayout) sizeLayout.addLayout(labelLayout) # add final layout to main layout mainLayout.addLayout(sizeLayout) mainLayout.addWidget(self.hLine()) # add min- sizes and max- sizes if self.config["min-size"]: minWidthLabel = QLabel("min-width") minHeightLabel = QLabel("min-height") self.minWidthEdit = QLineEdit(self) self.minHeightEdit = QLineEdit(self) minLayout = QHBoxLayout() minLayout.addWidget(minWidthLabel) minLayout.addWidget(self.minWidthEdit) minLayout.addWidget(minHeightLabel) minLayout.addWidget(self.minHeightEdit) self.minWidthEdit.textEdited.connect( lambda i, v=self.widthValidate: self.onchange(i, v)) self.minHeightEdit.textEdited.connect( lambda i, v=self.heightValidate: self.onchange(i, v)) self.attr2qt["min-width"] = self.minWidthEdit self.attr2qt["min-height"] = self.minHeightEdit mainLayout.addLayout(minLayout) mainLayout.addWidget(self.hLine()) if self.config["max-size"]: maxWidthLabel = QLabel("max-width") maxHeightLabel = QLabel("max-height") self.maxWidthEdit = QLineEdit(self) self.maxHeightEdit = QLineEdit(self) maxLayout = QHBoxLayout() maxLayout.addWidget(maxWidthLabel) maxLayout.addWidget(self.maxWidthEdit) maxLayout.addWidget(maxHeightLabel) maxLayout.addWidget(self.maxHeightEdit) self.maxWidthEdit.textEdited.connect( lambda i, v=self.widthValidate: self.onchange(i, v)) self.maxHeightEdit.textEdited.connect( lambda i, v=self.heightValidate: self.onchange(i, v)) self.attr2qt["max-width"] = self.maxWidthEdit self.attr2qt["max-height"] = self.maxHeightEdit mainLayout.addLayout(maxLayout) mainLayout.addWidget(self.hLine()) # add widgets to show original width, height owidthLabel = QLabel('original width') oheightLabel = QLabel('original height') self.originalWidth = QLineEdit(self) self.originalHeight = QLineEdit(self) self.disableLineEdit(self.originalWidth) self.disableLineEdit(self.originalHeight) sizeLayout2 = QHBoxLayout() sizeLayout2.addWidget(owidthLabel) sizeLayout2.addWidget(self.originalWidth) sizeLayout2.addWidget(oheightLabel) sizeLayout2.addWidget(self.originalHeight) mainLayout.addLayout(sizeLayout2) # add Image Occlusion related buttons if self.is_occl: mainLayout.addWidget(self.hLine()) occlLabel = QLabel("Image Occlusion") occlLabel.setStyleSheet("QLabel {font-weight : bold;}") mainLayout.addWidget(occlLabel) occlAllNote = QCheckBox("Apply to all notes") self.occlAllNote = occlAllNote occlLayout = QHBoxLayout() occlLayout.addWidget(occlAllNote) self.attr2qt["Apply to all notes"] = self.occlAllNote if self.curr_fld in self.main.all_occl_flds: occlAllFld = QCheckBox("Apply to all fields") self.occlAllFld = occlAllFld occlLayout.addWidget(occlAllFld) self.attr2qt["Apply to all fields"] = self.occlAllFld mainLayout.addLayout(occlLayout) # add buttons okButton = QPushButton("OK") okButton.clicked.connect(self.clicked_ok) okButton.setDefault(True) okButton.setShortcut("Ctrl+Return") cancelButton = QPushButton("Cancel") cancelButton.clicked.connect(self.clicked_cancel) resetButton = QPushButton("Default") resetButton.clicked.connect(self.clicked_defaults) btnLayout = QHBoxLayout() btnLayout.addStretch(1) btnLayout.addWidget(okButton) btnLayout.addWidget(cancelButton) btnLayout.addWidget(resetButton) mainLayout.addLayout(btnLayout) self.setWindowTitle('Style Editor') self.show()