def _insertAnchors(self, cursor, plainText, matcher, hrefFunc): for start, end, matcher in self._iterMatchedRanges(matcher, plainText): cursor.setPosition(start); cursor.setPosition(end, QTextCursor.KeepAnchor) fmt = QTextCharFormat() fmt.setAnchor(True) fmt.setAnchorHref(hrefFunc(matcher.cap())) cursor.mergeCharFormat(fmt)
def writeMessage(self, message, type): """This writes both status and output messages to the log. For output messages also the correct encoding is re-applied: LilyPond writes filenames out in the system's filesystemencoding, while the messages are always written in UTF-8 encoding... """ if type == job.STDERR: # find filenames in message: parts = iter(errors.message_re.split(message.encode("latin1"))) msg = next(parts).decode("utf-8", "replace") self.cursor.insertText(msg, self.textFormat(type)) enc = sys.getfilesystemencoding() for url, path, line, col, msg in zip(*itertools.repeat(parts, 5)): url = url.decode(enc) path = path.decode(enc) msg = msg.decode("utf-8", "replace") if self._rawView: fmt = QTextCharFormat(self.textFormat(type)) display_url = url else: fmt = QTextCharFormat(self.textFormat("link")) display_url = os.path.basename(path) fmt.setAnchor(True) fmt.setAnchorHref(str(len(self._errors))) fmt.setToolTip(_("Click to edit this file")) pos = self.cursor.position() self.cursor.insertText(display_url, fmt) self.cursor.insertText(msg, self.textFormat(type)) self._errors.append((pos, self.cursor.position(), url)) else: if type == job.STDOUT: message = message.encode("latin1").decode("utf-8") super(LogWidget, self).writeMessage(message, type)
def writeMessage(self, message, type): """This writes both status and output messages to the log. For output messages also the correct encoding is re-applied: LilyPond writes filenames out in the system's filesystemencoding, while the messages are always written in UTF-8 encoding... """ if type == job.STDERR: # find filenames in message: parts = iter(errors.message_re.split(message.encode('latin1'))) msg = next(parts).decode('utf-8', 'replace') self.cursor.insertText(msg, self.textFormat(type)) enc = sys.getfilesystemencoding() for url, path, line, col, msg in zip(*itertools.repeat(parts, 5)): url = url.decode(enc) path = path.decode(enc) msg = msg.decode('utf-8', 'replace') if self._rawView: fmt = QTextCharFormat(self.textFormat(type)) display_url = url else: fmt = QTextCharFormat(self.textFormat("link")) display_url = os.path.basename(path) fmt.setAnchor(True) fmt.setAnchorHref(str(len(self._errors))) fmt.setToolTip(_("Click to edit this file")) pos = self.cursor.position() self.cursor.insertText(display_url, fmt) self.cursor.insertText(msg, self.textFormat(type)) self._errors.append((pos, self.cursor.position(), url)) else: if type == job.STDOUT: message = message.encode('latin1').decode('utf-8') super(LogWidget, self).writeMessage(message, type)