Example #1
0
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)
Example #2
0
 def editShortcut(self, name, title, icon=None, globalPos=None):
     """
     Shows a dialog to set a keyboard shortcut for a name (string).
     The title argument should contain a description for this action.
     """
     dlg = KDialog(self._manager.mainwin)
     dlg.setCaption(i18n("Configure Keyboard Shortcut"))
     dlg.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel))
     l = QGridLayout(dlg.mainWidget())
     l.setHorizontalSpacing(12)
     if icon:
         pic = QLabel()
         pic.setPixmap(icon.pixmap(22))
         l.addWidget(pic, 0, 0)
     l.addWidget(QLabel("<p>{0}<br /><b>{1}</b></p>".format(
         i18n("Press the button to configure the keyboard shortcut for:"), title)), 0, 1)
     key = KKeySequenceWidget()
     l.addWidget(key, 1, 1)
     self.keySetCheckActionCollections(key)
     self.keyLoadShortcut(key, name)
     if dlg.exec_():
         self.keySaveShortcut(key, name)