本文整理汇总了Python中PyQt5.QtWidgets.QPlainTextEdit类的典型用法代码示例。如果您正苦于以下问题:Python QPlainTextEdit类的具体用法?Python QPlainTextEdit怎么用?Python QPlainTextEdit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPlainTextEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GalleryDownloaderUrlExtracter
class GalleryDownloaderUrlExtracter(QWidget):
url_emit = pyqtSignal(str)
def __init__(self, parent=None):
super().__init__(parent, flags=Qt.Window|Qt.WindowStaysOnTopHint)
self.main_layout = QVBoxLayout(self)
self.text_area = QPlainTextEdit(self)
self.text_area.setPlaceholderText("URLs are seperated by a newline")
self.main_layout.addWidget(self.text_area)
self.text_area.setWordWrapMode(QTextOption.NoWrap)
add_to_queue = QPushButton('Add to queue')
add_to_queue.adjustSize()
add_to_queue.setFixedWidth(add_to_queue.width())
add_to_queue.clicked.connect(self.add_to_queue)
self.main_layout.addWidget(add_to_queue, 0, Qt.AlignRight)
self.setWindowIcon(QIcon(app_constants.APP_ICO_PATH))
self.show()
def add_to_queue(self):
txt = self.text_area.document().toPlainText()
urls = txt.split('\n')
for u in urls:
if u:
self.url_emit.emit(u)
self.close()
示例2: PackageTab
class PackageTab(QWidget):
configChanged = pyqtSignal()
def __init__(self):
super(QWidget, self).__init__()
layout = QFormLayout()
self.setLayout(layout)
self.buildDependencies = QPlainTextEdit()
self.buildDependencies.textChanged.connect(self.buildDependenciesChanged)
self.buildDependencies.setMinimumHeight(70)
layout.addRow('Build Dependencies', self.buildDependencies)
self.runDependencies = QPlainTextEdit()
self.runDependencies.textChanged.connect(self.runDependenciesChanged)
self.runDependencies.setMinimumHeight(70)
layout.addRow('Run Dependencies', self.runDependencies)
def buildDependenciesChanged(self):
if self.config is not None:
self.config.setBuildDependencies(self.buildDependencies.toPlainText())
self.configChanged.emit()
def runDependenciesChanged(self):
if self.config is not None:
self.config.setRunDependencies(self.runDependencies.toPlainText())
self.configChanged.emit()
def setConfig(self, config):
self.config = config
self.buildDependencies.setPlainText(self.config.getBuildDependenciesAsText())
self.runDependencies.setPlainText(self.config.getRunDependenciesAsText())
示例3: __init__
def __init__(self, Wizard, parent=None):
super(RequiresPage, self).__init__(parent)
self.base = Wizard.base
self.setTitle(self.tr("Requires page"))
self.setSubTitle(self.tr("Write requires and provides"))
buildRequiresLabel = QLabel("BuildRequires: ")
self.bRequiresEdit = QPlainTextEdit()
self.bRequiresEdit.setMaximumHeight(40)
requiresLabel = QLabel("Requires: ")
self.requiresEdit = QPlainTextEdit()
self.requiresEdit.setMaximumHeight(40)
preovidesLabel = QLabel("Provides: ")
self.previdesEdit = QPlainTextEdit()
grid = QGridLayout()
grid.addWidget(buildRequiresLabel, 0, 0)
grid.addWidget(self.bRequiresEdit, 1, 0)
grid.addWidget(requiresLabel, 2, 0)
grid.addWidget(self.requiresEdit, 3, 0,)
grid.addWidget(preovidesLabel, 4, 0)
grid.addWidget(self.previdesEdit, 5, 0)
self.setLayout(grid)
示例4: show_info_dialog
def show_info_dialog( caption, parent, initial_text ):
dialog = QDialog( parent )
dialog.setWindowTitle( caption )
# Create OK and Cancel buttons in a horizontal box.
ok_button = QPushButton("OK")
ok_button.setDefault(True)
ok_button.clicked.connect(dialog.accept)
cancel_button = QPushButton("Cancel")
cancel_button.setDefault(False)
cancel_button.clicked.connect(dialog.reject)
hbox = QHBoxLayout()
hbox.addWidget(cancel_button,0)
hbox.addStretch()
hbox.addWidget(ok_button,0)
# Lay out a Plain Text Edit above the buttons.
vbox = QVBoxLayout()
pt_editor = QPlainTextEdit()
pt_editor.document().setPlainText( initial_text )
vbox.addWidget(pt_editor,1)
vbox.addLayout(hbox,0)
dialog.setLayout(vbox)
result = dialog.exec_()
if result :
return pt_editor.document().toPlainText()
else :
return None
示例5: keyPressEvent
def keyPressEvent(self, e):
if self.isReadOnly():
return
if self.is_special_key(e):
e.ignore()
return
QPlainTextEdit.keyPressEvent(self, e)
ctrlOrShift = e.modifiers() and (Qt.ControlModifier or Qt.ShiftModifier)
if self.completer is None or (ctrlOrShift and not e.text()):
return
if not self.suggestions_enabled:
return
eow = "[email protected]#$%^&*()_+{}|:\"<>?,./;'[]\\-="
hasModifier = (e.modifiers() != Qt.NoModifier) and not ctrlOrShift
completionPrefix = self.text_under_cursor()
if hasModifier or not e.text() or len(completionPrefix) < 1 or eow.find(e.text()[-1]) >= 0:
self.completer.popup().hide()
return
if completionPrefix != self.completer.completionPrefix():
self.completer.setCompletionPrefix(completionPrefix)
self.completer.popup().setCurrentIndex(self.completer.completionModel().index(0, 0))
cr = self.cursorRect()
cr.setWidth(self.completer.popup().sizeHintForColumn(0) + self.completer.popup().verticalScrollBar().sizeHint().width())
self.completer.complete(cr)
示例6: __init__
def __init__(self):
super(self.__class__, self).__init__()
self.name_label = QLabel("Name (optional):")
self.name_line_edit = QLineEdit()
self.introducer_label = QLabel("Introducer fURL:")
self.introducer_text_edit = QPlainTextEdit()
self.introducer_text_edit.setMaximumHeight(70)
self.introducer_text_edit.setTabChangesFocus(True)
self.description_label = QLabel("Description (optional):")
self.description_text_edit = QPlainTextEdit()
self.description_text_edit.setMaximumHeight(70)
self.description_text_edit.setTabChangesFocus(True)
self.push_button = QPushButton("Save")
form = QFormLayout()
form.setWidget(0, QFormLayout.LabelRole, self.name_label)
form.setWidget(0, QFormLayout.FieldRole, self.name_line_edit)
form.setWidget(1, QFormLayout.LabelRole, self.introducer_label)
form.setWidget(1, QFormLayout.FieldRole, self.introducer_text_edit)
#form.setWidget(2, QFormLayout.LabelRole, self.description_label)
#form.setWidget(2, QFormLayout.FieldRole, self.description_text_edit)
form.setWidget(3, QFormLayout.FieldRole, self.push_button)
hbox = QHBoxLayout(self)
#hbox.addItem(QSpacerItem(100, 0, QSizePolicy.Preferred, 0))
hbox.addLayout(form)
示例7: Window
class Window(QWidget):
def __init__(self):
super().__init__()
# Make widgets #################
self.edit = QPlainTextEdit()
self.btn = QPushButton("Print")
self.edit.setPlaceholderText("Type something here and press the 'Print' button")
# Set button slot ##############
self.btn.clicked.connect(self.printText)
# Set the layout ###############
vbox = QVBoxLayout()
vbox.addWidget(self.edit)
vbox.addWidget(self.btn)
self.setLayout(vbox)
def printText(self):
print(self.edit.toPlainText())
示例8: keyPressEvent
def keyPressEvent(self, event):
#if self.completer.popup().isVisible():
#if event.key() in (Qt.Key_Enter, Qt.Key_Return, Qt.Key_Tab):
#event.ignore()
#self.completer.popup().hide()
#return
#elif event.key in (Qt.Key_Space, Qt.Key_Escape, Qt.Key_Backtab):
#self.completer.popup().hide()
self._check_event_on_selection(event)
if self._pre_key_press.get(event.key(), lambda x: False)(event):
return
if event.text() in (set(BRACES.values()) - set(["'", '"'])):
cursor = self.textCursor()
cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor)
brace = cursor.selection().toPlainText()
cursor = self.textCursor()
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
braceClose = cursor.selection().toPlainText()
if BRACES.get(brace, False) == event.text() and \
braceClose == event.text():
self.moveCursor(QTextCursor.Right)
return
QPlainTextEdit.keyPressEvent(self, event)
if event.text() in BRACES:
cursor = self.textCursor()
cursor.movePosition(QTextCursor.StartOfLine,
QTextCursor.KeepAnchor)
self.textCursor().insertText(
BRACES[event.text()])
self.moveCursor(QTextCursor.Left)
示例9: keyPressEvent
def keyPressEvent(self, event):
if self.isReadOnly():
return
modifiers = event.modifiers()
if modifiers in (Qt.AltModifier, Qt.ControlModifier):
return
if modifiers == Qt.ShiftModifier:
if not event.text():
return
key = event.key()
if key == Qt.Key_Backspace:
text_selected = self.textCursor().selectedText()
if text_selected:
del self.__input[-len(text_selected):]
else:
try:
self.__input.pop()
except IndexError:
return
elif key in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down,
Qt.Key_CapsLock):
return
elif key in (Qt.Key_Enter, Qt.Key_Return):
data = "".join(self.__input)
self.inputRequested.emit(data)
self.__input.clear()
else:
self.__input.append(event.text())
QPlainTextEdit.keyPressEvent(self, event)
示例10: __init__
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)
示例11: mousePressEvent
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)
示例12: QTextInputDialog
class QTextInputDialog(QDialog):
def __init__(self, initial='', parent=None):
super().__init__(parent)
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.setMaximumSize(400, 230)
self.setMinimumSize(400, 230)
self.resize(400, 230)
self.scrollArea = QScrollArea(self)
self.scrollArea.setGeometry(QtCore.QRect(5, 5, 390, 190))
self.scrollArea.setWidgetResizable(True)
self.plainTextEdit = QPlainTextEdit()
self.plainTextEdit.setGeometry(QtCore.QRect(0, 0, 390, 190))
self.plainTextEdit.setPlainText(initial)
self.scrollArea.setWidget(self.plainTextEdit)
self.acceptButton = QPushButton(self)
self.acceptButton.setGeometry(QtCore.QRect(280, 200, 100, 25))
self.acceptButton.setText("Ok")
self.rejectButton = QPushButton(self)
self.rejectButton.setGeometry(QtCore.QRect(160, 200, 100, 25))
self.rejectButton.setText("Cancel")
self.rejectButton.clicked.connect(self.reject)
self.acceptButton.clicked.connect(self.accept)
示例13: previewWidget
def previewWidget(self):
t = QTabWidget()
t.setDocumentMode(True)
t.setStyleSheet("""
QTabBar::tab{
background-color: #BBB;
padding: 3px 25px;
border: none;
}
QTabBar::tab:selected, QTabBar::tab:hover{
background-color:skyblue;
}
""")
w0 = QPlainTextEdit()
w0.setFrameShape(QFrame.NoFrame)
w0.setReadOnly(True)
w1 = QPlainTextEdit()
w1.setFrameShape(QFrame.NoFrame)
w1.setReadOnly(True)
t.addTab(w0, qApp.translate("Export", "Markdown source"))
t.addTab(w1, qApp.translate("Export", "HTML Source"))
if webView:
w2 = webView()
t.addTab(w2, qApp.translate("Export", "HTML Output"))
t.setCurrentIndex(2)
return t
示例14: resizeEvent
def resizeEvent(self, e):
QPlainTextEdit.resizeEvent(self, e)
self.cr = self.contentsRect()
self.lineNumberArea.setGeometry(self.cr.left(),
self.cr.top(),
self.lineNumberAreaWidth(),
self.cr.height())
示例15: __init__
def __init__(self, parent=None, text=None, EditorHighlighterClass=PythonHighlighter, indenter=PythonCodeIndenter):
QPlainTextEdit.__init__(self, parent)
self.setFrameStyle(QFrame.NoFrame)
self.setTabStopWidth(4)
self.setLineWrapMode(QPlainTextEdit.NoWrap)
font = QFont()
font.setFamily("lucidasanstypewriter")
font.setFixedPitch(True)
font.setPointSize(10)
self.setFont(font)
self.highlighter = EditorHighlighterClass(self)
if text:
self.setPlainText(text)
self.frame_style = self.frameStyle()
self.draw_line = True
self.print_width = self.fontMetrics().width("x" * 78)
self.line_pen = QPen(QColor("lightgrey"))
self.last_row = self.last_col = -1
self.last_block = None
self.highlight_line = True
self.highlight_color = self.palette().highlight().color().light(175)
self.highlight_brush = QBrush(QColor(self.highlight_color))
self.cursorPositionChanged.connect(self.onCursorPositionChanged)
self.indenter = indenter(RopeEditorWrapper(self))
# True if you want to catch Emacs keys in actions
self.disable_shortcuts = False
self.prj = get_no_project()
self.prj.root = None
self.calltip = CallTip(self)
self.autocomplete = AutoComplete(self)