本文整理汇总了Python中PyQt4.Qt.QTextEdit.setPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.setPlainText方法的具体用法?Python QTextEdit.setPlainText怎么用?Python QTextEdit.setPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.setPlainText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PrefsViewerDialog
# 需要导入模块: from PyQt4.Qt import QTextEdit [as 别名]
# 或者: from PyQt4.Qt.QTextEdit import setPlainText [as 别名]
class PrefsViewerDialog(SizePersistedDialog):
def __init__(self, gui, namespace):
SizePersistedDialog.__init__(self, gui, 'Prefs Viewer dialog')
self.setWindowTitle('Preferences for: '+namespace)
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)
button_box.setCenterButtons(True)
layout.addWidget(button_box)
def _populate_settings(self):
self.keys_list.clear()
ns_prefix = 'namespaced:%s:'% self.namespace
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))
示例2: TextMessageBox
# 需要导入模块: from PyQt4.Qt import QTextEdit [as 别名]
# 或者: from PyQt4.Qt.QTextEdit import setPlainText [as 别名]
class TextMessageBox(QDialog):
"""
The TextMessageBox class provides a modal dialog with a textedit widget
and a close button. It is used as an option to QMessageBox when displaying
a large amount of text. It also has the benefit of allowing the user to copy and
paste the text from the textedit widget.
Call the setText() method to insert text into the textedit widget.
"""
def __init__(self, parent = None, name = None, modal = 1, fl = 0):
#QDialog.__init__(self,parent,name,modal,fl)
QDialog.__init__(self,parent)
self.setModal(modal)
qt4todo("handle flags in TextMessageBox.__init__")
if name is None: name = "TextMessageBox"
self.setObjectName(name)
self.setWindowTitle(name)
TextMessageLayout = QVBoxLayout(self)
TextMessageLayout.setMargin(5)
TextMessageLayout.setSpacing(1)
self.text_edit = QTextEdit(self)
TextMessageLayout.addWidget(self.text_edit)
self.close_button = QPushButton(self)
self.close_button.setText("Close")
TextMessageLayout.addWidget(self.close_button)
self.resize(QSize(350, 300).expandedTo(self.minimumSizeHint()))
# Width changed from 300 to 350. Now hscrollbar doesn't appear in
# Help > Graphics Info textbox. mark 060322
qt4todo('self.clearWState(Qt.WState_Polished)') # what is this?
self.connect(self.close_button, SIGNAL("clicked()"),self.close)
def setText(self, txt):
"""
Sets the textedit's text to txt
"""
self.text_edit.setPlainText(txt)
pass
示例3: PrefsViewerDialog
# 需要导入模块: from PyQt4.Qt import QTextEdit [as 别名]
# 或者: from PyQt4.Qt.QTextEdit import setPlainText [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)
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 _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()
d = info_dialog(self, 'Settings deleted',
'<p>All settings for this plugin in this library have been cleared.</p>'
'<p>Please restart calibre now.</p>',
show_copy_button=False)
b = d.bb.addButton(_('Restart calibre now'), d.bb.AcceptRole)
b.setIcon(QIcon(I('lt.png')))
d.do_restart = False
def rf():
d.do_restart = True
b.clicked.connect(rf)
d.set_details('')
d.exec_()
b.clicked.disconnect()
self.close()
if d.do_restart:
self.gui.quit(restart=True)
示例4: TwitterGui
# 需要导入模块: from PyQt4.Qt import QTextEdit [as 别名]
# 或者: from PyQt4.Qt.QTextEdit import setPlainText [as 别名]
class TwitterGui(QWidget):
URL_REGEX = re.compile(r'''((?:mailto:|ftp://|http://|https://)[^ <>'"{}|\\^`[\]]*)''')
def __init__(self, parent, logger, db_conn, update_func, safe_conn):
super(TwitterGui, self).__init__(parent)
self._db_conn = db_conn
self.logger = logger
self._reply_to_id = 0
self._update_func = update_func
self._list = None
if get_settings().get_proxy():
u = urlparse.urlsplit(get_settings().get_proxy())
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName(u.hostname);
proxy.setPort(u.port)
QNetworkProxy.setApplicationProxy(proxy);
self.msgview = QWebView(self)
self.msgview.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.msgview.linkClicked.connect(self.link_clicked)
self.userCombo = QComboBox(self)
self.userCombo.setEditable(True)
self.userCombo.activated.connect(self.toggle_user_in_list)
self.showButton = QPushButton(chr(94), self)
self.showButton.setMaximumHeight(13)
self.showButton.clicked.connect(self.show_hide_animation)
self.post_field = QTextEdit(self)
self.post_field.setMaximumHeight(50)
self.post_field.textChanged.connect(self.text_changed)
self.send_button = QPushButton("Post", self)
self.send_button.clicked.connect(self.post_status_clicked)
self.refresh_button = QPushButton("Refresh", self)
self.refresh_button.clicked.connect(self._update_func)
self.attach_button = QPushButton("Attach", self)
self.attach_button.clicked.connect(lambda _ : self.set_status("Attach something"))
self.lists_box = QComboBox(self)
self.lists_box.currentIndexChanged.connect(self.list_changed)
self.lists_box.setEditable(False)
self.lists_box.addItems([u"Home"] + self._db_conn.get_lists())
self.statusLabel = QLabel("Status", self)
self.charCounter = QLabel("0", self)
self.gridw = QWidget(self)
self.gridw.setContentsMargins(0, 0, 0, 0)
gridlay = QGridLayout(self.gridw)
gridlay.setContentsMargins(0, 0, 0, 0)
gridlay.addWidget(self.post_field, 0, 0, 2, 1)
gridlay.addWidget(self.attach_button, 0, 1, 1, 1)
gridlay.addWidget(self.send_button, 1, 1, 1, 1)
gridlay.addWidget(self.lists_box, 0, 2, 1, 1)
gridlay.addWidget(self.refresh_button, 1, 2, 1, 1)
gridlay.addWidget(self.statusLabel, 2, 0, 1, 1)
gridlay.addWidget(self.charCounter, 2, 1, 1, 2)
hlay = QVBoxLayout(self)
hlay.addWidget(self.msgview)
hlay.addWidget(self.userCombo)
hlay.addWidget(self.showButton)
hlay.addWidget(self.gridw)
safe_conn.connect_home_timeline_updated(self.update_view)
safe_conn.connect_twitter_loop_started(self.start_refresh_animation)
safe_conn.connect_twitter_loop_stopped(self.stop_refresh_animation)
safe_conn.connect_update_posted(self.enable_posting)
safe_conn.connect_range_limit_exceeded(lambda _ : self.set_status("Range limit exceeded"))
safe_conn.connect_not_authenticated(lambda _ : self.set_status("Authentication failed"))
self.gridw.hide()
self.update_view()
self.set_status("Twitter plugin initialized")
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())
#.........这里部分代码省略.........