本文整理汇总了Python中PyQt5.QtGui.QTextCharFormat.setFontUnderline方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat.setFontUnderline方法的具体用法?Python QTextCharFormat.setFontUnderline怎么用?Python QTextCharFormat.setFontUnderline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextCharFormat
的用法示例。
在下文中一共展示了QTextCharFormat.setFontUnderline方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: css2fmt
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def css2fmt(d, f=None):
"""Convert a css dictionary to a QTextCharFormat."""
if f is None:
f = QTextCharFormat()
v = d.get('font-style')
if v:
f.setFontItalic(v in ('oblique', 'italic'))
v = d.get('font-weight')
if v:
if v == 'bold':
f.setFontWeight(QFont.Bold)
elif v == 'normal':
f.setFontWeight(QFont.Normal)
elif v.isdigit():
f.setFontWeight(int(v) / 10)
v = d.get('color')
if v:
f.setForeground(QColor(v))
v = d.get('background')
if v:
f.setBackground(QColor(v))
v = d.get('text-decoration')
if v:
f.setFontUnderline(v == 'underline')
v = d.get('text-decoration-color')
if v:
f.setUnderlineColor(QColor(v))
return f
示例2: highlightBlock
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def highlightBlock(self, text):
patterns = (
# regex, color, font style, italic, underline
(reHtmlTags, 'htmlTags', QFont.Bold), # 0
(reHtmlSymbols, 'htmlSymbols', QFont.Bold), # 1
(reHtmlStrings, 'htmlStrings', QFont.Bold), # 2
(reHtmlComments, 'htmlComments', QFont.Normal), # 3
(reAsterisks, None, QFont.Normal, True), # 4
(reUnderline, None, QFont.Normal, True), # 5
(reDblAsterisks, None, QFont.Bold), # 6
(reDblUnderline, None, QFont.Bold), # 7
(reTrpAsterisks, None, QFont.Bold, True), # 8
(reTrpUnderline, None, QFont.Bold, True), # 9
(reMkdHeaders, None, QFont.Black), # 10
(reMkdLinksImgs, 'markdownLinks', QFont.Normal), # 11
(reMkdLinkRefs, None, QFont.Normal, True, True), # 12
(reBlockQuotes, 'blockquotes', QFont.Normal), # 13
(reReSTDirects, 'restDirectives', QFont.Bold), # 14
(reReSTRoles, 'restRoles', QFont.Bold), # 15
(reTextileHdrs, None, QFont.Black), # 16
(reTextileQuot, 'blockquotes', QFont.Normal), # 17
(reAsterisks, None, QFont.Bold), # 18
(reDblUnderline, None, QFont.Normal, True), # 19
)
patternsDict = {
'Markdown': (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
'reStructuredText': (4, 6, 14, 15),
'Textile': (0, 5, 6, 16, 17, 18, 19),
'html': (0, 1, 2, 3)
}
# Syntax highlighter
if self.docType in patternsDict:
for number in patternsDict[self.docType]:
pattern = patterns[number]
charFormat = QTextCharFormat()
charFormat.setFontWeight(pattern[2])
if pattern[1] != None:
charFormat.setForeground(colorScheme[pattern[1]])
if len(pattern) >= 4:
charFormat.setFontItalic(pattern[3])
if len(pattern) >= 5:
charFormat.setFontUnderline(pattern[4])
for match in pattern[0].finditer(text):
self.setFormat(match.start(), match.end() - match.start(), charFormat)
for match in reSpacesOnEnd.finditer(text):
charFormat = QTextCharFormat()
charFormat.setBackground(colorScheme['whitespaceOnEnd'])
self.setFormat(match.start(), match.end() - match.start(), charFormat)
# Spell checker
if self.dictionary:
charFormat = QTextCharFormat()
charFormat.setUnderlineColor(Qt.red)
charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
for match in reWords.finditer(text):
finalFormat = QTextCharFormat()
finalFormat.merge(charFormat)
finalFormat.merge(self.format(match.start()))
if not self.dictionary.check(match.group(0)):
self.setFormat(match.start(), match.end() - match.start(), finalFormat)
示例3: _get_underline
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def _get_underline(self):
_format = QTextCharFormat()
if self.textCursor().charFormat().font().underline():
_format.setFontUnderline(False)
else:
_format.setFontUnderline(True)
return _format
示例4: logformats
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
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,
}
示例5: highlightBlock
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def highlightBlock(self, text):
patterns = (
# regex, color, font style, italic, underline
(reHtmlTags, colorScheme[0], QFont.Bold),
(reHtmlSymbols, colorScheme[1], QFont.Bold),
(reHtmlStrings, colorScheme[2], QFont.Bold),
(reHtmlComments, colorScheme[3], QFont.Normal),
(reItalics1, None, QFont.Normal, True),
(reItalics2, None, QFont.Normal, True),
(reBold1, None, QFont.Bold),
(reBold2, None, QFont.Bold),
(reBoldItalics1, None, QFont.Bold, True),
(reBoldItalics2, None, QFont.Bold, True),
(reMkdHeaders, None, QFont.Black),
(reMkdLinksImgs, colorScheme[4], QFont.Normal),
(reMkdLinkRefs, None, QFont.Normal, True, True),
(reBlockQuotes, colorScheme[5], QFont.Normal),
(reReSTDirects, colorScheme[6], QFont.Normal),
(reReSTRoles, colorScheme[7], QFont.Normal)
)
patternsDict = {
DOCTYPE_NONE: (),
DOCTYPE_MARKDOWN: (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13),
DOCTYPE_REST: (4, 6, 14, 15),
DOCTYPE_HTML: (0, 1, 2, 3)
}
# Syntax highlighter
if self.docType in patternsDict:
for number in patternsDict[self.docType]:
pattern = patterns[number]
charFormat = QTextCharFormat()
charFormat.setFontWeight(pattern[2])
if pattern[1] != None:
charFormat.setForeground(pattern[1])
if len(pattern) >= 4:
charFormat.setFontItalic(pattern[3])
if len(pattern) >= 5:
charFormat.setFontUnderline(pattern[4])
for match in pattern[0].finditer(text):
self.setFormat(match.start(), match.end() - match.start(), charFormat)
# Spell checker
if self.dictionary:
charFormat = QTextCharFormat()
charFormat.setUnderlineColor(Qt.red)
charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
for match in reWords.finditer(text):
finalFormat = QTextCharFormat()
finalFormat.merge(charFormat)
finalFormat.merge(self.format(match.start()))
if not self.dictionary.check(match.group(0)):
self.setFormat(match.start(), match.end() - match.start(), finalFormat)
示例6: eltToStyle
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def eltToStyle(elt):
fmt = QTextCharFormat()
if elt.get('bold'):
fmt.setFontWeight(QFont.Bold if toBool(elt.get('bold')) else QFont.Normal)
if elt.get('italic'):
fmt.setFontItalic(toBool(elt.get('italic')))
if elt.get('underline'):
fmt.setFontUnderline(toBool(elt.get('underline')))
if elt.get('textColor'):
fmt.setForeground(QColor(elt.get('textColor')))
if elt.get('backgroundColor'):
fmt.setBackground(QColor(elt.get('backgroundColor')))
if elt.get('underlineColor'):
fmt.setUnderlineColor(QColor(elt.get('underlineColor')))
return fmt
示例7: DNAHighlighter
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
class DNAHighlighter(QSyntaxHighlighter):
def __init__(self, parent):
QSyntaxHighlighter.__init__(self, parent)
self.parent = parent
self.format = QTextCharFormat()
self.format.setForeground(QBrush(styles.INVALID_DNA_COLOR))
if styles.UNDERLINE_INVALID_DNA:
self.format.setFontUnderline(True)
self.format.setUnderlineColor(styles.INVALID_DNA_COLOR)
def highlightBlock(self, text):
index = dnapattern.indexIn(text)
while index >= 0:
length = dnapattern.matchedLength()
self.setFormat(index, length, self.format)
index = text.indexOf(dnapattern, index + length)
self.setCurrentBlockState(0)
示例8: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def __init__(self, *args, **kwargs):
Formatter.__init__(self)
self.data=[]
self.styles={}
for token, style in self.style:
qtf=QTextCharFormat()
if style['color']:
qtf.setForeground(self.hex2QColor(style['color']))
if style['bgcolor']:
qtf.setBackground(self.hex2QColor(style['bgcolor']))
if style['bold']:
qtf.setFontWeight(QFont.Bold)
if style['italic']:
qtf.setFontItalic(True)
if style['underline']:
qtf.setFontUnderline(True)
self.styles[str(token)]=qtf
return
示例9: formatConverterFunction
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def formatConverterFunction(format):
if format == qutepart.syntax.TextFormat():
return None # Do not apply default format. Performance optimization
qtFormat = QTextCharFormat()
foregroundColor = QColor(format.color)
backgroundColor = QColor(format.background)
if foregroundColor != Qt.black:
qtFormat.setForeground(foregroundColor)
if backgroundColor != Qt.white:
qtFormat.setBackground(backgroundColor)
qtFormat.setFontItalic(format.italic)
qtFormat.setFontWeight(QFont.Bold if format.bold else QFont.Normal)
qtFormat.setFontUnderline(format.underline)
qtFormat.setFontStrikeOut(format.strikeOut)
return qtFormat
示例10: DNAHighlighter
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
class DNAHighlighter(QSyntaxHighlighter):
"""Summary
Attributes:
format (TYPE): Description
parent (TYPE): Description
"""
def __init__(self, parent):
"""Summary
Args:
parent (TYPE): Description
"""
QSyntaxHighlighter.__init__(self, parent)
self.parent = parent
self.format = QTextCharFormat()
self.format.setForeground(getBrushObj(Qt.white))
self.format.setBackground(getBrushObj(styles.INVALID_DNA_COLOR))
if styles.UNDERLINE_INVALID_DNA:
self.format.setFontUnderline(True)
self.format.setUnderlineColor(getColorObj(styles.INVALID_DNA_COLOR))
def highlightBlock(self, text):
"""Summary
Args:
text (TYPE): Description
Returns:
TYPE: Description
"""
for match in re.finditer(RE_DNA_PATTERN, text):
index = match.start()
length = match.end() - index
self.setFormat(index, length, self.format)
self.setCurrentBlockState(0)
示例11: textUnderline
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
def textUnderline(self):
fmt = QTextCharFormat()
fmt.setFontUnderline(self.actionTextUnderline.isChecked())
self.mergeFormatOnWordOrSelection(fmt)
示例12: makeFormat
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
#.........这里部分代码省略.........
# size = _format.fontPointSize()
_format = QTextCharFormat(self._defaultCharFormat)
# Base
if base:
_format = base
# Presets
if preset in [State.CODE_AREA, State.CODE_LINE, "code"]:
style = "bold"
color = "black"
fixedPitch = True
_format.setBackground(QColor("#EEEEEE"))
if preset in [State.COMMENT_AREA, State.COMMENT_LINE, "comment"]:
style = "italic"
color = "darkGreen"
if preset in [State.SETTINGS_LINE, "setting", State.MACRO]:
# style = "italic"
color = "magenta"
if preset in [State.BLOCKQUOTE_LINE]:
color = "red"
if preset in [State.HEADER_LINE]:
size *= 2
# print size
if preset in [State.RAW_AREA, State.RAW_LINE, "raw"]:
color = "blue"
if preset in [State.TAGGED_AREA, State.TAGGED_LINE, "tagged"]:
color = "purple"
if preset in State.TITLES:
style = "bold"
color = "darkRed" if State.titleLevel(preset) % 2 == 1 else "blue"
size = (self._defaultCharFormat.font().pointSize()
+ 11 - 2 * State.titleLevel(preset))
if preset == State.TABLE_HEADER:
style = "bold"
color = "darkMagenta"
if preset == State.TABLE_LINE:
color = "darkMagenta"
if preset == State.LIST_BULLET:
color = "red"
style = "bold"
fixedPitch = True
if preset == State.LIST_BULLET_ENDS:
color = "darkGray"
fixedPitch = True
if preset in [State.MARKUP, "markup"]:
color = "darkGray"
if preset in [State.HORIZONTAL_LINE]:
color = "cyan"
fixedPitch = True
if preset == State.LINKS:
color = "blue"
# style="underline"
if preset == "selected":
_format.setBackground(QColor("yellow"))
if preset == "higlighted":
bgcolor = "yellow"
# if preset == State.DEFAULT:
# size = self.defaultFontPointSize
# _format.setFontFamily(self.defaultFontFamily)
# Manual formatting
if color:
_color.setNamedColor(color)
_format.setForeground(_color)
if bgcolor:
_color.setNamedColor(bgcolor)
_format.setBackground(_color)
if 'bold' in style:
_format.setFontWeight(QFont.Bold)
if 'italic' in style:
_format.setFontItalic(True)
if 'strike' in style:
_format.setFontStrikeOut(True)
if 'underline' in style:
_format.setFontUnderline(True)
if size:
_format.setFontPointSize(size)
if fixedPitch:
_format.setFontFixedPitch(True)
return _format
示例13: highlightBlock
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
#.........这里部分代码省略.........
# InDocRules
for (r, c) in self.inDocRules:
i = re.finditer(r.decode('utf8'), text, re.UNICODE)
for m in i:
f = self.format(m.start())
l = m.end() - m.start()
if "," in c:
c1, c2 = c.split(",")
self.setFormat(m.start(), l,
self.style.makeFormat(color=c1, bgcolor=c2, base=f))
else:
self.setFormat(m.start(), l,
self.style.makeFormat(color=c, base=f))
# Links
if state not in [State.COMMENT_LINE, State.COMMENT_AREA]:
r = QRegExp(r'\[(\[[^\]]*\])?[^\]]*\s*([^\s]+)\]')
r.setMinimal(False)
pos = r.indexIn(text)
links = []
while pos >= 0:
# TODO: The text should not be formatted if [**not bold**]
# if max([k[pos] for k in formatArray]) == 0 or 1 == 1:
self.setFormat(pos, 1,
self.style.format(State.MARKUP))
self.setFormat(pos + 1, len(r.cap(0)) - 1,
self.style.format(State.LINKS))
self.setFormat(pos + len(r.cap(0)) - 1, 1,
self.style.format(State.MARKUP))
if r.pos(2) > 0:
_f = QTextCharFormat(self.style.format(State.LINKS))
_f.setForeground(QBrush(_f.foreground()
.color().lighter()))
_f.setFontUnderline(True)
self.setFormat(r.pos(2), len(r.cap(2)), _f)
links.append([pos, len(r.cap(0))]) # To remember for the next highlighter (single links)
pos = r.indexIn(text, pos + 1)
# Links like www.theologeek.ch, http://www.fsf.org, ...
# FIXME: - "http://adresse et http://adresse" is detected also as italic
# - some error, like "http://adress.htm." also color the final "."
# - also: [email protected], ftp://, www2, www3, etc.
# - But for now, does the job
r = QRegExp(r'http://[^\s]*|www\.[a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+[^\s]*')
# r.setMinimal(True)
pos = r.indexIn(text)
while pos >= 0:
for k in links:
# print pos, k[0], k[1]
if k[0] < pos < k[0] + k[1]: # already highlighted
break
else:
self.setFormat(pos, len(r.cap(0)), self.style.format(State.LINKS))
pos = r.indexIn(text, pos + 1)
# Bold, Italic, Underline, Code, Tagged, Strikeout
for i, t in enumerate(text):
f = self.format(i)
beautifiers = [k[i] for k in formatArray]
self.setFormat(i, 1, self.style.beautifyFormat(f, beautifiers))
# Macro words
for r in [r'(%%)\b\w+\b', r'(%%)\b\w+\b\(.+\)']:
r = QRegExp(r)
示例14: OutputWidget
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setFontUnderline [as 别名]
class OutputWidget(QPlainTextEdit):
def __init__(self, parent):
super(OutputWidget, self).__init__(parent)
self._parent = parent
self.setReadOnly(True)
self.maxValue = 0
self.actualValue = 0
#traceback pattern
self.patLink = re.compile(r'(\s)*File "(.*?)", line \d.+')
#formats
font = QFont(settings.FONT_FAMILY, settings.FONT_SIZE)
self.plain_format = QTextCharFormat()
self.plain_format.setFont(font)
self.plain_format.setForeground(QBrush(QColor(
resources.CUSTOM_SCHEME.get("editor-text",
resources.COLOR_SCHEME["editor-text"]))))
self.error_format = QTextCharFormat()
self.error_format.setFont(font)
self.error_format.setAnchor(True)
self.error_format.setFontUnderline(True)
self.error_format.setUnderlineStyle(QTextCharFormat.SingleUnderline)
self.error_format.setUnderlineColor(Qt.red)
self.error_format.setForeground(Qt.blue)
self.error_format.setToolTip(_translate("OutputWidget", "Click to show the source"))
self.blockCountChanged[int].connect(self._scroll_area)
css = 'QPlainTextEdit {color: %s; background-color: %s;' \
'selection-color: %s; selection-background-color: %s;}' \
% (resources.CUSTOM_SCHEME.get('editor-text',
resources.COLOR_SCHEME['editor-text']),
resources.CUSTOM_SCHEME.get('editor-background',
resources.COLOR_SCHEME['editor-background']),
resources.CUSTOM_SCHEME.get('editor-selection-color',
resources.COLOR_SCHEME['editor-selection-color']),
resources.CUSTOM_SCHEME.get('editor-selection-background',
resources.COLOR_SCHEME['editor-selection-background']))
self.setStyleSheet(css)
def _scroll_area(self):
"""When new text is added to the widget, move the scroll to the end."""
if self.actualValue == self.maxValue:
self.moveCursor(QTextCursor.End)
def mousePressEvent(self, event):
"""
When the execution fail, allow to press the links in the traceback,
to go to the line when the error occur.
"""
QPlainTextEdit.mousePressEvent(self, event)
self.go_to_error(event)
def _refresh_output(self):
"""Read the output buffer from the process and append the text."""
#we should decode the bytes!
currentProcess = self._parent.currentProcess
text = currentProcess.readAllStandardOutput().data().decode('utf8')
verticalScroll = self.verticalScrollBar()
self.actualValue = verticalScroll.value()
self.maxValue = verticalScroll.maximum()
self.textCursor().insertText(text, self.plain_format)
def _refresh_error(self):
"""Read the error buffer from the process and append the text."""
#we should decode the bytes!
cursor = self.textCursor()
currentProcess = self._parent.currentProcess
text = currentProcess.readAllStandardError().data().decode('utf8')
text_lines = text.split('\n')
verticalScroll = self.verticalScrollBar()
self.actualValue = verticalScroll.value()
self.maxValue = verticalScroll.maximum()
for t in text_lines:
cursor.insertBlock()
if self.patLink.match(t):
cursor.insertText(t, self.error_format)
else:
cursor.insertText(t, self.plain_format)
def go_to_error(self, event):
"""Resolve the link and take the user to the error line."""
cursor = self.cursorForPosition(event.pos())
text = cursor.block().text()
if self.patLink.match(text):
file_path, lineno = self._parse_traceback(text)
main = main_container.MainContainer()
main.open_file(file_path)
main.editor_jump_to_line(lineno=int(lineno) - 1)
def _parse_traceback(self, text):
"""
Parse a line of python traceback and returns
a tuple with (file_name, lineno)
"""
file_word_index = text.find('File')
comma_min_index = text.find(',')
comma_max_index = text.rfind(',')
file_name = text[file_word_index + 6:comma_min_index - 1]
lineno = text[comma_min_index + 7:comma_max_index]
#.........这里部分代码省略.........