本文整理汇总了Python中PyQt4.Qt.QTextEdit.toPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.toPlainText方法的具体用法?Python QTextEdit.toPlainText怎么用?Python QTextEdit.toPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.toPlainText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PrefsViewerDialog
# 需要导入模块: from PyQt4.Qt import QTextEdit [as 别名]
# 或者: from PyQt4.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>'
#.........这里部分代码省略.........
示例2: TwitterGui
# 需要导入模块: from PyQt4.Qt import QTextEdit [as 别名]
# 或者: from PyQt4.Qt.QTextEdit import toPlainText [as 别名]
#.........这里部分代码省略.........
def enable_posting(self, q_id, m_id):
if m_id>1:
self.post_field.setText("")
self.set_status("Tweet posted")
else:
self.set_status("Failed to post tweet, Error: " + str(abs(m_id)))
self.post_field.setEnabled(True)
def link_clicked(self, url):
if not url.host():
if url.hasQueryItem("reply-to") and url.hasQueryItem("screen-name"):
self._reply_to_id = long(convert_string(url.queryItemValue("reply-to")))
self.post_field.setPlainText("@"+convert_string(url.queryItemValue("screen-name"))+" ")
self.set_status("Reply to @"+convert_string(url.queryItemValue("screen-name")))
else:
self.logger.error("Unknown command from link: "+str(url.toString()))
else:
webbrowser.open(str(url.toString()))
def list_changed(self, list_idx):
if list_idx:
self._list = convert_string(self.lists_box.currentText())
self.userCombo.clear()
self.userCombo.addItems(self._db_conn.get_known_users())
self.userCombo.completer().setCompletionMode(QCompleter.PopupCompletion)
self.userCombo.show()
self.set_status(self._list)
else:
self.userCombo.hide()
self._list = None
self.update_view()
def post_status_clicked(self):
msg = unicode(self.post_field.toPlainText().toUtf8(), encoding="UTF-8")
if msg:
self._db_conn.insert_post_queue(msg, self._reply_to_id)
self._reply_to_id = 0
self._update_func()
self.post_field.setDisabled(True)
def start_refresh_animation(self):
self.refresh_button.setDisabled(True)
def stop_refresh_animation(self):
self.refresh_button.setEnabled(True)
def show_hide_animation(self):
if self.gridw.isHidden():
self.gridw.show()
self.showButton.setText("v")
else:
self.gridw.hide()
self.showButton.setText(chr(94))
def text_changed(self):
count = len(self.post_field.toPlainText())
if count==0:
self._reply_to_id = 0
if self._reply_to_id:
self.charCounter.setText(str(count) + " - reply to ")
else:
self.charCounter.setText(str(count))
def toggle_user_in_list(self, _):
user = convert_string(self.userCombo.currentText())
if user in self._db_conn.get_users_from_list(self._list):