本文整理汇总了Python中PyQt5.QtWidgets.QPlainTextEdit.appendPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QPlainTextEdit.appendPlainText方法的具体用法?Python QPlainTextEdit.appendPlainText怎么用?Python QPlainTextEdit.appendPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QPlainTextEdit
的用法示例。
在下文中一共展示了QPlainTextEdit.appendPlainText方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QPlainTextEditLogger
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [as 别名]
class QPlainTextEditLogger(logging.Handler):
def __init__(self, parent):
super().__init__()
self.widget = QPlainTextEdit(parent)
self.widget.setReadOnly(True)
def emit(self, record):
msg = self.format(record)
self.widget.appendPlainText(msg)
示例2: TextLogElement
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [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)
示例3: PythonConsoleWidget
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [as 别名]
class PythonConsoleWidget(QWidget, MooseWidget):
"""
Widget holding the input/output of a python console.
Saves/restores history to preferences. This allows previous commands
to be saved/restored.
There is a global dict called "peacock" that allows saving arbitrary
variables in.
For example, peacock["your_variable"] could be any python variable.
Signals:
new_line: A new line of input. Argument is the input.
"""
new_line = pyqtSignal(str)
def __init__(self, **kwds):
super(PythonConsoleWidget, self).__init__(**kwds)
self.top_layout = WidgetUtils.addLayout(vertical=True)
self.setLayout(self.top_layout)
self.output = QPlainTextEdit(parent=self)
self.output.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.output.setReadOnly(False)
self.output.setFocusPolicy(Qt.ClickFocus)
self.output.setStyleSheet("QPlainTextEdit { background: black; color: white;}")
self.output.setTextInteractionFlags(Qt.TextSelectableByMouse|Qt.TextSelectableByKeyboard|Qt.LinksAccessibleByMouse|Qt.LinksAccessibleByKeyboard)
self.top_layout.addWidget(self.output)
self.input_layout = WidgetUtils.addLayout()
self.top_layout.addLayout(self.input_layout)
self.prompt = WidgetUtils.addLabel(self.input_layout, self, ">>>")
self.input_line = WidgetUtils.addLineEdit(self.input_layout, self, self._returnPressed)
self.input_line.setFocusPolicy(Qt.StrongFocus)
self.input_line.installEventFilter(self)
self.user_inputs = []
self.current_index = -1
# get a list of globals and locals from the callstack
self._global_data = {}
self._global_data['global_vars'] = globals()
self._global_data['peacock'] = {}
self.console = QPythonConsole(self._global_data, parent=self)
self.console.write_output.connect(self.output.appendPlainText)
self.output.appendPlainText("Peaock variables are in the dict 'peacock'")
self.output.appendPlainText("Global variables are in the dict 'global_vars'")
self.console.prompt_changed.connect(self.prompt.setText)
self.new_line.connect(self.console._newLine)
self.console._setPrompt()
self._loadHistory()
self.resize(600, 400)
self.setup()
def _loadHistory(self):
"""
Loads previous commands from settings.
"""
settings = QSettings()
history = settings.value("python/history", type=str)
if history != None:
for v in history:
self.user_inputs.append(str(v))
self.current_index = len(self.user_inputs)
def eventFilter(self, obj, event):
"""
Process QEvent
Input:
obj: The object that the event happened on
event: QEvent() object
Return:
True if we processed this event. False otherwise.
"""
if obj == self.input_line:
if event.type() == QEvent.KeyPress:
if event.key() == Qt.Key_Up:
self._changeInput(-1)
return True
elif event.key() == Qt.Key_Down:
self._changeInput(1)
return True
elif event.key() == Qt.Key_Tab:
# don't allow to tab out of the command line
return True
return False
def saveHistory(self):
"""
Save history into settings.
"""
settings = QSettings()
num_to_save = settings.value("python/history_size", type=int)
if num_to_save == None:
num_to_save = 50
settings.setValue("python/history_size", num_to_save)
settings.setValue("python/history", self.user_inputs[-num_to_save:])
def _changeInput(self, change):
"""
#.........这里部分代码省略.........
示例4: View
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [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)
示例5: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [as 别名]
#.........这里部分代码省略.........
self.topright = QFrame(self)
self.topright.setFrameShape(QFrame.StyledPanel)
self.topright_grid = QGridLayout(self)
self.topright.setLayout(self.topright_grid)
self.info_label = QLabel('===INFO===')
self.info_label.setAlignment(QtCore.Qt.AlignHCenter)
self.info_author = QLabel('Author: Kurashov Sergey')
self.info_author.setAlignment(QtCore.Qt.AlignHCenter)
self.info_contacts = QLabel('Contacts: [email protected]')
self.info_contacts.setAlignment(QtCore.Qt.AlignHCenter)
self.info_sourcecode = QLabel('<a href="https://github.com/shimielder/win_switcher">Sourcecode on GitHub</a>')
self.info_sourcecode.setAlignment(QtCore.Qt.AlignHCenter)
self.info_sourcecode.setOpenExternalLinks(True)
self.topright_grid.addWidget(self.info_label, 0, 0)
self.topright_grid.addWidget(self.info_author, 1, 0)
self.topright_grid.addWidget(self.info_contacts, 2, 0)
self.topright_grid.addWidget(self.info_sourcecode, 3, 0)
grid.addWidget(self.topright, 0, 1)
self.middle = QFrame(self)
self.middle.setFrameShape(QFrame.StyledPanel)
self.middle_grid = QGridLayout(self)
self.middle.setLayout(self.middle_grid)
self.dictionsries_label = QLabel('Dictionaries to switch:')
self.dict_one = QPlainTextEdit()
self.dict_one.clear()
self.dict_one.appendPlainText(options['layouts'][0])
self.dict_two = QPlainTextEdit()
self.dict_two.clear()
self.dict_two.appendPlainText(options['layouts'][1])
self.middle_grid.addWidget(self.dictionsries_label, 0, 0, 1, 4)
self.middle_grid.addWidget(self.dict_one, 1, 0, 1, 4)
self.middle_grid.addWidget(self.dict_two, 2, 0, 1, 4)
grid.addWidget(self.middle, 1, 0, 1, 2)
self.bottom = QFrame(self)
self.bottom.setFrameShape(QFrame.StyledPanel)
self.bottom_grid = QGridLayout(self)
self.bottom.setLayout(self.bottom_grid)
self.loglevel_label = QLabel('Logging level:')
self.loglevel_dropmenu = QComboBox(self)
self.loglevel_dropmenu.addItems(LOGGING_LEVELS)
self.loglevel_dropmenu.setCurrentIndex(LOGGING_LEVELS.index((options['log_level'].upper())))
self.loglevel_dropmenu.activated[str].connect(self.set_logginglevel)
# self.log_to_file_label = QLabel('Check to save logs to file')
self.log_to_file_chk = QCheckBox('Check to save logs to file')
self.log_to_file_chk.stateChanged.connect(self.set_log_to_file)
self.logging_output_label = QLabel('Logging output:')
self.logging_output_label.setAlignment(QtCore.Qt.AlignHCenter)
self.bottom_grid.addWidget(self.loglevel_label, 0, 0)
self.bottom_grid.addWidget(self.loglevel_dropmenu, 0, 1)
self.bottom_grid.addWidget(self.log_to_file_chk, 0, 3, 1, 1)
self.bottom_grid.addWidget(self.logging_output_label, 1, 0, 1, 4)
self.bottom_grid.addWidget(self.log_textbox.widget, 2, 0, 2, 4)
示例6: Window
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [as 别名]
#.........这里部分代码省略.........
self.step_flow_response_table = RowControlTableWidget([('Response Step', []), ('Match Criteria', ''), ('Step', []), ('Sleep Time', '0.0')])
vbox.addLayout(self.step_flow_response_table.layout)
self.step_flow_percentage_table = RowControlTableWidget([('Percentage', ''), ('Step', []), ('Sleep Time', '0.0')])
self.step_flow_percentage_table.set_text([['100', {'Next Step': ['Next Step', 'End Cycle', 'End User']}, '0.0']])
vbox.addLayout(self.step_flow_percentage_table.layout)
self.step_flow_conditional_table = RowControlTableWidget([('Phrase 1', ''), ('Conditional', ['<', '<=', '=', '=>', '>', '!=', 'in', 'not in']), ('Phrase 2', ''), ('Operator', ['AND', 'OR'])])
vbox.addLayout(self.step_flow_conditional_table.layout)
group_box.setLayout(vbox)
return group_box
def create_specific_step_details(self):
pass
# ------------------------------------------------------ end of creations ----------------------------------------------------------
# def create_actions(self):
# self.import_act = QAction("&Import...", self, shortcut="Ctrl+I", triggered=self.import_uj)
# self.export_act = QAction("&Export...", self, shortcut="Ctrl+E", triggered=self.export_uj)
# def update_content_subtypes(self, item):
# # item is supposed to be the text value of the combobox selection
# print('reached function update_content_subtypes with item=', item)
def debug__(self, message):
self.debug_edit.appendPlainText(message)
def load_data_file(self):
filename = QFileDialog.getOpenFileName(self, 'Open File', os.getenv('HOME'))
self.ddi_delimited_filename_widget.set_text(filename[0])
self.selected_ddi.file_name = filename
def import_uj(self, filename=[]):
if not filename:
filename = QFileDialog.getOpenFileName(self, 'Open File', os.getenv('HOME'))
self.uj = UserJourney('')
self.uj.import_uj(filename[0])
self.uj_name.set_text(self.uj.name)
ddi_nodes = []
for ddi in self.uj.dditems:
new_ddi_node = QTreeWidgetItem()
new_ddi_node.setText(0, ddi.name)
ddi_nodes.append(new_ddi_node)
self.ddi_tree.addTopLevelItems(ddi_nodes)
date_type_ddis = self.uj.find_ddis_by_attribute('type', 'DATE ')
if date_type_ddis:
self.ddi_date.related_ddi_box.reset_items({z.name:z.name for z in date_type_ddis})
relatable_type_ddis = []
for type_ in ['FLATFILE', 'LIST ', 'RESPONSE']:
relatable_type_ddis.extend(self.uj.find_ddis_by_attribute('type', type_))
if relatable_type_ddis:
self.ddi_related_ddi.reset_items({z.name:z.name for z in relatable_type_ddis})
sourceable_step_names = []
示例7: Assembler
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [as 别名]
#.........这里部分代码省略.........
qstringobj = self.plainTextEdit.toPlainText()
#import sys;sys.exit(42)
pth = parse( qstringobj )
#import sys;sys.exit(42)
if len(pth)==0:
printline("No of sequences found in Data window")
return
if self.filename is None:
self.fileSaveAs()
dir_, ext = os.path.splitext( str(self.filename))
fl, log = ypkpathway.pathway( pth, dir_, pYPKa_A = not self.checkbox.isChecked(), print = printline)
if not fl:
return
with open(os.path.join(dir_, "log.txt"),"w") as f: f.write(log)
shutil.copy2( str(self.filename), os.path.join(dir_, "INDATA_"+os.path.basename(str(self.filename))))
printline('')
printline('\n\nAssembly finished.')
printline('click on the Open pathway button above to open the pathway in the default web browser')
self.nb = fl.path
def qprintline(self, line):
'''Append one line to Solution Page.'''
self.plainTextEdit_2.appendPlainText(line.rstrip()) #.decode("utf8"))
QApplication.processEvents()
def openNB(self):
if self.nb:
subprocess.Popen(["ipython", "notebook", self.nb])
def aboutBox(self):
from PyQt5.QtCore import QT_VERSION_STR
from PyQt5.Qt import PYQT_VERSION_STR
from sip import SIP_VERSION_STR
from ._version import get_versions
__version__ = get_versions()["version"][:5]
del get_versions
from IPython import __version__ as IPython_version
QMessageBox.about(self, "About ypkpathway",
"""<b>Planning of yeast pathway kit constructions.</b>
<p>version: {}<br>
Copyright 2015-2017 Björn Johansson.
This software is released under a BSD style license.
This software comes with no warranties
expressed or implied.<br><br>
Python version: {}<br><br>
IPython version: {}<br>
Qt version: {}<br>
SIP version: {}<br>
PyQt version: {}<br>
pydna version: {}<br></p>
""".format(__version__,
示例8: View
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [as 别名]
#.........这里部分代码省略.........
if currentValue is not None:
self.currentValueList = currentValue
self.currentTimeList = timeValue
def Button2Plot(self):
self.painter.update_figure()
def closeEvent(self, event):
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()
示例9: SubscriberWindow
# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendPlainText [as 别名]
#.........这里部分代码省略.........
if not self._apply_filter(text):
return
except Exception as ex:
self._num_errors += 1
text = '!!! [%d] MESSAGE PROCESSING FAILED: %s' % (self._num_errors, ex)
else:
self._num_messages_past_filter += 1
self._msgs_per_sec_estimator.register_event(e.transfer.ts_monotonic)
# Sending the text for later rendering
try:
self._message_queue.put_nowait(text)
except queue.Full:
pass
def _toggle_start_stop(self):
try:
if self._subscriber_handle is None:
self._do_start()
else:
self._do_stop()
finally:
self._start_stop_button.setChecked(self._subscriber_handle is not None)
def _do_stop(self):
if self._subscriber_handle is not None:
self._subscriber_handle.remove()
self._subscriber_handle = None
self._pause_button.setChecked(False)
self.setWindowTitle(self.WINDOW_NAME_PREFIX)
def _do_start(self):
self._do_stop()
self._do_clear()
try:
selected_type = self._type_selector.currentText().strip()
if not selected_type:
return
data_type = uavcan.TYPENAMES[selected_type]
except Exception as ex:
show_error('Subscription error', 'Could not load requested data type', ex, self)
return
try:
self._subscriber_handle = self._node.add_handler(data_type, self._on_message)
except Exception as ex:
show_error('Subscription error', 'Could not create requested subscription', ex, self)
return
self.setWindowTitle('%s [%s]' % (self.WINDOW_NAME_PREFIX, selected_type))
self._start_stop_button.setChecked(True)
def _do_redraw(self):
self._num_messages_total_label.set(self._num_messages_total)
self._num_messages_past_filter_label.set(self._num_messages_past_filter)
estimated_rate = self._msgs_per_sec_estimator.get_rate_with_timestamp()
self._msgs_per_sec_label.set('N/A' if estimated_rate is None else ('%.0f' % estimated_rate[0]))
if self._pause_button.isChecked():
return
self._log_viewer.setUpdatesEnabled(False)
while True:
try:
text = self._message_queue.get_nowait()
except queue.Empty:
break
else:
self._log_viewer.appendPlainText(text + '\n')
self._log_viewer.setUpdatesEnabled(True)
def _update_data_type_list(self):
logger.info('Updating data type list')
if self._show_all_message_types.isChecked():
items = self._active_data_type_detector.get_names_of_all_message_types_with_data_type_id()
else:
items = self._active_data_type_detector.get_names_of_active_messages()
self._type_selector.clear()
self._type_selector.addItems(items)
def _do_clear(self):
self._num_messages_total = 0
self._num_messages_past_filter = 0
self._do_redraw()
self._log_viewer.clear()
def closeEvent(self, qcloseevent):
try:
self._subscriber_handle.close()
except Exception:
pass
super(SubscriberWindow, self).closeEvent(qcloseevent)
@staticmethod
def spawn(parent, node, active_data_type_detector):
SubscriberWindow(parent, node, active_data_type_detector).show()