本文整理汇总了Python中PyQt5.QtWidgets.QTextBrowser.setPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser.setPlainText方法的具体用法?Python QTextBrowser.setPlainText怎么用?Python QTextBrowser.setPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTextBrowser
的用法示例。
在下文中一共展示了QTextBrowser.setPlainText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setPlainText [as 别名]
def __init__(self):
super(Window, self).__init__()
centralWidget = QTextBrowser()
centralWidget.setPlainText("Central widget")
layout = BorderLayout()
layout.addWidget(centralWidget, BorderLayout.Center)
# Because BorderLayout doesn't call its super-class addWidget() it
# doesn't take ownership of the widgets until setLayout() is called.
# Therefore we keep a local reference to each label to prevent it being
# garbage collected too soon.
label_n = self.createLabel("North")
layout.addWidget(label_n, BorderLayout.North)
label_w = self.createLabel("West")
layout.addWidget(label_w, BorderLayout.West)
label_e1 = self.createLabel("East 1")
layout.addWidget(label_e1, BorderLayout.East)
label_e2 = self.createLabel("East 2")
layout.addWidget(label_e2, BorderLayout.East)
label_s = self.createLabel("South")
layout.addWidget(label_s, BorderLayout.South)
self.setLayout(layout)
self.setWindowTitle("Border Layout")
示例2: Article
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setPlainText [as 别名]
class Article(QDialog):
def __init__(self, listIndexArticle, articleList, parentW=None, shuffle_=False):
super(Article, self).__init__()
self.parentW = parentW
self.articleList = articleList
if shuffle_ == True:
shuffle(self.articleList)
self.articleId = self.articleList[listIndexArticle]
self.listIndexArticle = listIndexArticle
self.selectArticle(self.articleId)
self.setWindowTitle("Article id: " + str(self.articleId))
self.initUI()
def initUI(self):
self.setGeometry(1030, 220, 400, 700)
mainLayout = QVBoxLayout()
self.createNavigationWidget()
self.createTitleBox()
self.createAuthorBox()
self.createDateBox()
self.createContentBrowser()
self.createEntitiesBox()
mainLayout.addWidget(self.titleBox)
mainLayout.addWidget(self.authorBox)
mainLayout.addWidget(self.dateBox)
mainLayout.addWidget(self.contentBrowser)
mainLayout.addWidget(self.entityBox)
mainLayout.addWidget(self.navigationWidget)
self.setLayout(mainLayout)
self.show()
def createNavigationWidget(self):
previousButton = QPushButton("<")
previousButton.setFocusPolicy(Qt.NoFocus)
previousButton.clicked.connect(self.previousArticle)
nextButton = QPushButton(">")
nextButton.setFocusPolicy(Qt.NoFocus)
nextButton.clicked.connect(self.nextArticle)
layout = QHBoxLayout()
layout.addWidget(previousButton)
layout.addWidget(nextButton)
self.navigationWidget = QWidget()
self.navigationWidget.setLayout(layout)
def createTitleBox(self):
self.titleLabel = QLabel(self.articleTitle)
self.titleLabel.setWordWrap(True)
layout = QHBoxLayout()
layout.addWidget(self.titleLabel)
self.titleBox = QGroupBox("Title")
self.titleBox.setLayout(layout)
def createAuthorBox(self):
self.authorLabel = QLabel(self.articleAuthor)
layout = QHBoxLayout()
layout.addWidget(self.authorLabel)
self.authorBox = QGroupBox("Author")
self.authorBox.setLayout(layout)
def createDateBox(self):
self.dateLabel = QLabel(str(self.articleDate))
layout = QHBoxLayout()
layout.addWidget(self.dateLabel)
self.dateBox = QGroupBox("Date")
self.dateBox.setLayout(layout)
def createContentBrowser(self):
self.contentBrowser = QTextBrowser(self)
self.contentBrowser.setPlainText(self.articleContent)
self.contentBrowser.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
def createEntitiesBox(self):
layout = self.createEntityGridLayout()
self.entityBox = QGroupBox("Entities - Opinions")
self.entityBox.setLayout(layout)
if len(self.entities) == 0:
self.entityBox.setVisible(False)
else:
self.entityBox.setVisible(True)
#.........这里部分代码省略.........
示例3: Dialog
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setPlainText [as 别名]
#.........这里部分代码省略.........
def setDiffText(self, text=''):
if text:
from_filename = "current" # TODO: maybe use real filename here
to_filename = "converted" # but difflib can choke on non-ascii characters,
# see https://github.com/wbsoft/frescobaldi/issues/674
difflist = list(difflib.unified_diff(
self._text.split('\n'), text.split('\n'),
from_filename, to_filename))
diffHLstr = self.diffHighl(difflist)
self.uni_diff.setHtml(diffHLstr)
else:
self.uni_diff.clear()
def convertedText(self):
return self._convertedtext or ''
def setDocument(self, doc):
v = documentinfo.docinfo(doc).version_string()
if v:
self.fromVersion.setText(v)
self.reason.setText(_("(set in document)"))
else:
self.reason.clear()
self._text = doc.toPlainText()
self._encoding = doc.encoding() or 'UTF-8'
self.setConvertedText()
self.setDiffText()
def run(self):
"""Runs convert-ly (again)."""
fromVersion = self.fromVersion.text()
toVersion = self.toVersion.text()
if not fromVersion or not toVersion:
self.messages.setPlainText(_(
"Both 'from' and 'to' versions need to be set."))
return
info = self._info
command = info.toolcommand(info.ly_tool('convert-ly'))
command += ['-f', fromVersion, '-t', toVersion, '-']
# if the user wants english messages, do it also here: LANGUAGE=C
env = None
if os.name == "nt":
# Python 2.7 subprocess on Windows chokes on unicode in env
env = util.bytes_environ()
else:
env = dict(os.environ)
if sys.platform.startswith('darwin'):
try:
del env['PYTHONHOME']
except KeyError:
pass
try:
del env['PYTHONPATH']
except KeyError:
pass
if QSettings().value("lilypond_settings/no_translation", False, bool):
if os.name == "nt":
# Python 2.7 subprocess on Windows chokes on unicode in env
env[b'LANGUAGE'] = b'C'
else:
env['LANGUAGE'] = 'C'
with qutil.busyCursor():
try:
proc = subprocess.Popen(command,
示例4: Widget
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setPlainText [as 别名]
#.........这里部分代码省略.........
"""Called when the user clicks the apply button. Applies current snippet."""
name = self.currentSnippet()
if name:
view = self.parent().mainwindow().currentView()
insert.insert(name, view)
def slotImport(self):
"""Called when the user activates the import action."""
filetypes = "{0} (*.xml);;{1} (*)".format(_("XML Files"), _("All Files"))
caption = app.caption(_("dialog title", "Import Snippets"))
filename = None
filename = QFileDialog.getOpenFileName(self, caption, filename, filetypes)[0]
if filename:
from . import import_export
import_export.load(filename, self)
def slotExport(self):
"""Called when the user activates the export action."""
allrows = [row for row in range(model.model().rowCount())
if not self.treeView.isRowHidden(row, QModelIndex())]
selectedrows = [i.row() for i in self.treeView.selectedIndexes()
if i.column() == 0 and i.row() in allrows]
names = self.treeView.model().names()
names = [names[row] for row in selectedrows or allrows]
filetypes = "{0} (*.xml);;{1} (*)".format(_("XML Files"), _("All Files"))
n = len(names)
caption = app.caption(_("dialog title",
"Export {num} Snippet", "Export {num} Snippets", n).format(num=n))
filename = QFileDialog.getSaveFileName(self, caption, None, filetypes)[0]
if filename:
from . import import_export
try:
import_export.save(names, filename)
except (IOError, OSError) as e:
QMessageBox.critical(self, _("Error"), _(
"Can't write to destination:\n\n{url}\n\n{error}").format(
url=filename, error=e.strerror))
def slotRestore(self):
"""Called when the user activates the Restore action."""
from . import restore
dlg = restore.RestoreDialog(self)
dlg.setWindowModality(Qt.WindowModal)
dlg.populate()
dlg.show()
dlg.finished.connect(dlg.deleteLater)
def slotHelp(self):
"""Called when the user clicks the small help button."""
userguide.show("snippets")
def currentSnippet(self):
"""Returns the name of the current snippet if it is visible."""
row = self.treeView.currentIndex().row()
if row != -1 and not self.treeView.isRowHidden(row, QModelIndex()):
return self.treeView.model().names()[row]
def updateFilter(self):
"""Called when the text in the entry changes, updates search results."""
text = self.searchEntry.text()
ltext = text.lower()
filterVars = text.startswith(':')
if filterVars:
try:
fvar, fval = text[1:].split(None, 1)
fhide = lambda v: v.get(fvar) in (True, None) or fval not in v.get(fvar)
except ValueError:
fvar = text[1:].strip()
fhide = lambda v: not v.get(fvar)
for row in range(self.treeView.model().rowCount()):
name = self.treeView.model().names()[row]
nameid = snippets.get(name).variables.get('name', '')
if filterVars:
hide = fhide(snippets.get(name).variables)
elif nameid == text:
i = self.treeView.model().createIndex(row, 0)
self.treeView.selectionModel().setCurrentIndex(i, QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows)
hide = False
elif nameid.lower().startswith(ltext):
hide = False
elif ltext in snippets.title(name).lower():
hide = False
else:
hide = True
self.treeView.setRowHidden(row, QModelIndex(), hide)
self.updateText()
def updateText(self):
"""Called when the current snippet changes."""
name = self.currentSnippet()
self.textView.clear()
if name:
s = snippets.get(name)
self.highlighter.setPython('python' in s.variables)
self.textView.setPlainText(s.text)
def updateColumnSizes(self):
self.treeView.resizeColumnToContents(0)
self.treeView.resizeColumnToContents(1)