def promptText(parent, message, title = None, text="", rx=None, help=None): """ Prompts for a text. Returns None on cancel, otherwise the input string. rx = if given, regexp string that the input must validate against help = if given, the docbook id in the help menu handbook. """ d = KDialog(parent) buttons = KDialog.Ok | KDialog.Cancel if help: buttons |= KDialog.Help d.setHelp(help) d.setButtons(KDialog.ButtonCode(buttons)) if title: d.setCaption(title) v = KVBox() v.setSpacing(4) d.setMainWidget(v) QLabel(message, v) edit = KLineEdit(v) if rx: edit.setValidator(QRegExpValidator(QRegExp(rx), edit)) edit.setText(text) d.show() edit.setFocus() if d.exec_(): return edit.text()
def hyphenate(text, mainwindow): """ Ask the user which language to use. Returns None if the user cancels the dialog or no hyphenation pattern files could be found. """ if not hyphdicts: KMessageBox.sorry(mainwindow, i18n( "Could not find any hyphenation dictionaries.\n\n" "Please install a package containing some and/or or configure the " "search path to find them in the Frescobaldi settings under " "\"Paths.\"")) return conf = config("hyphenation") lang = conf.readEntry("lastused", "") langs = list(sorted(hyphdicts.keys())) index = lang in langs and langs.index(lang) or 0 d = KDialog(mainwindow) d.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel | KDialog.Help)) d.setCaption(i18n("Hyphenate Lyrics Text")) d.setHelp("lyrics") layout = QVBoxLayout() d.mainWidget().setLayout(layout) layout.addWidget(QLabel(i18n("Please select a language:"))) listbox = QListWidget() layout.addWidget(listbox) listbox.addItems(langs) listbox.setCurrentRow(index) listbox.setFocus() if d.exec_(): lang = langs[listbox.currentRow()] conf.writeEntry("lastused", lang) conf.sync() # get hyphenator h = Hyphenator(hyphdicts[lang]) return ly.rx.lyric_word.sub(lambda m: h.inserted(m.group(), ' -- '), text)