Beispiel #1
0
 def load(self, url=None, encoding=None, keepUndo=False):
     """Load the specified or current url (if None was specified).
     
     Currently only local files are supported. An IOError is raised
     when trying to load a nonlocal URL.
     
     If loading succeeds and an url was specified, the url is make the
     current url (by calling setUrl() internally).
     
     If keepUndo is True, the loading can be undone (with Ctrl-Z).
     
     """
     if url is None:
         url = QUrl()
     u = url if not url.isEmpty() else self.url()
     text = self.load_data(u, encoding or self._encoding)
     if keepUndo:
         c = QTextCursor(self)
         c.select(QTextCursor.Document)
         c.insertText(text)
     else:
         self.setPlainText(text)
     self.setModified(False)
     if not url.isEmpty():
         self.setUrl(url)
     self.loaded()
     app.documentLoaded(self)
Beispiel #2
0
    def drawContents(self, painter):
        """
        Reimplementation of drawContents to limit the drawing
        inside `textRext`.

        """
        painter.setPen(self.__color)
        painter.setFont(self.font())

        if self.__textRect:
            rect = self.__textRect
        else:
            rect = self.rect().adjusted(5, 5, -5, -5)
        if Qt.mightBeRichText(self.__message):
            doc = QTextDocument()
            doc.setHtml(self.__message)
            doc.setTextWidth(rect.width())
            cursor = QTextCursor(doc)
            cursor.select(QTextCursor.Document)
            fmt = QTextBlockFormat()
            fmt.setAlignment(self.__alignment)
            cursor.mergeBlockFormat(fmt)
            painter.save()
            painter.translate(rect.topLeft())
            doc.drawContents(painter)
            painter.restore()
        else:
            painter.drawText(rect, self.__alignment, self.__message)
Beispiel #3
0
 def load(self, url=None, encoding=None, keepUndo=False):
     """Load the specified or current url (if None was specified).
     
     Currently only local files are supported. An IOError is raised
     when trying to load a nonlocal URL.
     
     If loading succeeds and an url was specified, the url is make the
     current url (by calling setUrl() internally).
     
     If keepUndo is True, the loading can be undone (with Ctrl-Z).
     
     """
     if url is None:
         url = QUrl()
     u = url if not url.isEmpty() else self.url()
     text = self.load_data(u, encoding or self._encoding)
     if keepUndo:
         c = QTextCursor(self)
         c.select(QTextCursor.Document)
         c.insertText(text)
     else:
         self.setPlainText(text)
     self.setModified(False)
     if not url.isEmpty():
         self.setUrl(url)
     self.loaded()
     app.documentLoaded(self)
Beispiel #4
0
    def drawContents(self, painter):
        """
        Reimplementation of drawContents to limit the drawing
        inside `textRext`.

        """
        painter.setPen(self.__color)
        painter.setFont(self.font())

        if self.__textRect:
            rect = self.__textRect
        else:
            rect = self.rect().adjusted(5, 5, -5, -5)
        if Qt.mightBeRichText(self.__message):
            doc = QTextDocument()
            doc.setHtml(self.__message)
            doc.setTextWidth(rect.width())
            cursor = QTextCursor(doc)
            cursor.select(QTextCursor.Document)
            fmt = QTextBlockFormat()
            fmt.setAlignment(self.__alignment)
            cursor.mergeBlockFormat(fmt)
            painter.save()
            painter.translate(rect.topLeft())
            doc.drawContents(painter)
            painter.restore()
        else:
            painter.drawText(rect, self.__alignment, self.__message)
Beispiel #5
0
    def postImport(self, settings, doc):
        """Adaptations of the source after running musicxml2ly
		
		Present settings: 
		Reformat source
        Remove superfluous durations
        Remove duration scaling
        Engrave directly
		
        """
        cursor = QTextCursor(doc)
        if settings[0]:
            import reformat

            reformat.reformat(cursor)
        if settings[1]:
            cursor.select(QTextCursor.Document)
            from rhythm import rhythm

            rhythm.rhythm_implicit_per_line(cursor)
        if settings[2]:
            cursor.select(QTextCursor.Document)
            from rhythm import rhythm

            rhythm.rhythm_remove_fraction_scaling(cursor)
        if settings[3]:
            import engrave

            engrave.engraver(self.mainwindow()).engrave("preview", doc, False)
