本文整理汇总了Python中PyQt5.QtWidgets.QTextBrowser类的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser类的具体用法?Python QTextBrowser怎么用?Python QTextBrowser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextBrowser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: slotButtonShowDiff
def slotButtonShowDiff(self):
"""Called when the user clicks Show Difference."""
docs = self.selectedDocuments() or self.allDocuments()
if not docs:
return
d = docs[0]
if documentwatcher.DocumentWatcher.instance(d).isdeleted():
return
filename = d.url().toLocalFile()
try:
with open(filename, 'rb') as f:
disktext = util.decode(f.read())
except (IOError, OSError):
return
currenttext = d.toPlainText()
html = htmldiff.htmldiff(
currenttext, disktext,
_("Current Document"), _("Document on Disk"), numlines=5)
dlg = widgets.dialog.Dialog(self, buttons=('close',))
view = QTextBrowser(lineWrapMode=QTextBrowser.NoWrap)
view.setHtml(html)
dlg.setMainWidget(view)
dlg.setWindowTitle(app.caption("Differences"))
dlg.setMessage(_(
"Document: {url}\n"
"Difference between the current document and the file on disk:").format(
url=filename))
dlg.setWindowModality(Qt.NonModal)
dlg.setAttribute(Qt.WA_QuitOnClose, False)
dlg.setAttribute(Qt.WA_DeleteOnClose)
qutil.saveDialogSize(dlg, "externalchanges/diff/dialog/size", QSize(600, 300))
dlg.show()
示例2: createPreviewBox
def createPreviewBox(self):
if globalSettings.useWebKit:
return self.createWebView()
browser = QTextBrowser()
# TODO: honor globalSettings.handleWebLinks?
browser.setOpenExternalLinks(True)
return browser
示例3: __init__
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")
示例4: HelpDialog
class HelpDialog(QDialog):
def __init__(self, parent, help_file):
super(HelpDialog, self).__init__(parent)
#QDialog.__init__(self, parent)
self.setWindowTitle(_translate("Packaga Manager","Package Manager Help"))
self.resize(700,500)
self.setModal(True)
self.layout = QGridLayout(self)
self.htmlPart = QTextBrowser(self)
self.layout.addWidget(self.htmlPart, 1, 1)
locale = setSystemLocale(justGet = True)
if locale in ["tr", "es", "en", "fr", "nl", "de", "sv"]:
self.htmlPart.setSource(
QUrl("/usr/share/package-manager/help/%s/%s" %
(locale, help_files[help_file])))
else:
self.htmlPart.setSource(
QUrl("/usr/share/package-manager/help/en/%s" %
help_files[help_file]))
self.show()
示例5: HelpForm
class HelpForm(QDialog):
def __init__(self, page, parent=None):
super(HelpForm, self).__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setWindowModality(Qt.WindowModal)
# actions
backAction = QAction(QIcon(":/back.png"), "&Back", self)
backAction.setShortcut(QKeySequence.Back)
homeAction = QAction(QIcon(":/home.png"), "&Home", self)
homeAction.setShortcut("Home")
self.pageLabel = QLabel()
#toolbar
toolBar = QToolBar()
toolBar.addAction(backAction)
toolBar.addAction(homeAction)
toolBar.addWidget(self.pageLabel)
self.textBrowser = QTextBrowser()
# layout
layout = QVBoxLayout()
layout.addWidget(toolBar)
layout.addWidget(self.textBrowser, 1)
self.setLayout(layout)
# signals and slots
backAction.triggered.connect(self.textBrowser.backward)
homeAction.triggered.connect(self.textBrowser.home)
self.textBrowser.sourceChanged.connect(self.updatePageTitle)
self.textBrowser.setSearchPaths([":/help"])
self.textBrowser.setSource(QUrl(page))
self.resize(400, 600)
self.setWindowTitle("{0} Help".format(
QApplication.applicationName()))
def updatePageTitle(self):
self.pageLabel.setText(self.textBrowser.documentTitle())
开发者ID:imagingearth,项目名称:Rapid-GUI-Programming-with-Python-and-Qt---PyQt5-codes,代码行数:33,代码来源:helpform.py
示例6: __init__
def __init__(self):
super().__init__()
self.worker = None
self.statusBar().showMessage('ready')
self.resize(250, 150)
self.move(300, 300)
self.setWindowTitle('刷起来')
self.setWindowIcon(QIcon('icon.ico'))
self.imagesPath = "./images/tp14/"
self.toolBar = self.addToolBar('')
GameStatus().window = self
yaoguaifaxian_action = QAction(QIcon('./images/ui/yaoguaifaxian.jpg'), '妖怪发现', self)
yaoguaifaxian_action.triggered.connect(self.yaoguaifaxian)
exit_action = QAction(QIcon('./images/ui/exit.png'), '停止', self)
exit_action.setShortcut('Ctrl+Q')
exit_action.triggered.connect(self.stop_loop)
self.toolBar.addAction(yaoguaifaxian_action)
self.toolBar.addAction(exit_action)
txt = QTextBrowser()
txt.setContentsMargins(5, 5, 5, 5)
self.setCentralWidget(txt)
self.show()
示例7: App
class App(QWidget):
def __init__(self, room):
super().__init__()
vbox = QVBoxLayout()
self.text_browser = QTextBrowser()
vbox.addWidget(self.text_browser)
self.text_entry = Entry(room)
self.text_entry.setFocus()
vbox.addWidget(self.text_entry)
self.setLayout(vbox)
self.messages_future = None
self._run(room)
def closeEvent(self, e):
if self.messages_future:
self.messages_future.cancel()
super().closeEvent(e)
def _run(self, room):
@coroutine
def logger():
while True:
message = (yield)
self.text_browser.append(message['text'])
self.messages_future = asyncio.ensure_future(
room.get_messages(logger()))
示例8: __init__
def __init__(self, exctype, excvalue, exctb):
super(ExceptionDialog, self).__init__()
self._tbshort = ''.join(traceback.format_exception_only(exctype, excvalue))
self._tbfull = ''.join(traceback.format_exception(exctype, excvalue, exctb))
layout = QVBoxLayout()
self.setLayout(layout)
self.errorLabel = QLabel()
layout.addWidget(self.errorLabel)
textview = QTextBrowser()
layout.addWidget(textview)
textview.setText(self._tbfull)
textview.moveCursor(QTextCursor.End)
layout.addWidget(widgets.Separator())
b = self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
b.button(QDialogButtonBox.Ok).setIcon(icons.get("tools-report-bug"))
layout.addWidget(b)
b.accepted.connect(self.accept)
b.rejected.connect(self.reject)
self.resize(600,300)
app.translateUI(self)
self.exec_()
示例9: Window
class Window(QWidget):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
model = FileListModel(self)
model.setDirPath(QLibraryInfo.location(QLibraryInfo.PrefixPath))
label = QLabel("Directory")
lineEdit = QLineEdit()
label.setBuddy(lineEdit)
view = QListView()
view.setModel(model)
self.logViewer = QTextBrowser()
self.logViewer.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
lineEdit.textChanged.connect(model.setDirPath)
lineEdit.textChanged.connect(self.logViewer.clear)
model.numberPopulated.connect(self.updateLog)
layout = QGridLayout()
layout.addWidget(label, 0, 0)
layout.addWidget(lineEdit, 0, 1)
layout.addWidget(view, 1, 0, 1, 2)
layout.addWidget(self.logViewer, 2, 0, 1, 2)
self.setLayout(layout)
self.setWindowTitle("Fetch More Example")
def updateLog(self, number):
self.logViewer.append("%d items added." % number)
示例10: __init__
def __init__(self, *args, **kwargs):
super(MainForm, self).__init__(*args, **kwargs)
self.resize(320, 360)
self.setWindowIcon(QIcon('./assets/eset_logo.png'))
self.setWindowTitle("ESET Key scraper")
self.label = QLabel(
"Keys for " + (KeyValue.get('evaluation_type') or 'EAV'))
self.label.setFixedSize(100, 20)
text_box = QTextBrowser()
text_box.setFont(QFont('Ubuntu mono', 12))
refresh_button = QPushButton("Refresh")
refresh_button.setFixedHeight(40)
settings_button = QPushButton()
settings_button.setFixedSize(60, 40)
settings_button.setIcon(QIcon('./assets/settings.png'))
layout = QGridLayout()
layout.addWidget(self.label, 1, 1, 1, 2)
layout.addWidget(text_box, 2, 1, 1, 2)
layout.addWidget(refresh_button, 3, 1)
layout.addWidget(settings_button, 3, 2)
refresh_button.clicked.connect(lambda: self.refresh(text_box))
settings_button.clicked.connect(self.show_settings)
self.setLayout(layout)
self.refresh(text_box)
示例11: PreviewWidgetColor
class PreviewWidgetColor(QGroupBox):
def __init__(self, parent=None):
super().__init__(parent)
self.setTitle(self.tr("Preview"))
self.setMaximumHeight(120)
self.parent = parent
vboxLayout = QVBoxLayout(self)
self.previewGroupBox = QGroupBox(self)
self.previewGroupBox.setObjectName("previewGroupBox")
vboxLayout.addWidget(self.previewGroupBox)
self.horizontalLayout = QHBoxLayout(self.previewGroupBox)
self.verticalLayout = QVBoxLayout()
self.horizontalLayout.addLayout(self.verticalLayout)
self.previewLabel = QLabel(self.previewGroupBox)
self.previewLabel.setText(self.tr("Window Text"))
self.previewLabel.setObjectName("previewLabel")
self.verticalLayout.addWidget(self.previewLabel)
self.previewPushButton = QPushButton(self.previewGroupBox)
self.previewPushButton.setText(self.tr("Button"))
self.previewPushButton.setObjectName("previewPushButton")
self.verticalLayout.addWidget(self.previewPushButton)
self.previewTextBrowser = QTextBrowser(self.previewGroupBox)
self.previewTextBrowser.setObjectName("previewTextBrowser")
css = iniToCss(os.path.join("/usr/share/color-schemes", self.parent.children()[1].currentItem().colorSchemeName))
self.previewTextBrowser.setHtml("""<style>#unclicked {color : rgb(%s);}
#clicked {color : rgb(%s);}</style>"""%(css[1][0],css[1][1]) +
self.tr("""<p>Normal text <a id='unclicked' href='#'>link</a> <a id='clicked' href='#'>visited</a></p>"""))
self.horizontalLayout.addWidget(self.previewTextBrowser)
self.previewPushButton.installEventFilter(self.previewGroupBox)
self.previewPushButton.setFocusPolicy(Qt.NoFocus)
self.previewTextBrowser.installEventFilter(self.previewGroupBox)
self.previewTextBrowser.setFocusPolicy(Qt.NoFocus)
self.previewTextBrowser.setTextInteractionFlags(Qt.NoTextInteraction)
def eventFilter(self, obj, event):
if self.previewPushButton:
if event.type() == QEvent.MouseButtonRelease:
return True
elif event.type() == QEvent.MouseButtonPress:
return True
elif event.type() == QEvent.MouseButtonDblClick:
return True
else:
return False
else:
super().eventFilter(obj, event)
示例12: __init__
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.setWindowTitle('About Linux Show Player')
self.setMaximumSize(500, 420)
self.setMinimumSize(500, 420)
self.resize(500, 420)
self.setLayout(QGridLayout())
self.icon = QLabel(self)
self.icon.setPixmap(QPixmap(self.ICON).scaled(100, 100,
transformMode=Qt.SmoothTransformation))
self.layout().addWidget(self.icon, 0, 0)
self.shortInfo = QLabel(self)
self.shortInfo.setAlignment(Qt.AlignCenter)
self.shortInfo.setText('<h2>Linux Show Player ' +
str(lisp.__version__) + '</h2>'
'Copyright © Francesco Ceruti')
self.layout().addWidget(self.shortInfo, 0, 1)
self.layout().addWidget(QWidget(), 1, 0, 1, 2)
# Informations tabs
self.tabWidget = QTabWidget(self)
self.layout().addWidget(self.tabWidget, 2, 0, 1, 2)
self.info = QTextBrowser(self)
self.info.setOpenExternalLinks(True)
self.info.setHtml(self.INFO)
self.tabWidget.addTab(self.info, 'Info')
self.license = QTextBrowser(self)
self.license.setOpenExternalLinks(True)
self.license.setHtml(self.LICENSE)
self.tabWidget.addTab(self.license, 'License')
self.contributors = QTextBrowser(self)
self.contributors.setOpenExternalLinks(True)
self.contributors.setHtml(self.CONTRIBUTORS)
self.tabWidget.addTab(self.contributors, 'Contributors')
# Ok button
self.buttons = QDialogButtonBox(QDialogButtonBox.Ok)
self.buttons.accepted.connect(self.accept)
self.layout().addWidget(self.buttons, 3, 1)
self.layout().setColumnStretch(0, 1)
self.layout().setColumnStretch(1, 3)
self.layout().setRowStretch(0, 6)
self.layout().setRowStretch(1, 1)
self.layout().setRowStretch(2, 16)
self.layout().setRowStretch(3, 3)
self.buttons.setFocus()
示例13: __init__
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self._info = None
self._text = ''
self._convertedtext = ''
self._encoding = None
self.mainwindow = parent
self.fromVersionLabel = QLabel()
self.fromVersion = QLineEdit()
self.reason = QLabel()
self.toVersionLabel = QLabel()
self.toVersion = QLineEdit()
self.lilyChooser = lilychooser.LilyChooser()
self.messages = QTextBrowser()
self.diff = QTextBrowser(lineWrapMode=QTextBrowser.NoWrap)
self.uni_diff = QTextBrowser(lineWrapMode=QTextBrowser.NoWrap)
self.copyCheck = QCheckBox(checked=
QSettings().value('convert_ly/copy_messages', True, bool))
self.tabw = QTabWidget()
self.tabw.addTab(self.messages, '')
self.tabw.addTab(self.diff, '')
self.tabw.addTab(self.uni_diff, '')
self.buttons = QDialogButtonBox(
QDialogButtonBox.Reset | QDialogButtonBox.Save |
QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttons.button(QDialogButtonBox.Ok).clicked .connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.buttons.button(QDialogButtonBox.Reset).clicked.connect(self.run)
self.buttons.button(QDialogButtonBox.Save).clicked.connect(self.saveFile)
layout = QVBoxLayout()
self.setLayout(layout)
grid = QGridLayout()
grid.addWidget(self.fromVersionLabel, 0, 0)
grid.addWidget(self.fromVersion, 0, 1)
grid.addWidget(self.reason, 0, 2, 1, 3)
grid.addWidget(self.toVersionLabel, 1, 0)
grid.addWidget(self.toVersion, 1, 1)
grid.addWidget(self.lilyChooser, 1, 3, 1, 2)
layout.addLayout(grid)
layout.addWidget(self.tabw)
layout.addWidget(self.copyCheck)
layout.addWidget(widgets.Separator())
layout.addWidget(self.buttons)
app.translateUI(self)
qutil.saveDialogSize(self, 'convert_ly/dialog/size', QSize(600, 300))
app.settingsChanged.connect(self.readSettings)
self.readSettings()
self.finished.connect(self.saveCopyCheckSetting)
self.lilyChooser.currentIndexChanged.connect(self.slotLilyPondVersionChanged)
self.slotLilyPondVersionChanged()
示例14: CheckInputWidget
class CheckInputWidget(QWidget, MooseWidget):
"""
Runs the executable with "--check-input" on the input file and stores the results.
Signals:
needInputFile: Emitted when we need the input file. Argument is the path where the input file will be written.
"""
needInputFile = pyqtSignal(str)
def __init__(self, **kwds):
super(CheckInputWidget, self).__init__(**kwds)
self.input_file = "peacock_check_input.i"
self.top_layout = WidgetUtils.addLayout(vertical=True)
self.setLayout(self.top_layout)
self.output = QTextBrowser(self)
self.output.setStyleSheet("QTextBrowser { background: black; color: white; }")
self.output.setReadOnly(True)
self.top_layout.addWidget(self.output)
self.button_layout = WidgetUtils.addLayout()
self.top_layout.addLayout(self.button_layout)
self.hide_button = WidgetUtils.addButton(self.button_layout, self, "Hide", lambda: self.hide())
self.check_button = WidgetUtils.addButton(self.button_layout, self, "Check", self._check)
self.resize(800, 500)
self.setup()
self.path = None
def cleanup(self):
try:
os.remove(self.input_file)
except:
pass
def check(self, path):
"""
Runs the executable with "--check-input" and adds the output to the window
Input:
path[str]: Path to the executable
"""
self.path = path
self._check()
def _check(self):
"""
Runs the executable with "--check-input" and adds the output to the window
"""
input_file = os.path.abspath(self.input_file)
self.needInputFile.emit(input_file)
self.output.clear()
try:
args = ["-i", input_file, "--check-input"]
output = ExeLauncher.runExe(self.path, args, print_errors=False)
output_html = TerminalUtils.terminalOutputToHtml(output)
self.output.setHtml("<pre>%s</pre>" % output_html)
except Exception as e:
output_html = TerminalUtils.terminalOutputToHtml(str(e))
self.output.setHtml("<pre>%s</pre>" % output_html)
self.cleanup()
示例15: error_report_main
def error_report_main():
error_message = sys.stdin.read()
error_message = "<pre>{}</pre>".format(html.escape(error_message).replace("\n", "<br>"))
app = QApplication(sys.argv)
if sys.platform == 'darwin':
# workaround macOS QTBUG-61562
from brickv.mac_pasteboard_mime_fixed import MacPasteboardMimeFixed
mac_pasteboard_mime_fixed = MacPasteboardMimeFixed()
window = QMainWindow()
window.setWindowTitle('Error - Brick Viewer ' + config.BRICKV_VERSION)
window.setWindowIcon(QIcon(load_pixmap('brickv-icon.png')))
widget = QWidget()
window.setCentralWidget(widget)
widget.setLayout(QHBoxLayout())
icon = QLabel()
icon.setPixmap(QMessageBox.standardIcon(QMessageBox.Critical))
icon.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
widget.layout().addWidget(icon)
right_widget = QWidget()
right_widget.setLayout(QVBoxLayout())
right_widget.layout().setContentsMargins(0, 0, 0, 0)
label = QLabel("Please report this error to <a href='mailto:[email protected]'>[email protected]</a>.<br/><br/>" +
"If you know what caused the error and could work around it, please report it anyway. This allows us to improve the error messages.")
label.setWordWrap(True)
label.setOpenExternalLinks(True)
right_widget.layout().addWidget(label)
tb = QTextBrowser()
tb.setHtml(error_message)
right_widget.layout().addWidget(tb)
cbox = QCheckBox("Show this message again")
cbox.setChecked(True)
right_widget.layout().addWidget(cbox)
btn = QPushButton("Close")
btn.clicked.connect(lambda event: app.exit())
right_widget.layout().addWidget(btn)
widget.layout().addWidget(right_widget)
window.setMinimumSize(640, 400)
window.resize(950, 600)
window.show()
app.exec_()
return int(cbox.isChecked())