def setup_editor(self): variable_format = QTextCharFormat() variable_format.setFontWeight(QFont.Bold) variable_format.setForeground(Qt.blue) self._highlighter.add_mapping("\\b[A-Z_]+\\b", variable_format) single_line_comment_format = QTextCharFormat() single_line_comment_format.setBackground(QColor("#77ff77")) self._highlighter.add_mapping("#[^\n]*", single_line_comment_format) quotation_format = QTextCharFormat() quotation_format.setBackground(Qt.cyan) quotation_format.setForeground(Qt.blue) self._highlighter.add_mapping("\".*\"", quotation_format) function_format = QTextCharFormat() function_format.setFontItalic(True) function_format.setForeground(Qt.blue) self._highlighter.add_mapping("\\b[a-z0-9_]+\\(.*\\)", function_format) font = QFont() font.setFamily("Courier") font.setFixedPitch(True) font.setPointSize(10) self._editor = QPlainTextEdit() self._editor.setFont(font) self._highlighter.setDocument(self._editor.document())
def text_format(color, style=''): f = QTextCharFormat() f.setForeground(color) if 'bold' in style: f.setFontWeight(QFont.Bold) if 'italic' in style: f.setFontItalic(True) return f
def _formatiraj(self, r, g, b, stil=''): #_boja = QColor() _boja = QColor.fromRgb(r, g, b, 255) _format = QTextCharFormat() _format.setForeground(_boja) if 'bold' in stil: _format.setFontWeight(QFont.Bold) if 'italic' in stil: _format.setFontItalic(True) return _format
def getTextCharFormat(self, color, style=None): """Return a QTextCharFormat with the given attributes.""" textCharFormat = QTextCharFormat() textCharFormat.setForeground(color) if style is not None: if 'bold' in style: textCharFormat.setFontWeight(QFont.Bold) if 'italic' in style: textCharFormat.setFontItalic(True) return textCharFormat
def format(color, style=''): """Return a QTextCharFormat with the given attributes.""" _color = eval('getThemeColor(ThemeColor.%s)' % color) _format = QTextCharFormat() _format.setForeground(_color) if 'bold' in style: _format.setFontWeight(QFont.Bold) if 'italic' in style: _format.setFontItalic(True) return _format
def txformat(color, style=''): """Return a QTextCharFormat with the given attributes. """ _color = QColor() _color.setNamedColor(color) _format = QTextCharFormat() _format.setForeground(_color) if 'bold' in style: _format.setFontWeight(QFont.Bold) if 'italic' in style: _format.setFontItalic(True) return _format
def format(color, style=''): """Return a QTextCharFormat with the given attributes. """ _color = QColor(color[0], color[1], color[2]) _format = QTextCharFormat() _format.setFontFamily("Courier New") _format.setForeground(_color) if 'bold' in style: _format.setFontWeight(QFont.Bold) if 'italic' in style: _format.setFontItalic(True) return _format
def get_format(cls, color: str, style='', fontsize=None) -> QTextCharFormat: """Return a QTextCharFormat with the given attributes.""" _color = QColor() _color.setNamedColor(color) _format = QTextCharFormat() _format.setForeground(_color) if 'bold' in style: _format.setFontWeight(QFont.Bold) if 'italic' in style: _format.setFontItalic(True) if fontsize: _format.setFontPointSize(fontsize) return _format
def formatColor(color, style=None): """Return a QTextCharFormat with the given attributes. :param color: float3 rgb :type color: tuple :param style: the style name eg. 'bold' :type style: str or None """ style = style or "" _color = QColor(*color) _format = QTextCharFormat() _format.setForeground(_color) if "bold" in style: _format.setFontWeight(QFont.Bold) if "italic" in style: _format.setFontItalic(True) return _format
def formatText(cls, color, style=""): """ Return a QTextCharFormat with the given attributes. """ clr = QColor(*color) txt_format = QTextCharFormat() txt_format.setForeground(clr) if "bold" in style: txt_format.setFontWeight(QFont.Bold) if "italic" in style: txt_format.setFontItalic(True) return txt_format
def newLetter(self): self.textEdit.clear() cursor = self.textEdit.textCursor() cursor.movePosition(QTextCursor.Start) topFrame = cursor.currentFrame() topFrameFormat = topFrame.frameFormat() topFrameFormat.setPadding(16) topFrame.setFrameFormat(topFrameFormat) # timer = QTimer(self) # timer.timeout.connect(self.showTime) # timer.start(1000) textFormat = QTextCharFormat() boldFormat = QTextCharFormat() boldFormat.setFontWeight(QFont.Bold) italicFormat = QTextCharFormat() italicFormat.setFontItalic(True) tableFormat = QTextTableFormat() tableFormat.setBorder(1) tableFormat.setCellPadding(16) tableFormat.setAlignment(Qt.AlignRight) cursor.insertTable(1, 1, tableFormat) cursor.insertText("Tomasz Dróżdż", boldFormat) cursor.insertBlock() cursor.insertText("Politechnika Wrocławska", textFormat) cursor.insertBlock() cursor.insertText("Automatyka i Robotyka") cursor.insertBlock() cursor.insertText("SOLAR PANEL Program") cursor.setPosition(topFrame.lastPosition()) cursor.insertText( QDate.currentDate().toString("Dziś jest: d MMMM yyyy:"), textFormat) cursor.insertText(QTime.currentTime().toString(" hh:mm:ss"), textFormat) # cursor.insertText(QTimer.timer(" hh:mm:ss", 1000), textFormat) cursor.insertBlock() cursor.insertBlock() cursor.insertText("Wrocław: ", textFormat) cursor.insertText("17.03 deg; 51.10 deg", textFormat) cursor.insertText(",", textFormat) for i in range(3): cursor.insertBlock() cursor.insertText("Text", textFormat)
def __init__(self, document, **options): Formatter.__init__(self, **options) self.document = document # Prepare format by styles self.styles = {} for token, style in self.style: format = QTextCharFormat() if style['color']: format.setForeground(QColor('#' + style['color'])) if style['bold']: format.setFontWeight(QFont.Bold) if style['italic']: format.setFontItalic(True) if style['underline']: format.setFontUnderline(True) self.styles[token] = format
def mouseOverLabel(self, e): if self.previousKeywordFormat['cursor']: return cursor = self.cursorForPosition(e.pos()) cursor.select(QTextCursor.WordUnderCursor) newFormat = QTextCharFormat() newFormat.setUnderlineColor(QColor("#007ACC")) newFormat.setFontItalic(True) newFormat.setUnderlineStyle(QTextCharFormat.SingleUnderline) cursor.setCharFormat(newFormat) formater = Formater() self.previousKeywordFormat['cursor'] = cursor if isinstance(self.file, AssemblyFileProxy): self.previousKeywordFormat['format'] = formater._formatiraj( 255, 255, 255) else: self.previousKeywordFormat['format'] = formater.stilovi[ 'declarations']
def format(color, style=''): """ Return a QTextCharFormat with the given attributes. """ _color = QColor() if type(color) is not str: _color.setRgb(color[0], color[1], color[2]) else: _color.setNamedColor(color) _format = QTextCharFormat() _format.setForeground(_color) if 'bold' in style: _format.setFontWeight(QFont.Bold) if 'italic' in style: _format.setFontItalic(True) return _format
def newLetter(self): self.textEdit.clear() cursor = self.textEdit.textCursor() cursor.movePosition(QTextCursor.Start) topFrame = cursor.currentFrame() topFrameFormat = topFrame.frameFormat() topFrameFormat.setPadding(16) topFrame.setFrameFormat(topFrameFormat) textFormat = QTextCharFormat() boldFormat = QTextCharFormat() boldFormat.setFontWeight(QFont.Bold) italicFormat = QTextCharFormat() italicFormat.setFontItalic(True) tableFormat = QTextTableFormat() tableFormat.setBorder(1) tableFormat.setCellPadding(16) tableFormat.setAlignment(Qt.AlignRight) cursor.insertTable(1, 1, tableFormat) cursor.insertText("The Firm", boldFormat) cursor.insertBlock() cursor.insertText("321 City Street", textFormat) cursor.insertBlock() cursor.insertText("Industry Park") cursor.insertBlock() cursor.insertText("Some Country") cursor.setPosition(topFrame.lastPosition()) cursor.insertText(QDate.currentDate().toString("d MMMM yyyy"), textFormat) cursor.insertBlock() cursor.insertBlock() cursor.insertText("Dear ", textFormat) cursor.insertText("NAME", italicFormat) cursor.insertText(",", textFormat) for i in range(3): cursor.insertBlock() cursor.insertText("Yours sincerely,", textFormat) for i in range(3): cursor.insertBlock() cursor.insertText("The Boss", textFormat) cursor.insertBlock() cursor.insertText("ADDRESS", italicFormat)
def get_format(self, color, style=''): """ Returns a QTextCharFormat with the given attributes :param color: :param style: :return: """ c = QColor() c.setNamedColor(color) f = QTextCharFormat() f.setForeground(c) if 'bold' in style: f.setFontWeight(QFont.Bold) if 'italic' in style: f.setFontItalic(True) return f
def __init__(self, parent=None): super(CodePreview_Highlighter, self).__init__(parent) keyword_format = QTextCharFormat() keyword_format.setFontWeight(QFont.Bold) keyword_format.setForeground(QColor(80, 80, 240)) keyword_patterns = ["class", "def"] self.highlighting_rules = [(QRegExp(pattern), keyword_format) for pattern in keyword_patterns] # individual patterns if_format = QTextCharFormat() if_format.setForeground(QColor(255, 153, 51)) self.highlighting_rules.append((QRegExp('if .+:'), if_format)) elif_format = QTextCharFormat() elif_format.setForeground(QColor(255, 153, 51)) self.highlighting_rules.append((QRegExp('elif .+:'), elif_format)) else_format = QTextCharFormat() else_format.setForeground(QColor(255, 153, 51)) self.highlighting_rules.append((QRegExp('else:'), else_format)) else_format = QTextCharFormat() else_format.setFontItalic(True) else_format.setForeground(QColor(255, 179, 102)) self.highlighting_rules.append((QRegExp('pass'), else_format)) variable_assignment_format = QTextCharFormat() variable_assignment_format.setForeground(QColor(224, 108, 117)) self.highlighting_rules.append( (QRegExp('[a-zA-Z_]+( +)=( +)'), variable_assignment_format)) parameter_format = QTextCharFormat() parameter_format.setForeground(QColor(229, 192, 123)) self.highlighting_rules.append( (QRegExp("[a-zA-Z_]+\(.*\)"), parameter_format)) # not working with standard values ('=') yet function_call_format = QTextCharFormat() function_call_format.setForeground(QColor(204, 204, 255)) self.highlighting_rules.append( (QRegExp('[A-Za-z0-9_]+(?=\\()'), function_call_format)) self_format = QTextCharFormat() self_format.setForeground(QColor(204, 204, 255)) self.highlighting_rules.append((QRegExp('self'), self_format)) return_format = QTextCharFormat() return_format.setFontItalic(True) return_format.setForeground(QColor(204, 82, 0)) self.highlighting_rules.append((QRegExp('return'), return_format)) singleLineCommentFormat = QTextCharFormat() singleLineCommentFormat.setFontItalic(True) singleLineCommentFormat.setForeground(QColor(92, 99, 112)) self.highlighting_rules.append( (QRegExp('#[^\n]*'), singleLineCommentFormat))
def newLetter(self): self.textEdit.clear() self.text2 = QLabel("<b>Domyślne Współrzędne:</b><br/>" "Szerokość: 51° 06' 00''<br/>" "Długość: 17° 01' 00''<br/>" "(Współrzędne geograficzne Wrocławia)") cursor = self.textEdit.textCursor() cursor.movePosition(QTextCursor.Start) topFrame = cursor.currentFrame() topFrameFormat = topFrame.frameFormat() topFrameFormat.setPadding(16) topFrame.setFrameFormat(topFrameFormat) textFormat = QTextCharFormat() boldFormat = QTextCharFormat() boldFormat.setFontWeight(QFont.Bold) italicFormat = QTextCharFormat() italicFormat.setFontItalic(True) tableFormat = QTextTableFormat() tableFormat.setBorder(1) tableFormat.setCellPadding(16) tableFormat.setAlignment(Qt.AlignRight) cursor.insertTable(1, 1, tableFormat) cursor.insertText("Domyślne Współrzędne: ", boldFormat) self.text2.setText(self.nameEdit.text()) cursor.insertText #self.text1.setText(self.nameEdit.text()) cursor.insertBlock() cursor.insertBlock() cursor.insertText("Szerokość: 51° 06' 00''", textFormat) cursor.insertBlock() cursor.insertBlock() cursor.insertText("Długość: 17° 01' 00''") cursor.insertBlock() cursor.insertBlock() cursor.insertText("(Współrzędne geograficzne Wrocławia)") cursor.setPosition(topFrame.lastPosition())
def make_formats(self): self.formats = {} for kind, color in ( (Syntax.NORMAL, Qt.black), (Syntax.CONSTANT, Qt.darkCyan), (Syntax.FUNCTION, Qt.blue), (Syntax.KEYWORD, Qt.darkBlue), (Syntax.NUMBER, Qt.darkRed), (Syntax.OPERATOR, Qt.darkMagenta), (Syntax.STRING, Qt.darkYellow), (Syntax.COMMENT, Qt.darkGreen)): fmt = QTextCharFormat() fmt.setFontFamily('Consolas' if WIN else 'Monospace') fmt.setFontFixedPitch(True) fmt.setFontStyleHint(QFont.Monospace) fmt.setForeground(QColor(color)) if kind in {Syntax.CONSTANT, Syntax.FUNCTION, Syntax.KEYWORD, Syntax.OPERATOR}: fmt.setFontCapitalization(QFont.AllUppercase) if kind is Syntax.KEYWORD: fmt.setFontWeight(QFont.DemiBold) elif kind is Syntax.COMMENT: fmt.setFontItalic(True) self.formats[kind] = fmt