本文整理汇总了Python中PyQt5.QtGui.QTextCharFormat.setToolTip方法的典型用法代码示例。如果您正苦于以下问题:Python QTextCharFormat.setToolTip方法的具体用法?Python QTextCharFormat.setToolTip怎么用?Python QTextCharFormat.setToolTip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QTextCharFormat
的用法示例。
在下文中一共展示了QTextCharFormat.setToolTip方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setToolTip [as 别名]
def __init__(self, parent):
super(OutputWidget, self).__init__(parent)
self._parent = parent
self.setWordWrapMode(0)
self.setMouseTracking(True)
self.setFrameShape(0)
self.setUndoRedoEnabled(False)
# Traceback pattern
self.patLink = re.compile(r'(\s)*File "(.*?)", line \d.+')
# For user input
self.__input = []
self.setFont(settings.FONT)
# Formats
plain_format = QTextCharFormat()
normal_format = QTextCharFormat()
normal_format.setForeground(
QColor(resources.COLOR_SCHEME.get("editor.foreground")))
error_format = QTextCharFormat()
error_format.setForeground(QColor('#ff6c6c'))
error_format2 = QTextCharFormat()
error_format2.setToolTip(translations.TR_CLICK_TO_SHOW_SOURCE)
error_format2.setUnderlineStyle(QTextCharFormat.DashUnderline)
error_format2.setForeground(QColor('#ff6c6c'))
error_format2.setUnderlineColor(QColor('#ff6c6c'))
self._text_formats = {
self.Format.NORMAL: normal_format,
self.Format.PLAIN: plain_format,
self.Format.ERROR: error_format,
self.Format.ERROR_UNDERLINE: error_format2
}
self.blockCountChanged[int].connect(
lambda: self.moveCursor(QTextCursor.End))
# Style
palette = self.palette()
palette.setColor(
palette.Base,
QColor(resources.COLOR_SCHEME.get('editor.background')))
self.setPalette(palette)
示例2: writeMessage
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setToolTip [as 别名]
def writeMessage(self, message, type):
"""This writes both status and output messages to the log.
For output messages also the correct encoding is re-applied:
LilyPond writes filenames out in the system's filesystemencoding,
while the messages are always written in UTF-8 encoding...
"""
if type == job.STDERR:
# find filenames in message:
parts = iter(errors.message_re.split(message.encode('latin1')))
msg = next(parts).decode('utf-8', 'replace')
self.cursor.insertText(msg, self.textFormat(type))
enc = sys.getfilesystemencoding()
for url, path, line, col, msg in zip(*itertools.repeat(parts, 5)):
url = url.decode(enc)
path = path.decode(enc)
msg = msg.decode('utf-8', 'replace')
if self._rawView:
fmt = QTextCharFormat(self.textFormat(type))
display_url = url
else:
fmt = QTextCharFormat(self.textFormat("link"))
display_url = os.path.basename(path)
fmt.setAnchor(True)
fmt.setAnchorHref(str(len(self._errors)))
fmt.setToolTip(_("Click to edit this file"))
pos = self.cursor.position()
self.cursor.insertText(display_url, fmt)
self.cursor.insertText(msg, self.textFormat(type))
self._errors.append((pos, self.cursor.position(), url))
else:
if type == job.STDOUT:
# we use backslashreplace because LilyPond sometimes seems to write
# incorrect utf-8 to standard output in \displayMusic, \displayScheme
# functions etc.
message = message.encode('latin1').decode('utf-8', 'backslashreplace')
super(LogWidget, self).writeMessage(message, type)
示例3: add_io
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setToolTip [as 别名]
def add_io(self, vbox):
if self.tx.locktime > 0:
vbox.addWidget(QLabel("LockTime: %d\n" % self.tx.locktime))
vbox.addWidget(QLabel(_("Inputs") + ' (%d)'%len(self.tx.inputs())))
ext = QTextCharFormat()
rec = QTextCharFormat()
rec.setBackground(QBrush(ColorScheme.GREEN.as_color(background=True)))
rec.setToolTip(_("Wallet receive address"))
chg = QTextCharFormat()
chg.setBackground(QBrush(ColorScheme.YELLOW.as_color(background=True)))
chg.setToolTip(_("Wallet change address"))
twofactor = QTextCharFormat()
twofactor.setBackground(QBrush(ColorScheme.BLUE.as_color(background=True)))
twofactor.setToolTip(_("TrustedCoin (2FA) fee for the next batch of transactions"))
def text_format(addr):
if self.wallet.is_mine(addr):
return chg if self.wallet.is_change(addr) else rec
elif self.wallet.is_billing_address(addr):
return twofactor
return ext
def format_amount(amt):
return self.main_window.format_amount(amt, whitespaces=True)
i_text = QTextEditWithDefaultSize()
i_text.setFont(QFont(MONOSPACE_FONT))
i_text.setReadOnly(True)
cursor = i_text.textCursor()
for x in self.tx.inputs():
if x['type'] == 'coinbase':
cursor.insertText('coinbase')
else:
prevout_hash = x.get('prevout_hash')
prevout_n = x.get('prevout_n')
cursor.insertText(prevout_hash + ":%-4d " % prevout_n, ext)
addr = self.wallet.get_txin_address(x)
if addr is None:
addr = ''
cursor.insertText(addr, text_format(addr))
if x.get('value'):
cursor.insertText(format_amount(x['value']), ext)
cursor.insertBlock()
vbox.addWidget(i_text)
vbox.addWidget(QLabel(_("Outputs") + ' (%d)'%len(self.tx.outputs())))
o_text = QTextEditWithDefaultSize()
o_text.setFont(QFont(MONOSPACE_FONT))
o_text.setReadOnly(True)
cursor = o_text.textCursor()
for o in self.tx.get_outputs_for_UI():
addr, v = o.address, o.value
cursor.insertText(addr, text_format(addr))
if v is not None:
cursor.insertText('\t', ext)
cursor.insertText(format_amount(v), ext)
cursor.insertBlock()
vbox.addWidget(o_text)
示例4: OutputWidget
# 需要导入模块: from PyQt5.QtGui import QTextCharFormat [as 别名]
# 或者: from PyQt5.QtGui.QTextCharFormat import setToolTip [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]
#.........这里部分代码省略.........