本文整理汇总了Python中PyQt5.QtWidgets.QPlainTextEdit.verticalScrollBar方法的典型用法代码示例。如果您正苦于以下问题:Python QPlainTextEdit.verticalScrollBar方法的具体用法?Python QPlainTextEdit.verticalScrollBar怎么用?Python QPlainTextEdit.verticalScrollBar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QPlainTextEdit
的用法示例。
在下文中一共展示了QPlainTextEdit.verticalScrollBar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TextLogElement
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import verticalScrollBar [as 别名]
class TextLogElement(object):
def __init__(self,
maximum_block_count: int = 1000,
font_size_pt: int = 10,
font_family: str = "Courier",
title: str = "Log") -> None:
# For nested layouts: (1) create everything, (2) lay out
self.log_group = StyledQGroupBox(title)
log_layout_1 = QVBoxLayout()
log_layout_2 = QHBoxLayout()
self.log = QPlainTextEdit()
self.log.setReadOnly(True)
self.log.setLineWrapMode(QPlainTextEdit.NoWrap)
self.log.setMaximumBlockCount(maximum_block_count)
font = self.log.font()
font.setFamily(font_family)
font.setPointSize(font_size_pt)
log_clear_button = QPushButton('Clear log')
log_clear_button.clicked.connect(self.log.clear)
log_copy_button = QPushButton('Copy to clipboard')
log_copy_button.clicked.connect(self.copy_whole_log)
log_layout_2.addWidget(log_clear_button)
log_layout_2.addWidget(log_copy_button)
log_layout_2.addStretch(1)
log_layout_1.addWidget(self.log)
log_layout_1.addLayout(log_layout_2)
self.log_group.setLayout(log_layout_1)
def get_widget(self) -> QWidget:
return self.log_group
def add(self, msg: str) -> None:
# http://stackoverflow.com/questions/16568451
# self.log.moveCursor(QTextCursor.End)
self.log.appendPlainText(msg)
# ... will append it as a *paragraph*, i.e. no need to add a newline
# self.scroll_to_end_of_log()
def copy_whole_log(self) -> None:
# Ctrl-C will copy the selected parts.
# log.copy() will copy the selected parts.
self.log.selectAll()
self.log.copy()
self.log.moveCursor(QTextCursor.End)
self.scroll_to_end_of_log()
def scroll_to_end_of_log(self) -> None:
vsb = self.log.verticalScrollBar()
vsb.setValue(vsb.maximum())
hsb = self.log.horizontalScrollBar()
hsb.setValue(0)
示例2: View
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import verticalScrollBar [as 别名]
#.........这里部分代码省略.........
self.port_edit = QLineEdit()
self.port_edit.editingFinished.connect(self.changePort)
port_hbox.addWidget(self.port_edit)
vbox.addLayout(port_hbox)
self.setLayout(vbox)
def show_error(self, value):
msg = QMessageBox(
QMessageBox.NoIcon, 'Error occured.', value, QMessageBox.Ok)
msg.exec()
#==============================================================================
# Get, set
#==============================================================================
def set_queue(self, queue):
self.queue = queue
def set_end_cmd(self, end_cmd):
self.end_cmd = end_cmd
def set_autoscroll(self, value):
print('Set autoscroll: {}.'.format(value))
self.autoscroll = value
def set_port(self, value):
self.port_edit.insert(value)
def get_cmd(self):
return self.cmd_edit.text()
def set_eol(self, value):
self.eol_menu.setCurrentIndex(value)
def closeEvent(self, event):
self.end_cmd()
QWidget.closeEvent(self, event)
print('exit')
def update_gui(self):
self.process_incoming()
self.update()
def process_incoming(self):
while self.queue.qsize():
try:
msg = self.queue.get(0)
# Check contents of message and do what it says
# As a test, we simply print it
print(str(msg))
self.editer.appendPlainText(str(msg))
if self.autoscroll:
self.editer.ensureCursorVisible()
self.scroll_down()
except Queue.empty:
pass
def scroll_down(self):
sb = self.editer.verticalScrollBar()
sb.setValue(sb.maximum())
self.editer.moveCursor(QTextCursor.End)
def changePort(self):
if not self.msg_sent:
self.msg_sent = True
self.emit_port_changed()
else:
self.msg_sent = False
return None
#==============================================================================
# Signals
#==============================================================================
def emit_send_data(self):
self.send_data.emit(self.get_cmd())
self.cmd_edit.clear()
def emit_br_changed(self, value):
baudrate = self.br_menu.itemText(value)[:-5]
self.baudrate_changed.emit(baudrate)
def emit_eol_changed(self, value):
self.eol_changed.emit(value)
def emit_port_changed(self):
self.port_edit.clearFocus()
self.port_changed.emit(self.port_edit.text())
#==============================================================================
# Events
#==============================================================================
def ModScrollContentsBy(self, dx, dy):
if self.autoscroll:
self.editer.ensureCursorVisible()
else:
QPlainTextEdit.scrollContentsBy(self.editer, dx, dy)
示例3: Diff
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import verticalScrollBar [as 别名]
class Diff(QDockWidget):
""" A diff widget.
This class defines a dock widget which shows the differences between
the original page content retrieved in the last request and the current
content in the voice editor.
"""
def __init__(self):
""" Widget initialization
"""
super().__init__('Show changes')
self.beforePTE = QPlainTextEdit()
self.afterPTE = QPlainTextEdit()
# widgets are read-only
self.beforePTE.setReadOnly(True)
self.afterPTE.setReadOnly(True)
# bind the scroll position of the two widgets
beforeScrollbar = self.beforePTE.verticalScrollBar()
afterScrollbar = self.afterPTE.verticalScrollBar()
beforeScrollbar.valueChanged.connect(afterScrollbar.setValue)
afterScrollbar.valueChanged.connect(beforeScrollbar.setValue)
hbox = QHBoxLayout()
hbox.addWidget(self.beforePTE)
hbox.addWidget(self.afterPTE)
widget = QWidget()
widget.setLayout(hbox)
# # sizeHint for the widget
# def sizeHint(self):
# return QSize(self.width(), 150)
# widget.sizeHint = types.MethodType(sizeHint, widget)
self.setWidget(widget)
def showDiff(self, before, after):
""" Compute the diff and highlight changed parts.
Parameters
----------
self : QWidget
before : str
Original text.
after : str
Edited text.
"""
beforeCursor = self.beforePTE.textCursor()
afterCursor = self.afterPTE.textCursor()
textFormat = QTextCharFormat()
# delete any previous background
textFormat.setBackground(QBrush(QColor('transparent')))
beforeCursor.mergeCharFormat(textFormat)
afterCursor.mergeCharFormat(textFormat)
self.beforePTE.setPlainText(before)
self.afterPTE.setPlainText(after)
# get matching sequences
sm = SequenceMatcher(a=before, b=after)
i, j, k = 0, 0, 0
# highlight mismatching sequences
# NOTE: [ii:ii+kk] and [jj:jj+kk] are the matching sequences for the
# first and second string, while [i+k:ii] and [j+k:jj] are the
# mismatching ones
for ii, jj, kk in sm.get_matching_blocks():
# highlight with red the removed parts in the before text
beforeCursor.setPosition(i + k)
beforeCursor.movePosition(
QTextCursor.Right,
QTextCursor.KeepAnchor,
ii - i - k)
textFormat.setBackground(QBrush(QColor('#F99')))
beforeCursor.mergeCharFormat(textFormat)
# highlight with green the added parts in the after text
afterCursor.setPosition(j + k)
afterCursor.movePosition(
QTextCursor.Right,
QTextCursor.KeepAnchor,
jj - j - k)
textFormat.setBackground(QBrush(QColor('#CFC')))
afterCursor.mergeCharFormat(textFormat)
i, j, k = ii, jj, kk
示例4: View
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import verticalScrollBar [as 别名]
#.........这里部分代码省略.........
self.last.saveLast(self.lastpick)
self.end_cmd()
QWidget.closeEvent(self, event)
print('exit')
def beginGui(self):
self.update()
def update_gui(self):
self.process_incoming()
self.update()
def updataFigure(self,newtime,power):
# self.setCurrentValue(currentValue, timeValue)
self.painter.XYaxit(newtime,power)
self.painter.update_figure()
# print('update?')
# self.update()
def process_incoming(self):
while self.queue.qsize():
try:
msg = self.queue.get(0)
self.editer.appendPlainText(str(msg))
#show to the textplain?
#if self.autoscroll:
self.editer.ensureCursorVisible()
self.scroll_down()
except Queue.empty:
print('=== empty queue ===')
def scroll_down(self):
sb = self.editer.verticalScrollBar()
sb.setValue(sb.maximum())
def changePort(self):
if not self.msg_sent:
self.msg_sent = True
self.emit_port_changed()
else:
self.msg_sent = False
return None
#==============================================================================
# Signals
#==============================================================================
def emit_send_data(self):
self.send_data.emit(self.get_cmd())
self.cmd_edit.clear()
def emit_send_command(self,command):
self.send_data.emit(command)
self.cmd_edit.clear()
def emit_br_src_changed(self, value):
baudrate = self.baundrateMenu.itemText(value)[:-5]
self.baudrate_src_changed.emit(baudrate)
def emit_br_pump_changed(self, value):
baudrate = self.baundrateMenu.itemText(value)[:-5]
self.baudrate_pump_changed.emit(baudrate)
# def emit_br_temp_changed(self, value):
示例5: LogWindow
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import verticalScrollBar [as 别名]
class LogWindow(QMainWindow):
emit_msg = pyqtSignal(str)
def __init__(self,
level: int = logging.INFO,
window_title: str = "Python log",
logger: logging.Logger = None,
min_width: int = 800,
min_height: int = 400,
maximum_block_count: int = 1000) -> None:
super().__init__()
self.setStyleSheet(LOGEDIT_STYLESHEET)
self.handler = HtmlColorHandler(self.log_message, level)
self.may_close = False
self.set_may_close(self.may_close)
self.setWindowTitle(window_title)
if min_width:
self.setMinimumWidth(min_width)
if min_height:
self.setMinimumHeight(min_height)
log_group = StyledQGroupBox("Log")
log_layout_1 = QVBoxLayout()
log_layout_2 = QHBoxLayout()
self.log = QPlainTextEdit()
# QPlainTextEdit better than QTextEdit because it supports
# maximumBlockCount while still allowing HTML (via appendHtml,
# not insertHtml).
self.log.setReadOnly(True)
self.log.setLineWrapMode(QPlainTextEdit.NoWrap)
self.log.setMaximumBlockCount(maximum_block_count)
log_clear_button = QPushButton('Clear log')
log_clear_button.clicked.connect(self.log.clear)
log_copy_button = QPushButton('Copy to clipboard')
log_copy_button.clicked.connect(self.copy_whole_log)
log_layout_2.addWidget(log_clear_button)
log_layout_2.addWidget(log_copy_button)
log_layout_2.addStretch()
log_layout_1.addWidget(self.log)
log_layout_1.addLayout(log_layout_2)
log_group.setLayout(log_layout_1)
main_widget = QWidget(self)
self.setCentralWidget(main_widget)
main_layout = QVBoxLayout(main_widget)
main_layout.addWidget(log_group)
self.emit_msg.connect(self.log_internal)
if logger:
logger.addHandler(self.get_handler())
def get_handler(self) -> logging.Handler:
return self.handler
def set_may_close(self, may_close: bool) -> None:
# log.debug("LogWindow: may_close({})".format(may_close))
self.may_close = may_close
# return
if may_close:
self.setWindowFlags(self.windowFlags() | Qt.WindowCloseButtonHint)
else:
self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint)
self.show()
# ... or it will be hidden (in a logical not a real way!) by
# setWindowFlags(), and thus mess up the logic for the whole Qt app
# exiting (since qt_app.exec_() runs until there are no more windows
# being shown).
def copy_whole_log(self) -> None:
# Ctrl-C will copy the selected parts.
# log.copy() will copy the selected parts.
self.log.selectAll()
self.log.copy()
self.log.moveCursor(QTextCursor.End)
self.scroll_to_end_of_log()
def scroll_to_end_of_log(self) -> None:
vsb = self.log.verticalScrollBar()
vsb.setValue(vsb.maximum())
hsb = self.log.horizontalScrollBar()
hsb.setValue(0)
# noinspection PyPep8Naming
def closeEvent(self, event: QCloseEvent) -> None:
"""Trap exit."""
if not self.may_close:
# log.debug("LogWindow: ignore closeEvent")
event.ignore()
else:
# log.debug("LogWindow: accept closeEvent")
event.accept()
def log_message(self, html: str) -> None:
# Jump threads via a signal
self.emit_msg.emit(html)
@pyqtSlot(str)
#.........这里部分代码省略.........