当前位置: 首页>>代码示例>>Python>>正文


Python QTextCharFormat.merge方法代码示例

本文整理汇总了Python中PyQt5.QtGui.QTextCharFormat.merge方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat.merge方法的具体用法?Python QTextCharFormat.merge怎么用?Python QTextCharFormat.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtGui.QTextCharFormat的用法示例。


在下文中一共展示了QTextCharFormat.merge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: highlightBlock

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import merge [as 别名]
	def highlightBlock(self, text):
		# Syntax highlighter
		if self.docType in self.patternsDict:
			for number in self.patternsDict[self.docType]:
				pattern = self.patterns[number]
				for match in pattern[0].finditer(text):
					for i, formatter in enumerate(pattern[1:]):
						charFormat = QTextCharFormat()
						formatter.format(charFormat)
						self.setFormat(QString_length(text[:match.start(i)]),
						               QString_length(match.group(i)),
						               charFormat)
		for match in reSpacesOnEnd.finditer(text):
			charFormat = QTextCharFormat()
			charFormat.setBackground(colorScheme['whitespaceOnEnd'])
			self.setFormat(QString_length(text[:match.start()]),
			               QString_length(match.group(0)),
			               charFormat)
		# Spell checker
		if self.dictionary:
			charFormat = QTextCharFormat()
			charFormat.setUnderlineColor(Qt.red)
			charFormat.setUnderlineStyle(QTextCharFormat.WaveUnderline)
			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(QString_length(text[:match.start()]),
					               QString_length(match.group(0)),
					               finalFormat)
开发者ID:starofrainnight,项目名称:retext,代码行数:33,代码来源:highlighter.py

示例2: highlightBlock

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import merge [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)
开发者ID:ahnan4arch,项目名称:retext,代码行数:61,代码来源:highlighter.py

示例3: highlightBlock

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import merge [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)
开发者ID:jmpews,项目名称:retext,代码行数:53,代码来源:highlighter.py

示例4: highlightBlock

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import merge [as 别名]
	def highlightBlock(self, text):
		patterns = (
			# regex,         color,
			(reHtmlTags,     FG('htmlTags') | QFont.Bold),                          # 0
			(reHtmlSymbols,  FG('htmlSymbols') | QFont.Bold),                       # 1
			(reHtmlStrings,  FG('htmlStrings') | QFont.Bold),                       # 2
			(reHtmlComments, FG('htmlComments')),                                   # 3
			(reAsterisks,    ITAL),                                                 # 4
			(reUnderline,    ITAL),                                                 # 5
			(reDblAsterisks, NF | QFont.Bold),                                      # 6
			(reDblUnderline, NF | QFont.Bold),                                      # 7
			(reTrpAsterisks, ITAL | QFont.Bold),                                    # 8
			(reTrpUnderline, ITAL | QFont.Bold),                                    # 9
			(reMkdHeaders,   NF | QFont.Black),                                     # 10
			(reMkdLinksImgs, FG('markdownLinks')),                                  # 11
			(reMkdLinkRefs,  ITAL | UNDL),                                          # 12
			(reBlockQuotes,  FG('blockquotes')),                                    # 13
			(reReSTDirects,  FG('restDirectives') | QFont.Bold),                    # 14
			(reReSTRoles,    NF, FG('restRoles') | QFont.Bold, FG('htmlStrings')),  # 15
			(reTextileHdrs,  NF | QFont.Black),                                     # 16
			(reTextileQuot,  FG('blockquotes')),                                    # 17
			(reAsterisks,    NF | QFont.Bold),                                      # 18
			(reDblUnderline, ITAL),                                                 # 19
			(reMkdCodeSpans, FG('codeSpans')),                                      # 20
			(reReSTCodeSpan, FG('codeSpans')),                                      # 21
			(reReSTLinks,    NF, NF, ITAL | UNDL, NF),                              # 22
			(reReSTLinkRefs, NF, FG('markdownLinks'), ITAL | UNDL),                 # 23
			(reReSTFldLists, NF, FG('restDirectives')),                             # 24
			(reMkdMathSpans, FG('codeSpans')),                                      # 25
		)

		patternsDict = {
			'Markdown': (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 20, 25),
			'reStructuredText': (4, 6, 14, 15, 21, 22, 23, 24),
			'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]
				for match in pattern[0].finditer(text):
					for i, formatter in enumerate(pattern[1:]):
						charFormat = QTextCharFormat()
						formatter.format(charFormat)
						self.setFormat(match.start(i), match.end(i) - match.start(i), 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)
开发者ID:cufrancis,项目名称:retext,代码行数:63,代码来源:highlighter.py

示例5: textFormat

# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import merge [as 别名]
 def textFormat(self, group, name):
     """Return a QTextCharFormat() for the specified group and name."""
     inherit = self._inherits[group].get(name)
     f = QTextCharFormat(self.defaultStyles[inherit]) if inherit else QTextCharFormat()
     f.merge(self.allStyles[group][name])
     return f
开发者ID:AlexSchr,项目名称:frescobaldi,代码行数:8,代码来源:textformats.py


注:本文中的PyQt5.QtGui.QTextCharFormat.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。