示例#1
0
 def edit(func):
     """ edit the selected text using chord_rest and a function """
     text = editor.selectedText()
     if text:
         # return the full match if the function did not return anything.
         def repl(m):
             result = func(m)
             if result is None:
                 return m.group()
             else:
                 return result
         editor.replaceSelectionWith(Res.chord_rest.sub(repl, text), True)
     else:
         sorry(_("Please select some text first."))
示例#2
0
    def writeSign(self, sign):
        if self.shorthands.isChecked() and sign in shorthands:
            art = '^-_'[self.direction.currentItem()] + shorthands[sign]
        else:
            art = ('^', '', '_')[self.direction.currentItem()] + '\\' + sign

        text = editor.selectedText()
        if text:
            def repl(m):
                if m.group('chord'):
                    return m.group('full') + art
                else:
                    return m.group()
            editor.replaceSelectionWith(Res.chord.sub(repl, text))
        else:
            editor.insertText(art)