def __init__(self, mainwindow): super(ScoreWizardDialog, self).__init__(mainwindow) self.addAction(mainwindow.actionCollection.help_whatsthis) self._pitchLanguage = None layout = QVBoxLayout() self.setLayout(layout) self.tabs = QTabWidget() b = self.dialogButtons = QDialogButtonBox() b.setStandardButtons( QDialogButtonBox.Reset | QDialogButtonBox.Ok | QDialogButtonBox.Cancel) b.accepted.connect(self.accept) b.rejected.connect(self.reject) help.addButton(b, scorewiz_help) b.button(QDialogButtonBox.Reset).clicked.connect(self.reset) self.previewButton = b.addButton('', QDialogButtonBox.ActionRole) self.previewButton.clicked.connect(self.showPreview) layout.addWidget(self.tabs) layout.addWidget(b) self.header = Header(self) self.tabs.addTab(self.header, '') self.parts = Parts(self) self.tabs.addTab(self.parts, '') self.settings = Settings(self) self.tabs.addTab(self.settings, '') self.tabs.setCurrentIndex(0) self.tabs.widget(0).widget() # activate it self.tabs.currentChanged.connect(self.slotCurrentChanged) util.saveDialogSize(self, "scorewiz/dialog/size") app.translateUI(self) self.accepted.connect(self.slotAccepted)
def __init__(self, parent=None): super(SessionEditor, self).__init__(parent) self.setWindowModality(Qt.WindowModal) layout = QVBoxLayout() self.setLayout(layout) grid = QGridLayout() layout.addLayout(grid) self.name = QLineEdit() self.nameLabel = l = QLabel() l.setBuddy(self.name) grid.addWidget(l, 0, 0) grid.addWidget(self.name, 0, 1) self.autosave = QCheckBox() grid.addWidget(self.autosave, 1, 1) self.basedir = widgets.urlrequester.UrlRequester() self.basedirLabel = l = QLabel() l.setBuddy(self.basedir) grid.addWidget(l, 2, 0) grid.addWidget(self.basedir, 2, 1) layout.addWidget(widgets.Separator()) self.buttons = b = QDialogButtonBox(self) layout.addWidget(b) b.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) b.accepted.connect(self.accept) b.rejected.connect(self.reject) help.addButton(b, "sessions") app.translateUI(self)
def __init__(self, widget, name, text=""): super(Edit, self).__init__(widget) self._name = name layout = QVBoxLayout() self.setLayout(layout) self.topLabel = QLabel() self.text = QTextEdit(cursorWidth=2, acceptRichText=False) self.titleLabel = QLabel() self.titleEntry = QLineEdit() self.shortcutLabel = QLabel() self.shortcutButton = QPushButton(icon=icons.get("preferences-desktop-keyboard-shortcuts"), clicked=self.editShortcuts) layout.addWidget(self.topLabel) layout.addWidget(self.text) grid = QGridLayout() layout.addLayout(grid) grid.addWidget(self.titleLabel, 0, 0) grid.addWidget(self.titleEntry, 0, 1) grid.addWidget(self.shortcutLabel, 1, 0) grid.addWidget(self.shortcutButton, 1, 1) layout.addWidget(widgets.Separator()) b = QDialogButtonBox(accepted=self.accept, rejected=self.reject) layout.addWidget(b) buttons = QDialogButtonBox.Ok | QDialogButtonBox.Cancel if name and name in builtin.builtin_snippets: b.setStandardButtons(buttons | QDialogButtonBox.RestoreDefaults) b.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.slotDefaults) else: b.setStandardButtons(buttons) help.addButton(b, snippet_edit_help) highlight.Highlighter(self.text.document()) Matcher(self.text) widgets.indenter.Indenter(self.text) self.text.installEventFilter(homekey.handler) completer.Completer(self.text) if name: self.titleEntry.setText(snippets.title(name, False) or '') self.text.setPlainText(snippets.text(name)) ac = self.parent().parent().snippetActions self.setShortcuts(ac.shortcuts(name)) else: self.text.setPlainText(text) self.setShortcuts(None) app.translateUI(self) self.readSettings() app.settingsChanged.connect(self.readSettings) qutil.saveDialogSize(self, "snippettool/editor/size", QSize(400, 300)) self.show()
def openEditor(self, item): import preferences.prefshelp dlg = widgets.dialog.TextDialog(None, _("Enter a regular expression to match:"), app.caption("Outline")) help.addButton(dlg.buttonBox(), preferences.prefshelp.preferences_tools_outline) dlg.setValidateFunction(is_regex) dlg.setText(item.text()) if dlg.exec_(): item.setText(dlg.text()) return True return False
def getText( parent = None, title = "", message = "", text = "", icon = None, help = None, validate = None, regexp = None, wordWrap = True, complete = None, ): """Asks a string of text from the user. Arguments: parent: parent widget or None title: dialog window title (without appname) message: message, question text: pre-entered text in the line edit icon: which icon to show help: help page or name validate: a function that accepts text and returns whether it is valid. regexp: a regular expression string. If given it provides an alternate validation method using a QRegExpValidator. wordWrap: whether to word-wrap the message text (default: True). complete: a string list or QAbstractItemModel to provide completions. """ dlg = widgets.dialog.TextDialog(parent, title=app.caption(title), message=message, icon=icon) dlg.setText(text) dlg.setMinimumWidth(320) dlg.messageLabel().setWordWrap(wordWrap) if help is not None: help_.addButton(dlg.buttonBox(), help) dlg.setWindowModality(Qt.WindowModal) else: dlg.setWindowModality(Qt.ApplicationModal) if regexp: dlg.setValidateRegExp(regexp) elif validate: dlg.setValidateFunction(validate) if complete: c = QCompleter(complete, dlg.lineEdit()) dlg.lineEdit().setCompleter(c) if dlg.exec_(): return dlg.text()
def __init__(self, mainwindow): super(SessionManagerDialog, self).__init__(mainwindow) self.setWindowModality(Qt.WindowModal) self.setWindowTitle(app.caption(_("Manage Sessions"))) layout = QVBoxLayout() self.setLayout(layout) self.sessions = SessionList(self) layout.addWidget(self.sessions) layout.addWidget(widgets.Separator()) self.buttons = b = QDialogButtonBox(self) layout.addWidget(b) b.setStandardButtons(QDialogButtonBox.Close) b.rejected.connect(self.accept) help.addButton(b, "sessions") self.sessions.load()
def __init__(self, parent=None): super(RestoreDialog, self).__init__(parent) self.messageLabel().setWordWrap(True) help.addButton(self.buttonBox(), widget.snippet_help) self.tree = QTreeWidget(headerHidden=True, rootIsDecorated=False) self.setMainWidget(self.tree) self.deletedItem = QTreeWidgetItem(self.tree) self.deletedItem.setFlags(Qt.ItemIsUserCheckable) self.changedItem = QTreeWidgetItem(self.tree) self.changedItem.setFlags(Qt.ItemIsUserCheckable) self.tree.itemChanged.connect(self.slotItemChanged) app.translateUI(self) app.languageChanged.connect(self.populate) self.accepted.connect(self.updateSnippets) qutil.saveDialogSize(self, "snippettool/restoredialog/size")
def __init__(self, parent=None): super(Dialog, self).__init__(parent) self._document = None self._path = None layout = QGridLayout() self.setLayout(layout) self.noartCheck = QCheckBox() self.norestCheck = QCheckBox() self.nolayoutCheck = QCheckBox() self.nobeamCheck = QCheckBox() self.commandLineLabel = QLabel() self.commandLine = QTextEdit(acceptRichText=False) self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel) help.addButton(self.buttons, help_importXML) layout.addWidget(self.noartCheck, 0, 0, 1, 2) layout.addWidget(self.norestCheck, 1, 0, 1, 2) layout.addWidget(self.nolayoutCheck, 2, 0, 1, 2) layout.addWidget(self.nobeamCheck, 3, 0, 1, 2) layout.addWidget(self.commandLineLabel, 4, 0, 1, 2) layout.addWidget(self.commandLine, 5, 0, 1, 2) layout.addWidget(widgets.Separator(), 6, 0, 1, 2) layout.addWidget(self.buttons, 7, 0, 1, 2) app.translateUI(self) qutil.saveDialogSize(self, "importXML/dialog/size", QSize(480, 260)) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.noartCheck.toggled.connect(self.makeCommandLine) self.norestCheck.toggled.connect(self.makeCommandLine) self.nolayoutCheck.toggled.connect(self.makeCommandLine) self.nobeamCheck.toggled.connect(self.makeCommandLine) self.makeCommandLine()
def __init__(self, mainwindow): super(HyphenDialog, self).__init__(mainwindow) self.setWindowModality(Qt.WindowModal) layout = QVBoxLayout() self.setLayout(layout) self.topLabel = QLabel() self.listWidget = QListWidget() layout.addWidget(self.topLabel) layout.addWidget(self.listWidget) layout.addWidget(widgets.Separator()) self.buttons = b = QDialogButtonBox() layout.addWidget(b) b.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) help.addButton(b, lyrics_help) b.rejected.connect(self.reject) b.accepted.connect(self.accept) self.load() app.translateUI(self) qutil.saveDialogSize(self, "hyphenation/dialog/size")
def load(filename, widget): """Loads snippets from a file, displaying them in a list. The user can then choose: - overwrite builtin snippets or not - overwrite own snippets with same title or not - select and view snippets contents. """ try: d = ET.parse(filename) elements = list(d.findall('snippet')) if not elements: raise ValueError(_("No snippets found.")) except Exception as e: QMessageBox.critical(widget, app.caption(_("Error")), _("Can't read from source:\n\n{url}\n\n{error}").format( url=filename, error=e)) return dlg = widgets.dialog.Dialog(widget) dlg.setWindowModality(Qt.WindowModal) dlg.setWindowTitle(app.caption(_("dialog title", "Import Snippets"))) tree = QTreeWidget(headerHidden=True, rootIsDecorated=False) dlg.setMainWidget(tree) help.addButton(dlg.buttonBox(), snippet_import_export_help) allnames = frozenset(snippets.names()) builtins = frozenset(builtin.builtin_snippets) titles = dict((snippets.title(n), n) for n in allnames if n not in builtins) new = QTreeWidgetItem(tree, [_("New Snippets")]) updated = QTreeWidgetItem(tree, [_("Updated Snippets")]) unchanged = QTreeWidgetItem(tree, [_("Unchanged Snippets")]) new.setFlags(Qt.ItemIsEnabled) updated.setFlags(Qt.ItemIsEnabled) unchanged.setFlags(Qt.ItemIsEnabled) new.setExpanded(True) updated.setExpanded(True) items = [] for snip in elements: item = QTreeWidgetItem() item.body = snip.find('body').text item.title = snip.find('title').text item.shortcuts = list(e.text for e in snip.findall('shortcuts/shortcut')) title = item.title or snippets.maketitle(snippets.parse(item.body).text) item.setText(0, title) name = snip.get('id') name = name if name in builtins else None # determine if new, updated or unchanged if not name: name = titles.get(title) item.name = name if not name or name not in allnames: new.addChild(item) items.append(item) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable) item.setCheckState(0, Qt.Checked) elif name: if (item.body != snippets.text(name) or title != snippets.title(name) or (item.shortcuts and item.shortcuts != [s.toString() for s in model.shortcuts(name) or ()])): updated.addChild(item) items.append(item) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable) item.setCheckState(0, Qt.Checked) else: unchanged.addChild(item) item.setFlags(Qt.ItemIsEnabled) # count: for i in new, updated, unchanged: i.setText(0, i.text(0) + " ({0})".format(i.childCount())) for i in new, updated: if i.childCount(): i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable) i.setCheckState(0, Qt.Checked) def changed(item): if item in (new, updated): for i in range(item.childCount()): c = item.child(i) c.setCheckState(0, item.checkState(0)) tree.itemChanged.connect(changed) importShortcuts = QTreeWidgetItem([_("Import Keyboard Shortcuts")]) if items: tree.addTopLevelItem(importShortcuts) importShortcuts.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable) importShortcuts.setCheckState(0, Qt.Checked) dlg.setMessage(_("Choose which snippets you want to import:")) else: dlg.setMessage(_("There are no new or updated snippets in the file.")) unchanged.setExpanded(True) tree.setWhatsThis(_( "<p>Here the snippets from {filename} are displayed.</p>\n" "<p>If there are new or updated snippets, you can select or deselect " "them one by one, or all at once, using the checkbox of the group. " "Then click OK to import all the selected snippets.</p>\n" "<p>Existing, unchanged snippets can't be imported.</p>\n" ).format(filename=os.path.basename(filename))) qutil.saveDialogSize(dlg, "snippettool/import/size", QSize(400, 300)) if not dlg.exec_() or not items: return ac = model.collection() m = model.model() with qutil.busyCursor(): for i in items: if i.checkState(0) == Qt.Checked: index = m.saveSnippet(i.name, i.body, i.title) if i.shortcuts and importShortcuts.checkState(0): shortcuts = list(map(QKeySequence.fromString, i.shortcuts)) ac.setShortcuts(m.name(index), shortcuts) widget.updateColumnSizes()
def __init__(self, parent=None): super(Dialog, self).__init__(parent) self._document = None layout = QGridLayout() self.setLayout(layout) self.versionLabel = QLabel() self.versionCombo = QComboBox() self.outputLabel = QLabel() self.outputCombo = QComboBox() self.resolutionLabel = QLabel() self.resolutionCombo = QComboBox(editable=True) self.previewCheck = QCheckBox() self.verboseCheck = QCheckBox() self.englishCheck = QCheckBox() self.deleteCheck = QCheckBox() self.commandLineLabel = QLabel() self.commandLine = QTextEdit(acceptRichText=False) self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.buttons.button(QDialogButtonBox.Ok).setIcon(icons.get("lilypond-run")) help.addButton(self.buttons, help_engrave_custom) self.resolutionCombo.addItems(['100', '200', '300', '600', '1200']) self.resolutionCombo.setCurrentIndex(2) layout.addWidget(self.versionLabel, 0, 0) layout.addWidget(self.versionCombo, 0, 1) layout.addWidget(self.outputLabel, 1, 0) layout.addWidget(self.outputCombo, 1, 1) layout.addWidget(self.resolutionLabel, 2, 0) layout.addWidget(self.resolutionCombo, 2, 1) layout.addWidget(self.previewCheck, 3, 0, 1, 2) layout.addWidget(self.verboseCheck, 4, 0, 1, 2) layout.addWidget(self.englishCheck, 5, 0, 1, 2) layout.addWidget(self.deleteCheck, 6, 0, 1, 2) layout.addWidget(self.commandLineLabel, 7, 0, 1, 2) layout.addWidget(self.commandLine, 8, 0, 1, 2) layout.addWidget(widgets.Separator(), 9, 0, 1, 2) layout.addWidget(self.buttons, 10, 0, 1, 2) app.translateUI(self) util.saveDialogSize(self, "engrave/custom/dialog/size", QSize(480, 260)) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) model = listmodel.ListModel(formats, display=lambda f: f.title(), icon=lambda f: icons.file_type(f.type)) self.outputCombo.setModel(model) s = QSettings() s.beginGroup("lilypond_settings") self.englishCheck.setChecked( s.value("no_translation", False) in (True, "true")) self.deleteCheck.setChecked( s.value("delete_intermediate_files", True) not in (False, "false")) self.loadLilyPondVersions() self.selectLilyPondInfo(lilypondinfo.preferred()) app.settingsChanged.connect(self.loadLilyPondVersions) app.jobFinished.connect(self.slotJobFinished) self.outputCombo.currentIndexChanged.connect(self.makeCommandLine) self.previewCheck.toggled.connect(self.makeCommandLine) self.verboseCheck.toggled.connect(self.makeCommandLine) self.deleteCheck.toggled.connect(self.makeCommandLine) self.resolutionCombo.editTextChanged.connect(self.makeCommandLine) self.makeCommandLine()