def mediaChange(self, medium, drive): msg = _("Please insert '%s' into the drive '%s'") % (medium, drive) #change = QMessageBox.question(None, _("Media Change"), msg, QMessageBox.Ok, QMessageBox.Cancel) change = KMessageBox.questionYesNo(None, _("Media Change"), _("Media Change") + "<br>" + msg, KStandardGuiItem.ok(), KStandardGuiItem.cancel()) if change == KMessageBox.Yes: return True return False
def slotOptimiseDatabase(self): self.loadDatabaseBuilder() dbBuild = self.renderThread.getObjectInstance(build.DatabaseBuilder) if dbBuild.isOptimizable(): if KMessageBox.warningContinueCancel(self, i18n("This operation might take some time."), i18n("Optimise Database"), KStandardGuiItem.cont(), KStandardGuiItem.cancel(), 'database_optimise') \ == KMessageBox.Continue: QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) self.currentJob = self.renderThread.enqueue( build.DatabaseBuilder, 'optimize')
def installDictionary(self): if self.currentDictionary in self.dictionaryHasNewer \ and not self.dictionaryHasNewer[self.currentDictionary] \ and KMessageBox.warningContinueCancel(self, i18n("Local version is already up-to-date.\n\nInstall anyway?"), i18n("Reinstall"), KStandardGuiItem.cont(), KStandardGuiItem.cancel(), 'reinstall_confirmation') \ == KMessageBox.Cancel: return downloader = self.getDownloader(self.currentDictionary) link = downloader.getDownloadLink() if not link: self.statusLabel.setText(i18n('Error getting download page "%1"', downloader.lastError)) return self.statusLabel.setText(i18n('Downloading from %1...', link)) self.checkVersionButton.setEnabled(False) self.dictionaryCombo.setEnabled(False) self.removeButton.setEnabled(False) self.installButton.setEnabled(False) self.setWorking(True) filePath, fileType = downloader.download() if filePath: self.statusLabel.setText(i18n('Installing...', link)) dbBuild = self.renderThread.getObjectInstance(build.DatabaseBuilder) builderClass = dbBuild.getTableBuilder(self.currentDictionary) dbBuild.setBuilderOptions(builderClass, {'filePath': unicode(filePath), 'fileType': unicode(fileType)}) tables = [self.currentDictionary] # look for related tables and install them, too relatedKey = self.currentDictionary + '_related' if relatedKey in EclectusCommandLineBuilder.BUILD_GROUPS: tables.extend( EclectusCommandLineBuilder.BUILD_GROUPS[relatedKey]) # TODO UpdateVersion might be installed later # TODO if for the first time a new language is installed check if # tables in BUILD_GROUPS (zh-cmn, ja) need to be installed self.currentJob = self.renderThread.enqueue(build.DatabaseBuilder, 'build', tables) else: self.statusLabel.setText(i18n('Error downloading from "%1": "%2"', link, downloader.lastError)) self.dictionaryCombo.setEnabled(True) self.setWorking(False)
def mediaChange(self, medium, drive): msg = _("Please insert '%s' into the drive '%s'") % (medium, drive) if type(PYQT_VERSION) == int: change = QMessageBox.question(None, _("Media Change"), msg, QMessageBox.Ok, QMessageBox.Cancel) if change == QMessageBox.Ok: return True else: change = KMessageBox.questionYesNo(None, _("Media Change"), _("Media Change") + "<br>" + msg, KStandardGuiItem.ok(), KStandardGuiItem.cancel()) if change == KMessageBox.Yes: return True return False
def __init__(self, mainwin, pdfs): KDialog.__init__(self, mainwin) self.mainwin = mainwin self.setAttribute(Qt.WA_DeleteOnClose) self.setButtons(KDialog.ButtonCode( KDialog.User1 | KDialog.Ok | KDialog.Cancel)) self.setButtonGuiItem(KDialog.Ok, KStandardGuiItem.print_()) self.setButtonIcon(KDialog.User1, KIcon("edit-select-all")) self.setButtonText(KDialog.User1, i18n("Select all")) self.setCaption(i18n("Print documents")) b = KVBox(self) b.setSpacing(4) QLabel(i18n("Please select the files you want to print:"), b) fileList = QListWidget(b) fileList.setIconSize(QSize(22, 22)) fileList.setWhatsThis(i18n( "These are the PDF documents that are up-to-date (i.e. newer than " "the LilyPond source document). " "Check the documents you want to send to the printer.")) for pdf in pdfs: i = QListWidgetItem(KIcon("application-pdf"), os.path.basename(pdf), fileList) i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable) i.setCheckState(Qt.Unchecked) fileList.item(0).setCheckState(Qt.Checked) self.fileList = fileList self.setMainWidget(b) self.resize(350, 200) self.pdfs = pdfs self.user1Clicked.connect(self.selectAll)
def queryClose(self): """Ask user if document modified and saves if desired.""" # Many stuff copied from KatePart if not self.doc or not self.isModified(): return True res = KMessageBox.warningYesNoCancel(self.app.mainwin, i18n( "The document \"%1\" has been modified.\n" "Do you want to save your changes or discard them?", self.documentName()), i18n("Close Document"), KStandardGuiItem.save(), KStandardGuiItem.discard()) if res == KMessageBox.Yes: self.save() elif res == KMessageBox.No: return True else: # cancel return False
def __init__(self, *args, **kwargs): QWidget.__init__(self, *args, **kwargs) layout = QGridLayout(self) self.setLayout(layout) self.addButton = KPushButton(KStandardGuiItem.add()) self.editButton = KPushButton(KStandardGuiItem.configure()) self.removeButton = KPushButton(KStandardGuiItem.remove()) self.listBox = QListWidget() layout.setContentsMargins(1, 1, 1, 1) layout.setSpacing(0) layout.addWidget(self.listBox, 0, 0, 4, 1) layout.addWidget(self.addButton, 0, 1) layout.addWidget(self.editButton, 1, 1) layout.addWidget(self.removeButton, 2, 1) @self.addButton.clicked.connect def addClicked(): item = self.createItem() if self.openEditor(item): self.addItem(item) @self.editButton.clicked.connect def editClicked(): item = self.listBox.currentItem() item and self.editItem(item) @self.removeButton.clicked.connect def removeClicked(): item = self.listBox.currentItem() if item: self.removeItem(item) @self.listBox.itemDoubleClicked.connect def itemDoubleClicked(item): item and self.editItem(item) self.listBox.model().layoutChanged.connect(self.changed) def updateSelection(): selected = bool(self.listBox.currentItem()) self.editButton.setEnabled(selected) self.removeButton.setEnabled(selected) self.changed.connect(updateSelection) self.listBox.itemSelectionChanged.connect(updateSelection) updateSelection()
def validate(self): """Checks if the input is acceptable. If this method returns True, the dialog is accepted when OK is clicked. Otherwise a messagebox could be displayed, and the dialog will remain visible. """ # strip off whitespace name = self.name.text().strip() self.name.setText(name) if not name: self.setCurrentPage(self.firstPage) self.name.setFocus() KMessageBox.error(self, i18n("Please enter a session name.")) if self._originalName: self.name.setText(self._originalName) return False if name == 'none': self.setCurrentPage(self.firstPage) self.name.setFocus() KMessageBox.error(self, i18n( "Please do not use the name '%1'.", "none")) return False if '&' in name: self.setCurrentPage(self.firstPage) self.name.setFocus() KMessageBox.error(self, i18n( "Please do not use the ampersand (&) character " "in a session name.")) return False if self._originalName != name and name in self.sm.names(): self.setCurrentPage(self.firstPage) self.name.setFocus() if KMessageBox.warningContinueCancel(self, i18n( "Another session with the name %1 exists already.\n\n" "Do you want to overwrite it?", name), None, KStandardGuiItem.overwrite(), KStandardGuiItem.cancel(), "session_overwrite") == KMessageBox.Cancel: return False return True
def __init__(self, dialog): QWidget.__init__(self, dialog) SymbolManager.__init__(self) self.setDefaultSymbolSize(40) self.dialog = dialog self.setLayout(QGridLayout()) self.tree = QTreeWidget() self.stack = QStackedWidget() StackFader(self.stack) self.systems = QSpinBox() newStaves = QVBoxLayout() operations = QHBoxLayout() self.layout().addLayout(newStaves, 0, 0) self.layout().addWidget(self.tree, 0, 1) self.layout().addWidget(self.stack, 0, 2, 1, 2) self.layout().addWidget(self.systems, 1, 3) self.systems.setRange(1, 64) l = QLabel(i18n("Systems per page:")) l.setBuddy(self.systems) self.layout().addWidget(l, 1, 2, Qt.AlignRight) self.layout().addLayout(operations, 1, 1) operations.setSpacing(0) operations.setContentsMargins(0, 0, 0, 0) removeButton = KPushButton(KStandardGuiItem.remove()) removeButton.clicked.connect(self.removeSelectedItems) operations.addWidget(removeButton) upButton = QToolButton() upButton.clicked.connect(self.moveSelectedItemsUp) upButton.setIcon(KIcon("go-up")) operations.addWidget(upButton) downButton = QToolButton() downButton.clicked.connect(self.moveSelectedItemsDown) downButton.setIcon(KIcon("go-down")) operations.addWidget(downButton) newStaves.setSpacing(0) newStaves.setContentsMargins(0, 0, 0, 0) self.tree.setIconSize(QSize(32, 32)) self.tree.setDragDropMode(QTreeWidget.InternalMove) self.tree.headerItem().setHidden(True) self.tree.itemSelectionChanged.connect(self.slotSelectionChanged) for staffType in ( BracketItem, BraceItem, StaffItem, ): b = QPushButton(staffType.name()) b.clicked.connect((lambda t: lambda: self.createItem(t))(staffType)) b.setIconSize(QSize(40, 40)) self.addSymbol(b, staffType.symbol()) newStaves.addWidget(b)
def __getGuiItem(button): """ Private function to create a KGuiItem for a button. @param button flag indicating the button (QMessageBox.StandardButton) @return item for the button (KGuiItem) """ if button == QMessageBox.Ok: return KStandardGuiItem.ok() elif button == QMessageBox.Cancel: return KStandardGuiItem.cancel() elif button == QMessageBox.Yes: return KStandardGuiItem.yes() elif button == QMessageBox.No: return KStandardGuiItem.no() elif button == QMessageBox.Discard: return KStandardGuiItem.discard() elif button == QMessageBox.Save: return KStandardGuiItem.save() elif button == QMessageBox.Apply: return KStandardGuiItem.apply() elif button == QMessageBox.Help: return KStandardGuiItem.help() elif button == QMessageBox.Close: return KStandardGuiItem.close() elif button == QMessageBox.Open: return KStandardGuiItem.open() elif button == QMessageBox.Reset: return KStandardGuiItem.reset() elif button == QMessageBox.Ignore: return KGuiItem(QCoreApplication.translate("KQMessageBox", "Ignore")) elif button == QMessageBox.Abort: return KGuiItem(QCoreApplication.translate("KQMessageBox", "Abort")) elif button == QMessageBox.RestoreDefaults: return KGuiItem(QCoreApplication.translate("KQMessageBox", "Restore Defaults")) elif button == QMessageBox.SaveAll: return KGuiItem(QCoreApplication.translate("KQMessageBox", "Save All")) elif button == QMessageBox.YesToAll: return KGuiItem(QCoreApplication.translate("KQMessageBox", "Yes to &All")) elif button == QMessageBox.NoToAll: return KGuiItem(QCoreApplication.translate("KQMessageBox", "N&o to All")) elif button == QMessageBox.Retry: return KGuiItem(QCoreApplication.translate("KQMessageBox", "Retry")) elif button == QMessageBox.NoButton: return KGuiItem() else: return KStandardGuiItem.ok()
def addContextMenuActions(self, menu): a = menu.addAction(KIcon("edit-copy"), i18n("&Copy")) a.triggered.connect(self.copyLog) g = KStandardGuiItem.saveAs() a = menu.addAction(g.icon(), g.text()) a.triggered.connect(self.saveLogAs)
def __init__(self, parent): QSplitter.__init__(self, parent) parent.addPage(self, i18n("Parts")) # The part types overview widget. v = KVBox() self.addWidget(v) QLabel('<b>{0}</b>'.format(i18n("Available parts:")), v) allParts = QTreeWidget(v) addButton = KPushButton(KStandardGuiItem.add(), v) addButton.setToolTip(i18n("Add selected part to your score.")) # The listbox with selected parts v = KVBox() self.addWidget(v) QLabel('<b>{0}</b>'.format(i18n("Score:")), v) score = QListWidget(v) self.score = score # so the partList method can find us h = KHBox(v) removeButton = KPushButton(KStandardGuiItem.remove(), h) upButton = QToolButton(h) upButton.setIcon(KIcon("go-up")) downButton = QToolButton(h) downButton.setIcon(KIcon("go-down")) # The StackedWidget with settings partSettings = QStackedWidget() self.addWidget(partSettings) self.setStretchFactor(0, 1) self.setStretchFactor(1, 1) self.setStretchFactor(2, 1) self.setSizes((100, 100, 100)) allParts.setSelectionMode(QTreeWidget.ExtendedSelection) allParts.setRootIsDecorated(False) allParts.headerItem().setHidden(True) score.setSelectionMode(QListWidget.ExtendedSelection) score.setDragDropMode(QListWidget.InternalMove) class PartItem(QListWidgetItem): """ A part from the score, instantiating a config widget as well. """ def __init__(self, partClass): name = partClass.name() # partClass.name is a ki18n object QListWidgetItem.__init__(self, name, score) self.w = QGroupBox(name) partSettings.addWidget(self.w) self.part = partClass() layout = QVBoxLayout(self.w) self.part.widgets(layout) layout.addStretch(1) if score.count() == 1: score.setCurrentRow(0) self.setSelected(True) parent.enableButton(KPageDialog.Try, True) def showSettingsWidget(self): partSettings.setCurrentWidget(self.w) def remove(self): if score.count() == 1: parent.enableButton(KPageDialog.Try, False) sip.delete(self.w) sip.delete(self) # TODO: check if necessary @allParts.itemDoubleClicked.connect def addPart(item, col): if hasattr(item, "partClass"): PartItem(item.partClass) @allParts.itemClicked.connect def toggleExpand(item, col): item.setExpanded(not item.isExpanded()) @addButton.clicked.connect def addSelectedParts(): for item in allParts.selectedItems(): PartItem(item.partClass) @removeButton.clicked.connect def removeSelectedParts(): for item in score.selectedItems(): item.remove() def keepSel(func): """ Restore the selection and current element after reordering parts. """ def decorator(): selItems = score.selectedItems() curItem = score.currentItem() func() score.setCurrentItem(curItem) for i in selItems: i.setSelected(True) return decorator @upButton.clicked.connect @keepSel def moveUp(): """ Move selected parts up. """ for row in range(1, score.count()): if score.item(row).isSelected(): item = score.takeItem(row) score.insertItem(row - 1, item) @downButton.clicked.connect @keepSel def moveDown(): """ Move selected parts down. """ for row in range(score.count() - 1, -1, -1): if score.item(row).isSelected(): item = score.takeItem(row) score.insertItem(row + 1, item) @score.currentItemChanged.connect def showItem(cur, prev): if cur: cur.showSettingsWidget() from frescobaldi_app.scorewiz.parts import categories for name, parts in categories(): group = QTreeWidgetItem(allParts, [name]) group.setFlags(Qt.ItemIsEnabled) group.setIcon(0, KIcon("inode-directory")) for part in parts: p = QTreeWidgetItem(group, [part.name()]) p.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) p.partClass = part
def __init__(self, manager): self.manager = manager KDialog.__init__(self, manager.mainwin) self.setCaption(i18n("Expansion Manager")) self.setButtons(KDialog.ButtonCode( KDialog.Help | KDialog.Ok | KDialog.Close | KDialog.User1 | KDialog.User2 )) self.setButtonGuiItem(KDialog.User1, KStandardGuiItem.remove()) self.setButtonGuiItem(KDialog.User2, KStandardGuiItem.add()) self.setHelp("expand") layout = QVBoxLayout(self.mainWidget()) layout.setContentsMargins(0, 0, 0, 0) search = KTreeWidgetSearchLine() search.setClickMessage(i18n("Search...")) layout.addWidget(search) splitter = QSplitter() splitter.setOrientation(Qt.Vertical) layout.addWidget(splitter) tree = QTreeWidget() tree.setColumnCount(3) tree.setHeaderLabels((i18n("Name"), i18n("Description"), i18n("Shortcut"))) tree.setRootIsDecorated(False) tree.setAllColumnsShowFocus(True) search.setTreeWidget(tree) splitter.addWidget(tree) box = KVBox() splitter.addWidget(box) key = KKeySequenceWidget(box) key.layout().setContentsMargins(0, 0, 0, 0) key.layout().insertStretch(0, 1) key.setEnabled(False) edit = QTextEdit(box) edit.setAcceptRichText(False) edit.setStyleSheet("QTextEdit { font-family: monospace; }") edit.item = None edit.dirty = False ExpandHighlighter(edit.document()) # whats this etc. tree.setWhatsThis(i18n( "This is the list of defined expansions.\n\n" "Click on a row to see or change the associated text. " "Doubleclick a shortcut or its description to change it. " "You can also press F2 to edit the current shortcut.\n\n" "Use the buttons below to add or remove expansions.\n\n" "There are two ways to use the expansion: either type the " "shortcut in the text and then call the Expand function, or " "just call the Expand function (default shortcut: Ctrl+.), " "choose the expansion from the list and press Enter or click Ok." )) edit.setWhatsThis( "<html><head><style type='text/css'>" "td.short {{ font-family: monospace; font-weight: bold; }}" "</style></head><body>" "<p>{0}</p><table border=0 width=300 cellspacing=2><tbody>" "<tr><td class=short align=center>(|)</td><td>{1}</td></tr>" "<tr><td class=short align=center>@</td><td>{2}</td></tr>" "</tbody></table></body></html>".format( i18n("This is the text associated with the selected shortcut. " "Some characters have special meaning:"), i18n("Place the cursor on this spot."), i18n("Translate the following pitch."), )) self.searchLine = search self.treeWidget = tree self.key = key self.edit = edit self.restoreDialogSize(config()) # load the expansions for name in sorted(self.manager.expansionsList()): self.createItem(name, self.manager.description(name)) tree.sortByColumn(1, Qt.AscendingOrder) tree.setSortingEnabled(True) tree.resizeColumnToContents(1) self.user1Clicked.connect(self.removeItem) self.user2Clicked.connect(self.addItem) edit.textChanged.connect(self.editChanged) search.textChanged.connect(self.checkMatch) tree.itemSelectionChanged.connect(self.updateSelection) tree.itemChanged.connect(self.itemChanged, Qt.QueuedConnection) key.keySequenceChanged.connect(self.keySequenceChanged)