Beispiel #6
0
 def load(self, keepUndo=False):
     """Loads the current url.
     
     Returns True if loading succeeded, False if an error occurred,
     and None when the current url is empty or non-local.
     Currently only local files are supported.
     
     If keepUndo is True, the loading can be undone (with Ctrl-Z).
     
     """
     fileName = self.url().toLocalFile()
     if fileName:
         try:
             with open(fileName) as f:
                 data = f.read()
         except (IOError, OSError):
             return False # errors are caught in MainWindow.openUrl()
         text = util.decode(data)
         if keepUndo:
             c = QTextCursor(self)
             c.select(QTextCursor.Document)
             c.insertText(text)
         else:
             self.setPlainText(text)
         self.setModified(False)
         self.loaded()
         app.documentLoaded(self)
         return True
    def highlightHorizontalLine(self, text, cursor, bf, strt):
        found = False
        for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['HR'],text):
            prevBlock = self.currentBlock().previous()
            prevCursor = QTextCursor(prevBlock)
            prev = prevBlock.text()
            prevAscii = str(prev.replace(u'\u2029','\n'))
            if prevAscii.strip():
                #print "Its a header"
                prevCursor.select(QTextCursor.LineUnderCursor)
                #prevCursor.setCharFormat(self.MARKDOWN_KWS_FORMAT['Header'])
                formatRange = QTextLayout.FormatRange()
                formatRange.format = self.MARKDOWN_KWS_FORMAT['Header']
                formatRange.length = prevCursor.block().length()
                formatRange.start = 0
                prevCursor.block().layout().setAdditionalFormats([formatRange])
            self.setFormat(mo.start()+strt, mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['HR'])

        for mo in re.finditer(self.MARKDOWN_KEYS_REGEX['eHR'],text):
            prevBlock = self.currentBlock().previous()
            prevCursor = QTextCursor(prevBlock)
            prev = prevBlock.text()
            prevAscii = str(prev.replace(u'\u2029','\n'))
            if prevAscii.strip():
                #print "Its a header"
                prevCursor.select(QTextCursor.LineUnderCursor)
                #prevCursor.setCharFormat(self.MARKDOWN_KWS_FORMAT['Header'])
                formatRange = QTextLayout.FormatRange()
                formatRange.format = self.MARKDOWN_KWS_FORMAT['Header']
                formatRange.length = prevCursor.block().length()
                formatRange.start = 0
                prevCursor.block().layout().setAdditionalFormats([formatRange])
            self.setFormat(mo.start()+strt, mo.end() - mo.start(), self.MARKDOWN_KWS_FORMAT['HR'])
        return found
Beispiel #8
0
    def postImport(self, settings, doc):
        """Adaptations of the source after running musicxml2ly
		
		Present settings: 
		Reformat source
        Remove superfluous durations
        Remove duration scaling
        Engrave directly
		
        """
        cursor = QTextCursor(doc)
        if settings[0]:
            import reformat
            reformat.reformat(cursor)
        if settings[1]:
            cursor.select(QTextCursor.Document)
            from rhythm import rhythm
            rhythm.rhythm_implicit_per_line(cursor)
        if settings[2]:
            cursor.select(QTextCursor.Document)
            from rhythm import rhythm
            rhythm.rhythm_remove_fraction_scaling(cursor)
        if settings[3]:
            import engrave
            engrave.engraver(self.mainwindow()).engrave('preview', doc, False)
Beispiel #9
0
 def load(self, keepUndo=False):
     """Loads the current url.
     
     Returns True if loading succeeded, False if an error occurred,
     and None when the current url is empty or non-local.
     Currently only local files are supported.
     
     If keepUndo is True, the loading can be undone (with Ctrl-Z).
     
     """
     fileName = self.url().toLocalFile()
     if fileName:
         try:
             with open(fileName) as f:
                 data = f.read()
         except (IOError, OSError):
             return False # errors are caught in MainWindow.openUrl()
         text = util.decode(data)
         if keepUndo:
             c = QTextCursor(self)
             c.select(QTextCursor.Document)
             c.insertText(text)
         else:
             self.setPlainText(text)
         self.setModified(False)
         self.loaded()
         app.documentLoaded(self)
         return True
Beispiel #10
0
 def is_cell_separator(self, cursor=None, block=None):
     """Return True if cursor (or text block) is on a block separator"""
     assert cursor is not None or block is not None
     if cursor is not None:
         cursor0 = QTextCursor(cursor)
         cursor0.select(QTextCursor.BlockUnderCursor)
         text = to_text_string(cursor0.selectedText())
     else:
         text = to_text_string(block.text())
     return text.lstrip().startswith(self.CELL_SEPARATORS)
Beispiel #11
0
 def is_cell_separator(self, cursor=None, block=None):
     """Return True if cursor (or text block) is on a block separator"""
     assert cursor is not None or block is not None
     if cursor is not None:
         cursor0 = QTextCursor(cursor)
         cursor0.select(QTextCursor.BlockUnderCursor)
         text = to_text_string(cursor0.selectedText())
     else:
         text = to_text_string(block.text())
     return text.lstrip().startswith(self.CELL_SEPARATORS)
Beispiel #12
0
    def add_debug_message(self, message):
        self.text_debug.append(message)

        while self.text_debug.document().blockCount() > 1000:
            cursor = QTextCursor(self.text_debug.document().begin())
            cursor.select(QTextCursor.BlockUnderCursor)
            cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
            cursor.removeSelectedText()

        if self.checkbox_debug_auto_scroll.isChecked():
            self.text_debug.verticalScrollBar().setValue(self.text_debug.verticalScrollBar().maximum())
Beispiel #13
0
    def add_debug_message(self, message):
        self.text_debug.append(message)

        while self.text_debug.document().blockCount() > 1000:
            cursor = QTextCursor(self.text_debug.document().begin())
            cursor.select(QTextCursor.BlockUnderCursor)
            cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
            cursor.removeSelectedText()

        if self.checkbox_debug_auto_scroll.isChecked():
            self.text_debug.verticalScrollBar().setValue(self.text_debug.verticalScrollBar().maximum())
Beispiel #14
0
 def selectFoundText(self, cursor: QTextCursor):
     print(cursor.selectedText())
     cursor.select(QTextCursor.WordUnderCursor)