本文整理汇总了Python中PyQt5.Qt.QTextEdit.toPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.toPlainText方法的具体用法?Python QTextEdit.toPlainText怎么用?Python QTextEdit.toPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.toPlainText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ThemeCreateDialog
# 需要导入模块: from PyQt5.Qt import QTextEdit [as 别名]
# 或者: from PyQt5.Qt.QTextEdit import toPlainText [as 别名]
class ThemeCreateDialog(Dialog):
def __init__(self, parent, report):
self.report = report
Dialog.__init__(self, _('Create an icon theme'), 'create-icon-theme', parent)
def setup_ui(self):
self.splitter = QSplitter(self)
self.l = l = QVBoxLayout(self)
l.addWidget(self.splitter)
l.addWidget(self.bb)
self.w = w = QGroupBox(_('Theme Metadata'), self)
self.splitter.addWidget(w)
l = w.l = QFormLayout(w)
l.setFieldGrowthPolicy(l.ExpandingFieldsGrow)
self.missing_icons_group = mg = QGroupBox(self)
self.mising_icons = mi = QListWidget(mg)
mi.setSelectionMode(mi.NoSelection)
mg.l = QVBoxLayout(mg)
mg.l.addWidget(mi)
self.splitter.addWidget(mg)
self.title = QLineEdit(self)
l.addRow(_('&Title:'), self.title)
self.author = QLineEdit(self)
l.addRow(_('&Author:'), self.author)
self.version = v = QSpinBox(self)
v.setMinimum(1), v.setMaximum(1000000)
l.addRow(_('&Version:'), v)
self.license = lc = QLineEdit(self)
l.addRow(_('&License:'), lc)
self.url = QLineEdit(self)
l.addRow(_('&URL:'), self.url)
lc.setText(_(
'The license for the icons in this theme. Common choices are'
' Creative Commons or Public Domain.'))
self.description = QTextEdit(self)
l.addRow(self.description)
self.refresh_button = rb = self.bb.addButton(_('&Refresh'), self.bb.ActionRole)
rb.setIcon(QIcon(I('view-refresh.png')))
rb.clicked.connect(self.refresh)
self.apply_report()
def sizeHint(self):
return QSize(900, 670)
@property
def metadata(self):
self.report.theme.title = self.title.text().strip() # Needed for report.name to work
return {
'title': self.title.text().strip(),
'author': self.author.text().strip(),
'version': self.version.value(),
'description': self.description.toPlainText().strip(),
'number': len(self.report.name_map) - len(self.report.extra),
'date': utcnow().date().isoformat(),
'name': self.report.name,
'license': self.license.text().strip() or 'Unknown',
'url': self.url.text().strip() or None,
}
def save_metadata(self):
with open(os.path.join(self.report.path, THEME_METADATA), 'wb') as f:
json.dump(self.metadata, f, indent=2)
def refresh(self):
self.save_metadata()
self.report = read_theme_from_folder(self.report.path)
self.apply_report()
def apply_report(self):
theme = self.report.theme
self.title.setText((theme.title or '').strip())
self.author.setText((theme.author or '').strip())
self.version.setValue(theme.version or 1)
self.description.setText((theme.description or '').strip())
self.license.setText((theme.license or 'Unknown').strip())
self.url.setText((theme.url or '').strip())
if self.report.missing:
title = _('%d icons missing in this theme') % len(self.report.missing)
else:
title = _('No missing icons')
self.missing_icons_group.setTitle(title)
mi = self.mising_icons
mi.clear()
for name in sorted(self.report.missing):
QListWidgetItem(QIcon(I(name, allow_user_override=False)), name, mi)
def accept(self):
mi = self.metadata
if not mi.get('title'):
return error_dialog(self, _('No title specified'), _(
'You must specify a title for this icon theme'), show=True)
if not mi.get('author'):
return error_dialog(self, _('No author specified'), _(
'You must specify an author for this icon theme'), show=True)
return Dialog.accept(self)
示例2: PrefsViewerDialog
# 需要导入模块: from PyQt5.Qt import QTextEdit [as 别名]
# 或者: from PyQt5.Qt.QTextEdit import toPlainText [as 别名]
class PrefsViewerDialog(SizePersistedDialog):
def __init__(self, gui, namespace):
SizePersistedDialog.__init__(self, gui, _('Prefs Viewer dialog'))
self.setWindowTitle(_('Preferences for: ')+namespace)
self.gui = gui
self.db = gui.current_db
self.namespace = namespace
self._init_controls()
self.resize_dialog()
self._populate_settings()
if self.keys_list.count():
self.keys_list.setCurrentRow(0)
def _init_controls(self):
layout = QVBoxLayout(self)
self.setLayout(layout)
ml = QHBoxLayout()
layout.addLayout(ml, 1)
self.keys_list = QListWidget(self)
self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection)
self.keys_list.setFixedWidth(150)
self.keys_list.setAlternatingRowColors(True)
ml.addWidget(self.keys_list)
self.value_text = QTextEdit(self)
self.value_text.setTabStopWidth(24)
self.value_text.setReadOnly(True)
ml.addWidget(self.value_text, 1)
button_box = QDialogButtonBox(QDialogButtonBox.Ok)
button_box.accepted.connect(self.accept)
self.clear_button = button_box.addButton(_('Clear'), QDialogButtonBox.ResetRole)
self.clear_button.setIcon(get_icon('trash.png'))
self.clear_button.setToolTip(_('Clear all settings for this plugin'))
self.clear_button.clicked.connect(self._clear_settings)
if DEBUG:
self.edit_button = button_box.addButton(_('Edit'), QDialogButtonBox.ResetRole)
self.edit_button.setIcon(get_icon('edit_input.png'))
self.edit_button.setToolTip(_('Edit settings.'))
self.edit_button.clicked.connect(self._edit_settings)
self.save_button = button_box.addButton(_('Save'), QDialogButtonBox.ResetRole)
self.save_button.setIcon(get_icon('save.png'))
self.save_button.setToolTip(_('Save setting for this plugin'))
self.save_button.clicked.connect(self._save_settings)
self.save_button.setEnabled(False)
layout.addWidget(button_box)
def _populate_settings(self):
self.keys_list.clear()
ns_prefix = self._get_ns_prefix()
keys = sorted([k[len(ns_prefix):] for k in self.db.prefs.iterkeys()
if k.startswith(ns_prefix)])
for key in keys:
self.keys_list.addItem(key)
self.keys_list.setMinimumWidth(self.keys_list.sizeHintForColumn(0))
self.keys_list.currentRowChanged[int].connect(self._current_row_changed)
def _current_row_changed(self, new_row):
if new_row < 0:
self.value_text.clear()
return
key = unicode(self.keys_list.currentItem().text())
val = self.db.prefs.get_namespaced(self.namespace, key, '')
self.value_text.setPlainText(self.db.prefs.to_raw(val))
def _get_ns_prefix(self):
return 'namespaced:%s:'% self.namespace
def _edit_settings(self):
from calibre.gui2.dialogs.confirm_delete import confirm
message = '<p>' + _('Are you sure you want to edit settings in this library for this plugin?') + '</p>' \
+ '<p>' + _('The FanFicFare team does not support hand edited configurations.') + '</p>'
if confirm(message, self.namespace+'_edit_settings', self):
self.save_button.setEnabled(True)
self.edit_button.setEnabled(False)
self.value_text.setReadOnly(False)
def _save_settings(self):
from calibre.gui2.dialogs.confirm_delete import confirm
message = '<p>' + _('Are you sure you want to save this setting in this library for this plugin?') + '</p>' \
+ '<p>' + _('Any settings in other libraries or stored in a JSON file in your calibre plugins folder will not be touched.') + '</p>' \
+ '<p>' + _('You must restart calibre afterwards.') + '</p>'
if not confirm(message, self.namespace+'_save_settings', self):
return
ns_prefix = self._get_ns_prefix()
key = unicode(self.keys_list.currentItem().text())
self.db.prefs.set_namespaced(self.namespace, key,
self.db.prefs.raw_to_object(self.value_text.toPlainText()))
d = info_dialog(self, 'Settings saved',
'<p>' + _('All settings for this plugin in this library have been saved.') + '</p>' \
+ '<p>' + _('Please restart calibre now.') + '</p>',
show_copy_button=False)
b = d.bb.addButton(_('Restart calibre now'), d.bb.AcceptRole)
#.........这里部分代码省略.........
示例3: ConfigWidget
# 需要导入模块: from PyQt5.Qt import QTextEdit [as 别名]
# 或者: from PyQt5.Qt.QTextEdit import toPlainText [as 别名]
#.........这里部分代码省略.........
self.l.addWidget(self.checkbox_include_guide_text, row, 0)
self.l.addWidget(self.label_include_guide_text, row, 1)
row += 1
self.l.addWidget(self.include_guide_text, row, 1)
row += 1
self.l.addWidget(QLabel(''), row, 1)
row += 1
self.label_include_toc_text = QLabel('Include in TOC with string:')
self.checkbox_include_toc_text = QCheckBox('', self)
self.checkbox_include_toc_text.setChecked(prefs['checkbox_include_toc_text'] == 'True')
self.include_toc_text = QLineEdit(self)
self.include_toc_text.setText(prefs['include_toc_text'])
self.l.addWidget(self.checkbox_include_toc_text, row, 0)
self.l.addWidget(self.label_include_toc_text, row, 1)
row += 1
self.l.addWidget(self.include_toc_text, row, 1)
row += 1
self.l.addWidget(QLabel(''), row, 1)
row += 1
self.label_ask_replace = QLabel('Ask before replacing book in library')
self.checkbox_ask_replace = QCheckBox('', self)
self.checkbox_ask_replace.setChecked(prefs['checkbox_ask_replace'] == 'True')
self.l.addWidget(self.checkbox_ask_replace, row, 0)
self.l.addWidget(self.label_ask_replace, row, 1)
row += 1
self.label_disable_first_last_only = QLabel('When multiple EPUB files are selected, allow insertion points other than "1", "first", and "last"')
self.checkbox_disable_first_last_only = QCheckBox('', self)
self.checkbox_disable_first_last_only.setChecked(prefs['checkbox_disable_first_last_only'] == 'True')
self.l.addWidget(self.checkbox_disable_first_last_only, row, 0)
self.l.addWidget(self.label_disable_first_last_only, row, 1)
row += 1
self.l.addWidget(QLabel(''), row, 1)
row += 1
self.label_replace_strings = QLabel('Replace strings:')
self.replace_strings = QTextEdit(self)
self.replace_strings.setText(prefs['replace_strings'])
self.label_supportedMetadata = QLabel('Supported metadata:')
self.supportedMetadata = QListWidget(self)
#QtCore.QObject.connect(self.supportedMetadata, QtCore.SIGNAL("doubleClicked()"), self.add_replace_string)
self.supportedMetadata.doubleClicked.connect(self.add_replace_string)
producer = exlibris()
tags = producer.getSupportedMetadataList()
for tag in tags:
self.supportedMetadata.addItem(tag.decode('utf-8'))
self.l.addWidget(self.label_replace_strings, row, 1)
self.l.addWidget(self.label_supportedMetadata, row, 2)
row += 1
self.l.addWidget(self.replace_strings, row, 1)
self.l.addWidget(self.supportedMetadata, row, 2)
row += 1
self.resize(self.sizeHint())
def add_replace_string(self):
currentText = str(self.replace_strings.toPlainText()).strip()
currentItem = self.supportedMetadata.currentItem().text()
self.replace_strings.setText("%s\n%s=your_value_goes_here;" % (currentText, currentItem))
def button_xhtml_filename_handler(self):
initial_dir = os.path.dirname(str(self.xhtml_filename.text()))
new_file = QFileDialog.getOpenFileName(self, "Select ex libris XHTML file", initial_dir, "XHTML Files (*.xhtml)")
if new_file:
new_file = new_file[0] if isinstance(new_file, tuple) else new_file
if new_file and os.path.exists(new_file):
self.xhtml_filename.setText(new_file)
def button_include_dir_handler(self):
initial_dir = os.path.dirname(str(self.include_dir.text()))
dirDialog = QFileDialog()
dirDialog.setFileMode(QFileDialog.Directory)
new_dir = dirDialog.getExistingDirectory(self, "Select directory", initial_dir)
if (len(new_dir) > 0):
self.include_dir.setText(new_dir)
def save_settings(self):
prefs['xhtml_filename'] = unicode(self.xhtml_filename.text())
prefs['include_dir'] = unicode(self.include_dir.text())
prefs['include_guide_text'] = unicode(self.include_guide_text.text())
prefs['include_toc_text'] = unicode(self.include_toc_text.text())
prefs['replace_strings'] = unicode(self.replace_strings.toPlainText())
prefs['checkbox_include_dir'] = unicode(self.checkbox_include_dir.isChecked())
prefs['checkbox_include_guide_text'] = unicode(self.checkbox_include_guide_text.isChecked())
prefs['checkbox_include_toc_text'] = unicode(self.checkbox_include_toc_text.isChecked())
prefs['checkbox_ask_replace'] = unicode(self.checkbox_ask_replace.isChecked())
prefs['checkbox_disable_first_last_only'] = unicode(self.checkbox_disable_first_last_only.isChecked())
# TODO: save value from main.py (?)
prefs['include_spine'] = u'1'
prefs['include_toc'] = u'1'
示例4: EditQDialog
# 需要导入模块: from PyQt5.Qt import QTextEdit [as 别名]
# 或者: from PyQt5.Qt.QTextEdit import toPlainText [as 别名]
class EditQDialog(QDialog):
"""
Class who create Edit QDialog to edit text in Alignak-app
"""
def __init__(self, parent=None):
super(EditQDialog, self).__init__(parent)
self.setWindowTitle('Edit Dialog')
self.setWindowFlags(Qt.FramelessWindowHint)
self.setStyleSheet(settings.css_style)
self.setWindowIcon(QIcon(settings.get_image('icon')))
self.setObjectName('dialog')
self.setFixedSize(300, 300)
# Fields
self.text_edit = QTextEdit()
self.old_text = ''
def initialize(self, title, text):
"""
Initialize QDialog for UserNotesQDialog
:param title: title of the QDialog
:type title: str
:param text: text to edit
:type text: str
"""
self.old_text = text
center_widget(self)
# Main status_layout
main_layout = QVBoxLayout(self)
main_layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(main_layout)
main_layout.addWidget(get_logo_widget(self, title))
text_title = QLabel(_("Edit your text:"))
text_title.setObjectName('subtitle')
main_layout.addWidget(text_title)
main_layout.setAlignment(text_title, Qt.AlignCenter)
main_layout.addWidget(self.get_text_widget())
def get_text_widget(self):
"""
Return text QWidget with QTextEdit
:return: text QWidget
:rtype: QWidget
"""
text_widget = QWidget()
text_widget.setObjectName('dialog')
text_layout = QVBoxLayout()
text_widget.setLayout(text_layout)
self.text_edit.setPlaceholderText(_('type your text...'))
self.text_edit.setText(self.old_text)
text_layout.addWidget(self.text_edit)
# Accept button
accept_btn = QPushButton(_('Confirm'), self)
accept_btn.clicked.connect(self.accept_text)
accept_btn.setObjectName('valid')
accept_btn.setMinimumHeight(30)
text_layout.addWidget(accept_btn)
return text_widget
def accept_text(self):
"""
Set Edit QDialog to Rejected or Accepted (prevent to patch for nothing)
"""
if self.old_text == self.text_edit.toPlainText():
self.reject()
elif not self.old_text or self.old_text.isspace():
if not self.text_edit.toPlainText() or self.text_edit.toPlainText().isspace():
self.reject()
else:
self.accept()
else:
self.accept()
示例5: PrefsViewerDialog
# 需要导入模块: from PyQt5.Qt import QTextEdit [as 别名]
# 或者: from PyQt5.Qt.QTextEdit import toPlainText [as 别名]
class PrefsViewerDialog(SizePersistedDialog):
def __init__(self, gui, namespace):
SizePersistedDialog.__init__(self, gui, 'Prefs Viewer dialog')
self.setWindowTitle('Preferences for: '+namespace)
self.gui = gui
self.db = gui.current_db
self.namespace = namespace
self._init_controls()
self.resize_dialog()
self._populate_settings()
if self.keys_list.count():
self.keys_list.setCurrentRow(0)
def _init_controls(self):
layout = QVBoxLayout(self)
self.setLayout(layout)
ml = QHBoxLayout()
layout.addLayout(ml, 1)
self.keys_list = QListWidget(self)
self.keys_list.setSelectionMode(QAbstractItemView.SingleSelection)
self.keys_list.setFixedWidth(150)
self.keys_list.setAlternatingRowColors(True)
ml.addWidget(self.keys_list)
self.value_text = QTextEdit(self)
self.value_text.setTabStopWidth(24)
self.value_text.setReadOnly(False)
ml.addWidget(self.value_text, 1)
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self._apply_changes)
button_box.rejected.connect(self.reject)
self.clear_button = button_box.addButton('Clear', QDialogButtonBox.ResetRole)
self.clear_button.setIcon(get_icon('trash.png'))
self.clear_button.setToolTip('Clear all settings for this plugin')
self.clear_button.clicked.connect(self._clear_settings)
layout.addWidget(button_box)
def _populate_settings(self):
self.keys_list.clear()
ns_prefix = self._get_ns_prefix()
keys = sorted([k[len(ns_prefix):] for k in self.db.prefs.iterkeys()
if k.startswith(ns_prefix)])
for key in keys:
self.keys_list.addItem(key)
self.keys_list.setMinimumWidth(self.keys_list.sizeHintForColumn(0))
self.keys_list.currentRowChanged[int].connect(self._current_row_changed)
def _current_row_changed(self, new_row):
if new_row < 0:
self.value_text.clear()
return
key = unicode(self.keys_list.currentItem().text())
val = self.db.prefs.get_namespaced(self.namespace, key, '')
self.value_text.setPlainText(self.db.prefs.to_raw(val))
def _get_ns_prefix(self):
return 'namespaced:%s:'% self.namespace
def _apply_changes(self):
from calibre.gui2.dialogs.confirm_delete import confirm
message = '<p>Are you sure you want to change your settings in this library for this plugin?</p>' \
'<p>Any settings in other libraries or stored in a JSON file in your calibre plugins ' \
'folder will not be touched.</p>' \
'<p>You must restart calibre afterwards.</p>'
if not confirm(message, self.namespace+'_clear_settings', self):
return
val = self.db.prefs.raw_to_object(unicode(self.value_text.toPlainText()))
key = unicode(self.keys_list.currentItem().text())
self.db.prefs.set_namespaced(self.namespace, key, val)
restart = prompt_for_restart(self, 'Settings changed',
'<p>Settings for this plugin in this library have been changed.</p>'
'<p>Please restart calibre now.</p>')
self.close()
if restart:
self.gui.quit(restart=True)
def _clear_settings(self):
from calibre.gui2.dialogs.confirm_delete import confirm
message = '<p>Are you sure you want to clear your settings in this library for this plugin?</p>' \
'<p>Any settings in other libraries or stored in a JSON file in your calibre plugins ' \
'folder will not be touched.</p>' \
'<p>You must restart calibre afterwards.</p>'
if not confirm(message, self.namespace+'_clear_settings', self):
return
ns_prefix = self._get_ns_prefix()
keys = [k for k in self.db.prefs.iterkeys() if k.startswith(ns_prefix)]
for k in keys:
del self.db.prefs[k]
self._populate_settings()
restart = prompt_for_restart(self, 'Settings deleted',
'<p>All settings for this plugin in this library have been cleared.</p>'
#.........这里部分代码省略.........