本文整理汇总了Python中PyQt4.Qt.QTextCharFormat类的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat类的具体用法?Python QTextCharFormat怎么用?Python QTextCharFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextCharFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initializeFormats
def initializeFormats(self):
Config = self.Config
Config["fontfamily"] = "monospace"
#Config["fontsize"] = 10
for name, color, bold, italic in (
("normal", "#000000", False, False),
("keyword", "#000080", True, False),
("builtin", "#0000A0", False, False),
("comment", "#007F00", False, True),
("string", "#808000", False, False),
("number", "#924900", False, False),
("lparen", "#000000", True, True),
("rparen", "#000000", True, True)):
Config["%sfontcolor" % name] = color
Config["%sfontbold" % name] = bold
Config["%sfontitalic" % name] = italic
baseFormat = QTextCharFormat()
baseFormat.setFontFamily(Config["fontfamily"])
#baseFormat.setFontPointSize(Config["fontsize"])
for name in ("normal", "keyword", "builtin", "comment",
"string", "number", "lparen", "rparen"):
format = QTextCharFormat(baseFormat)
format.setForeground(QColor(Config["%sfontcolor" % name]))
if Config["%sfontbold" % name]:
format.setFontWeight(QFont.Bold)
format.setFontItalic(Config["%sfontitalic" % name])
self.Formats[name] = format
示例2: highlightBlock
def highlightBlock(self, text):
if not self.enabled:
return
fmt = QTextCharFormat()
fmt.setUnderlineColor(Qt.red)
fmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
for word_object in re.finditer(self.WORDS, text):
if not self.spellcheck.check(word_object.group()):
self.setFormat(word_object.start(),
word_object.end() - word_object.start(), fmt)
示例3: highlightBlock
def highlightBlock(self, text):
if not self.dict:
return
text = unicode(text)
format = QTextCharFormat()
format.setUnderlineColor(Qt.red)
format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
for word_object in re.finditer(self.WORDS, text):
if not self.dict.check(word_object.group()):
self.setFormat(word_object.start(),
word_object.end() - word_object.start(), format)
示例4: mark_nbsp
def mark_nbsp(state, text, nbsp_format):
ans = []
fmt = None
if state.bold or state.italic:
fmt = QTextCharFormat()
if state.bold:
fmt.setFontWeight(QFont.Bold)
if state.italic:
fmt.setFontItalic(True)
last = 0
for m in nbsp_pat.finditer(text):
ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)])
if not ans:
ans = [(len(text), fmt)]
return ans
示例5: highlightBlock
def highlightBlock(self, text):
if not self.dict:
return
if not text:
return
txt = unicode(text)
#if len(txt.split())==1:
# txt=""
#else:
# txt=txt.rsplit(' ',1)[0]
format = QTextCharFormat()
format.setUnderlineColor(Qt.red)
format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
unicode_pattern=regex.compile(self.pattern,regex.UNICODE)
for word_object in unicode_pattern.finditer(txt):
if not self.dict.spell(word_object.group().encode('utf-8')):
self.setFormat(word_object.start(), word_object.end() - word_object.start(), format)
self.errorcount+=1
print self.errorcount
示例6: check_spelling
def check_spelling(text, tlen, fmt, locale, sfmt, store_locale):
split_ans = []
ppos = 0
r, a = dictionaries.recognized, split_ans.append
for start, length in split_into_words_and_positions(text, lang=locale.langcode):
if start > ppos:
a((start - ppos, fmt))
ppos = start + length
recognized = r(text[start:ppos], locale)
if recognized:
a((length, fmt))
else:
if store_locale:
s = QTextCharFormat(sfmt)
s.setProperty(SPELL_LOCALE_PROPERTY, locale)
a((length, s))
else:
a((length, sfmt))
if ppos < tlen:
a((tlen - ppos, fmt))
return split_ans
示例7: process_text
def process_text(state, text, nbsp_format, spell_format, user_data):
ans = []
fmt = None
if state.is_bold or state.is_italic:
fmt = syntax_text_char_format()
if state.is_bold:
fmt.setFontWeight(QFont.Bold)
if state.is_italic:
fmt.setFontItalic(True)
last = 0
for m in nbsp_pat.finditer(text):
ans.extend([(m.start() - last, fmt), (m.end() - m.start(), nbsp_format)])
last = m.end()
if not ans:
ans = [(len(text), fmt)]
elif last < len(text):
ans.append((len(text) - last, fmt))
if do_spell_check and state.tags and user_data.tag_ok_for_spell(state.tags[-1].name):
split_ans = []
locale = state.current_lang or dictionaries.default_locale
sfmt = QTextCharFormat(spell_format)
if fmt is not None:
sfmt.merge(fmt)
tpos = 0
for tlen, fmt in ans:
if fmt is nbsp_format:
split_ans.append((tlen, fmt))
else:
split_ans.extend(check_spelling(text[tpos:tpos+tlen], tlen, fmt, locale, sfmt, store_locale.enabled))
tpos += tlen
ans = split_ans
return ans
示例8: __init__
def __init__(self, *args):
QTextCharFormat.__init__(self, *args)
self.setProperty(SYNTAX_PROPERTY, True)
示例9: initializeFormats
def initializeFormats(cls):
Config = cls.Config
baseFormat = QTextCharFormat()
baseFormat.setFontFamily(Config["fontfamily"])
baseFormat.setFontPointSize(Config["fontsize"])
for name in ("normal", "keyword", "builtin", "constant",
"decorator", "comment", "string", "number", "error",
"pyqt"):
format = QTextCharFormat(baseFormat)
format.setForeground(QColor(Config["%sfontcolor" % name]))
if Config["%sfontbold" % name]:
format.setFontWeight(QFont.Bold)
format.setFontItalic(Config["%sfontitalic" % name])
PythonHighlighter.Formats[name] = format
示例10: highlight_to_char_format
def highlight_to_char_format(h):
ans = QTextCharFormat()
if h.bold:
ans.setFontWeight(QFont.Bold)
if h.italic:
ans.setFontItalic(True)
if h.fg is not None:
ans.setForeground(h.fg)
if h.bg is not None:
ans.setBackground(h.bg)
if h.underline is not None:
ans.setUnderlineStyle(underline_styles[h.underline])
if h.underline_color is not None:
ans.setUnderlineColor(h.underline_color.color())
return ans
示例11: spell_property
def spell_property(sfmt, locale):
s = QTextCharFormat(sfmt)
s.setProperty(SPELL_LOCALE_PROPERTY, locale)
return s
示例12: __init__
def __init__(self, right=False, parent=None, show_open_in_editor=False):
PlainTextEdit.__init__(self, parent)
self.setFrameStyle(0)
self.show_open_in_editor = show_open_in_editor
self.side_margin = 0
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)
self.setFocusPolicy(Qt.NoFocus)
self.right = right
self.setReadOnly(True)
w = self.fontMetrics()
self.number_width = max(map(lambda x:w.width(str(x)), xrange(10)))
self.space_width = w.width(' ')
self.setLineWrapMode(self.WidgetWidth)
self.setTabStopWidth(tprefs['editor_tab_stop_width'] * self.space_width)
font = self.font()
ff = tprefs['editor_font_family']
if ff is None:
ff = default_font_family()
font.setFamily(ff)
font.setPointSize(tprefs['editor_font_size'])
self.setFont(font)
font = self.heading_font = QFont(self.font())
font.setPointSize(int(tprefs['editor_font_size'] * 1.5))
font.setBold(True)
theme = get_theme()
pal = self.palette()
pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg'))
pal.setColor(pal.AlternateBase, theme_color(theme, 'CursorLine', 'bg'))
pal.setColor(pal.Text, theme_color(theme, 'Normal', 'fg'))
pal.setColor(pal.Highlight, theme_color(theme, 'Visual', 'bg'))
pal.setColor(pal.HighlightedText, theme_color(theme, 'Visual', 'fg'))
self.setPalette(pal)
self.viewport().setCursor(Qt.ArrowCursor)
self.line_number_area = LineNumbers(self)
self.blockCountChanged[int].connect(self.update_line_number_area_width)
self.updateRequest.connect(self.update_line_number_area)
self.line_number_palette = pal = QPalette()
pal.setColor(pal.Base, theme_color(theme, 'LineNr', 'bg'))
pal.setColor(pal.Text, theme_color(theme, 'LineNr', 'fg'))
pal.setColor(pal.BrightText, theme_color(theme, 'LineNrC', 'fg'))
self.line_number_map = LineNumberMap()
self.search_header_pos = 0
self.changes, self.headers, self.images = [], [], OrderedDict()
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff), self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.diff_backgrounds = {
'replace' : theme_color(theme, 'DiffReplace', 'bg'),
'insert' : theme_color(theme, 'DiffInsert', 'bg'),
'delete' : theme_color(theme, 'DiffDelete', 'bg'),
'replacereplace': theme_color(theme, 'DiffReplaceReplace', 'bg'),
'boundary': QBrush(theme_color(theme, 'Normal', 'fg'), Qt.Dense7Pattern),
}
self.diff_foregrounds = {
'replace' : theme_color(theme, 'DiffReplace', 'fg'),
'insert' : theme_color(theme, 'DiffInsert', 'fg'),
'delete' : theme_color(theme, 'DiffDelete', 'fg'),
'boundary': QColor(0, 0, 0, 0),
}
for x in ('replacereplace', 'insert', 'delete'):
f = QTextCharFormat()
f.setBackground(self.diff_backgrounds[x])
setattr(self, '%s_format' % x, f)
示例13: syntax_text_char_format
def syntax_text_char_format(*args):
ans = QTextCharFormat(*args)
ans.setProperty(SYNTAX_PROPERTY, True)
return ans
示例14: setTheme
def setTheme(self, theme):
self.theme = theme
self.MARKDOWN_KWS_FORMAT = {}
pal = self.parent.palette()
pal.setColor(QPalette.Base, QColor(theme['background-color']))
self.parent.setPalette(pal)
self.parent.setTextColor(QColor(theme['color']))
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['bold']['color'])))
format.setFontWeight(QFont.Bold if theme['bold']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['bold']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['Bold'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['bold']['color'])))
format.setFontWeight(QFont.Bold if theme['bold']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['bold']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['uBold'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['emphasis']['color'])))
format.setFontWeight(QFont.Bold if theme['emphasis']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['emphasis']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['Italic'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['emphasis']['color'])))
format.setFontWeight(QFont.Bold if theme['emphasis']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['emphasis']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['uItalic'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['link']['color'])))
format.setFontWeight(QFont.Bold if theme['link']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['link']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['Link'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['image']['color'])))
format.setFontWeight(QFont.Bold if theme['image']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['image']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['Image'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['header']['color'])))
format.setFontWeight(QFont.Bold if theme['header']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['header']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['Header'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['header']['color'])))
format.setFontWeight(QFont.Bold if theme['header']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['header']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['HeaderAtx'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['unorderedlist']['color'])))
format.setFontWeight(QFont.Bold if theme['unorderedlist']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['unorderedlist']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['UnorderedList'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['orderedlist']['color'])))
format.setFontWeight(QFont.Bold if theme['orderedlist']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['orderedlist']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['OrderedList'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['blockquote']['color'])))
format.setFontWeight(QFont.Bold if theme['blockquote']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['blockquote']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['BlockQuote'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['codespan']['color'])))
format.setFontWeight(QFont.Bold if theme['codespan']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['codespan']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['CodeSpan'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['codeblock']['color'])))
format.setFontWeight(QFont.Bold if theme['codeblock']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['codeblock']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['CodeBlock'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['line']['color'])))
format.setFontWeight(QFont.Bold if theme['line']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['line']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['HR'] = format
format = QTextCharFormat()
format.setForeground(QBrush(QColor(theme['line']['color'])))
format.setFontWeight(QFont.Bold if theme['line']['font-weight']=='bold' else QFont.Normal)
format.setFontItalic(True if theme['line']['font-style']=='italic' else False)
self.MARKDOWN_KWS_FORMAT['eHR'] = format
format = QTextCharFormat()
#.........这里部分代码省略.........
示例15: base_fmt
def base_fmt(self):
fmt = QTextCharFormat()
fmt.setFontFamily('monospace')
return fmt