def logformats(self): """Returns a dictionary with QTextCharFormats for the different types of messages. Besides the STDOUT, STDERR, NEUTRAL, FAILURE and SUCCESS formats there is also a "link" format, that looks basically the same as the output formats, but blueish and underlined, to make parts of the output (e.g. filenames) look clickable. """ textColor = QApplication.palette().color(QPalette.WindowText) successColor = qutil.addcolor(textColor, 0, 128, 0) # more green failureColor = qutil.addcolor(textColor, 128, 0, 0) # more red linkColor = qutil.addcolor(textColor, 0, 0, 128) # more blue stdoutColor = qutil.addcolor(textColor, 64, 64, 0) # more purple s = QSettings() s.beginGroup("log") outputFont = QFont(s.value("fontfamily", "monospace", type(""))) outputFont.setPointSizeF(s.value("fontsize", 9.0, float)) output = QTextCharFormat() output.setFont(outputFont) # enable zooming the log font size output.setProperty(QTextFormat.FontSizeAdjustment, 0) stdout = QTextCharFormat(output) stdout.setForeground(stdoutColor) stderr = QTextCharFormat(output) link = QTextCharFormat(output) link.setForeground(linkColor) link.setFontUnderline(True) status = QTextCharFormat() status.setFontWeight(QFont.Bold) neutral = QTextCharFormat(status) success = QTextCharFormat(status) success.setForeground(successColor) failure = QTextCharFormat(status) failure.setForeground(failureColor) return { job.STDOUT: stdout, job.STDERR: stderr, job.NEUTRAL: neutral, job.SUCCESS: success, job.FAILURE: failure, 'link': link, }
def logformats(self): """Returns a dictionary with QTextCharFormats for the different types of messages. Besides the STDOUT, STDERR, NEUTRAL, FAILURE and SUCCESS formats there is also a "link" format, that looks basically the same as the output formats, but blueish and underlined, to make parts of the output (e.g. filenames) look clickable. """ textColor = QApplication.palette().color(QPalette.WindowText) successColor = qutil.addcolor(textColor, 0, 128, 0) # more green failureColor = qutil.addcolor(textColor, 128, 0, 0) # more red linkColor = qutil.addcolor(textColor, 0, 0, 128) # more blue stdoutColor = qutil.addcolor(textColor, 64, 64, 0) # more purple s = QSettings() s.beginGroup("log") outputFont = QFont(s.value("fontfamily", "monospace", str)) outputFont.setPointSizeF(s.value("fontsize", 9.0, float)) output = QTextCharFormat() output.setFont(outputFont) # enable zooming the log font size output.setProperty(QTextFormat.FontSizeAdjustment, 0) stdout = QTextCharFormat(output) stdout.setForeground(stdoutColor) stderr = QTextCharFormat(output) link = QTextCharFormat(output) link.setForeground(linkColor) link.setFontUnderline(True) status = QTextCharFormat() status.setFontWeight(QFont.Bold) neutral = QTextCharFormat(status) success = QTextCharFormat(status) success.setForeground(successColor) failure = QTextCharFormat(status) failure.setForeground(failureColor) return { job.STDOUT: stdout, job.STDERR: stderr, job.NEUTRAL: neutral, job.SUCCESS: success, job.FAILURE: failure, 'link': link, }
def updateView(self): """Recreate the items in the view.""" with qutil.signalsBlocked(self): self.clear() doc = self.parent().mainwindow().currentDocument() if not doc: return view_cursor_position = self.parent().mainwindow().textCursor( ).position() structure = documentstructure.DocumentStructure.instance(doc) last_item = None current_item = None last_block = None for i in structure.outline(): position = i.start() block = doc.findBlock(position) depth = tokeniter.state(block).depth() if block == last_block: parent = last_item elif last_block is None or depth == 1: # a toplevel item anyway parent = self else: while last_item and depth <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self else: # the item could belong to a parent item, but see if they # really are in the same (toplevel) state b = last_block.next() while b < block: depth2 = tokeniter.state(b).depth() if depth2 == 1: parent = self break while last_item and depth2 <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self break b = b.next() else: parent = last_item item = last_item = QTreeWidgetItem(parent) # set item text and display style bold if 'title' was used for name, text in i.groupdict().items(): if text: if name.startswith('title'): font = item.font(0) font.setWeight(QFont.Bold) item.setFont(0, font) break elif name.startswith('alert'): color = item.foreground(0).color() color = qutil.addcolor(color, 128, 0, 0) item.setForeground(0, QBrush(color)) font = item.font(0) font.setStyle(QFont.StyleItalic) item.setFont(0, font) elif name.startswith('text'): break else: text = i.group() item.setText(0, text) # remember whether is was collapsed by the user try: collapsed = block.userData().collapsed except AttributeError: collapsed = False item.setExpanded(not collapsed) item.depth = depth item.position = position last_block = block # scroll to the item at the view's cursor later if position <= view_cursor_position: current_item = item if current_item: self.scrollToItem(current_item)
def updateView(self): """Recreate the items in the view.""" with qutil.signalsBlocked(self): self.clear() doc = self.parent().mainwindow().currentDocument() if not doc: return view_cursor_position = self.parent().mainwindow().textCursor().position() structure = documentstructure.DocumentStructure.instance(doc) last_item = None current_item = None last_block = None for i in structure.outline(): position = i.start() block = doc.findBlock(position) depth = tokeniter.state(block).depth() if block == last_block: parent = last_item elif last_block is None or depth == 1: # a toplevel item anyway parent = self else: while last_item and depth <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self else: # the item could belong to a parent item, but see if they # really are in the same (toplevel) state b = last_block.next() while b < block: depth2 = tokeniter.state(b).depth() if depth2 == 1: parent = self break while last_item and depth2 <= last_item.depth: last_item = last_item.parent() if not last_item: parent = self break b = b.next() else: parent = last_item item = last_item = QTreeWidgetItem(parent) # set item text and display style bold if 'title' was used for name, text in i.groupdict().items(): if text: if name.startswith('title'): font = item.font(0) font.setWeight(QFont.Bold) item.setFont(0, font) break elif name.startswith('alert'): color = item.foreground(0).color() color = qutil.addcolor(color, 128, 0, 0) item.setForeground(0, QBrush(color)) font = item.font(0) font.setStyle(QFont.StyleItalic) item.setFont(0, font) elif name.startswith('text'): break else: text = i.group() item.setText(0, text) # remember whether is was collapsed by the user try: collapsed = block.userData().collapsed except AttributeError: collapsed = False item.setExpanded(not collapsed) item.depth = depth item.position = position last_block = block # scroll to the item at the view's cursor later if position <= view_cursor_position: current_item = item if current_item: self.scrollToItem(current_item)