本文整理汇总了Python中PyQt5.QtWidgets.QTextBrowser.setReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser.setReadOnly方法的具体用法?Python QTextBrowser.setReadOnly怎么用?Python QTextBrowser.setReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTextBrowser
的用法示例。
在下文中一共展示了QTextBrowser.setReadOnly方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CheckInputWidget
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setReadOnly [as 别名]
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()
示例2: LogWidget
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setReadOnly [as 别名]
class LogWidget(QWidget, MooseWidget):
"""
A widget that shows the log.
This ties into mooseutils.message.mooseMessage which will
emit a signal on mooseutils.message.messageEmitter
This widget listens to messageEmitter and puts
the text in the widget.
Color text is supported.
"""
def __init__(self, **kwds):
"""
Constructor.
"""
super(LogWidget, self).__init__(**kwds)
self.top_layout = WidgetUtils.addLayout(vertical=True)
self.setLayout(self.top_layout)
self.log = QTextBrowser(self)
self.log.setStyleSheet("QTextBrowser { background: black; color: white; }")
self.log.setReadOnly(True)
message.messageEmitter.message.connect(self._write)
self.button_layout = WidgetUtils.addLayout()
self.hide_button = WidgetUtils.addButton(self.button_layout, self, "Hide", lambda: self.hide())
self.clear_button = WidgetUtils.addButton(self.button_layout, self, "Clear", lambda: self.log.clear())
self.top_layout.addWidget(self.log)
self.top_layout.addLayout(self.button_layout)
self.resize(800, 500)
@pyqtSlot(str, str)
def _write(self, msg, color):
"""
This is the slot that will write the message to the widget.
Inputs:
msg: The message to write
color: The color to write the text in.
"""
if not msg:
return
msg = msg.encode('utf-8') # make sure if there are bad characters in the message that we can show them.
if not color or color == "None":
color = "white"
else:
color = str(color)
if msg.find("\n") >= 0:
self.log.insertHtml('<div style="color:%s"><pre><code>%s</code></pre></div><br>' % (color.lower(), escape(msg)))
else:
self.log.insertHtml('<div style="color:%s">%s</div><br>' % (color.lower(), escape(msg)))
示例3: AboutDialog
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setReadOnly [as 别名]
class AboutDialog(QDialog):
def __init__(self, title="Test", message="Test Text"):
super(AboutDialog, self).__init__()
self.title = title
self.message = message
self.initUI()
def initUI(self):
"""
initUI()
"""
vbox = QVBoxLayout(self)
grid1 = QGridLayout()
grid1.setSpacing(10)
self.text = QTextBrowser()
self.text.setReadOnly(True)
self.text.setOpenExternalLinks(True)
self.text.append(self.message)
self.text.moveCursor(QTextCursor.Start)
self.text.ensureCursorVisible()
vbox.addWidget(self.text)
self.setLayout(vbox)
self.setMinimumSize(550, 450)
self.resize(550, 600)
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
self.setWindowTitle(self.title)
iconWT = QIcon()
iconWT.addPixmap(QPixmap(":images/DXF2GCODE-001.ico"),
QIcon.Normal, QIcon.Off)
self.setWindowIcon(QIcon(iconWT))
self.exec_()
示例4: AboutWhat
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setReadOnly [as 别名]
class AboutWhat(QDialog):
def __init__(self, parent=None, pytesting=False):
super(AboutWhat, self).__init__(parent)
self._pytesting = pytesting
self.setWindowTitle('About %s' % __appname__)
self.setWindowIcon(icons.get_icon('master'))
self.setMinimumSize(800, 700)
self.setWindowFlags(Qt.Window |
Qt.CustomizeWindowHint |
Qt.WindowCloseButtonHint)
self.__initUI__()
def __initUI__(self):
"""Initialize the GUI."""
self.manager_updates = None
# ---- AboutTextBox
self.AboutTextBox = QTextBrowser()
self.AboutTextBox.installEventFilter(self)
self.AboutTextBox.setReadOnly(True)
self.AboutTextBox.setFixedWidth(850)
self.AboutTextBox.setFrameStyle(0)
self.AboutTextBox.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.AboutTextBox.setOpenExternalLinks(True)
self.AboutTextBox.setStyleSheet('QTextEdit {background-color:"white"}')
self.AboutTextBox.document().setDocumentMargin(0)
self.set_html_in_AboutTextBox()
# ---- toolbar
self.ok_btn = QPushButton('OK')
self.ok_btn.clicked.connect(self.close)
self.btn_check_updates = QPushButton(' Check for Updates ')
self.btn_check_updates.clicked.connect(
self._btn_check_updates_isclicked)
toolbar = QGridLayout()
toolbar.addWidget(self.btn_check_updates, 0, 1)
toolbar.addWidget(self.ok_btn, 0, 2)
toolbar.setContentsMargins(0, 0, 0, 0)
toolbar.setColumnStretch(0, 100)
# ---- Main Grid
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(self.AboutTextBox, 0, 1)
grid.addLayout(toolbar, 1, 1)
grid.setColumnStretch(1, 500)
grid.setContentsMargins(10, 10, 10, 10)
self.setLayout(grid)
self.ok_btn.setFocus()
@QSlot()
def _btn_check_updates_isclicked(self):
"""Handles when the button to check for updates is clicked."""
self.manager_updates = ManagerUpdates(self, self._pytesting)
def set_html_in_AboutTextBox(self):
"""Set the text in the About GWHAT text browser widget."""
# ---- Header logo
width = 750
filename = os.path.join(
__rootdir__, 'ressources', 'WHAT_banner_750px.png')
# http://doc.qt.io/qt-4.8/richtext-html-subset.html
if platform.system() == 'Windows':
fontfamily = "Segoe UI" # "Cambria" #"Calibri" #"Segoe UI""
elif platform.system() == 'Linux':
fontfamily = "Ubuntu"
html = """
<html>
<head>
<style>
p {font-size: 16px;
font-family: "%s";
margin-right:50px;
margin-left:50px;
}
p1 {font-size: 16px;
font-family: "%s";
margin-right:50px;
margin-left:50px;
}
</style>
</head>
<body>
""" % (fontfamily, fontfamily)
#.........这里部分代码省略.........
示例5: DolphinUpdate
# 需要导入模块: from PyQt5.QtWidgets import QTextBrowser [as 别名]
# 或者: from PyQt5.QtWidgets.QTextBrowser import setReadOnly [as 别名]
class DolphinUpdate(QMainWindow):
APP_TITLE = 'DolphinUpdate 3.1'
DOWNLOAD_PATH = os.path.join(os.getenv('APPDATA'), 'DolphinUpdate/')
def __init__(self, user_data_control):
super().__init__()
sys.excepthook = self._displayError
self._udc = user_data_control
self.check = QPixmap("res/check.png")
self.cancel = QPixmap("res/cancel.png")
self.setGeometry(500, 500, 500, 465)
self.init_ui()
self.init_window()
self.init_user_data()
self.setWindowTitle(self.APP_TITLE)
self.setWindowIcon(QIcon('res/rabbit.png'))
center(self)
self.show()
# PyQt Error Handling
def _displayError(self, etype, evalue, etraceback):
tb = ''.join(traceback.format_exception(etype, evalue, etraceback))
QMessageBox.critical(self, "FATAL ERROR", "An unexpected error occurred:\n%s\n\n%s" % (evalue, tb))
def init_ui(self):
"""create the UI elements in the main window"""
self.statusBar().showMessage('Ready')
main = QWidget()
self.setCentralWidget(main)
self.dolphin_dir = QLineEdit(main)
self.dolphin_dir.setPlaceholderText("Please Select a Dolphin Directory")
self.dolphin_dir.setReadOnly(True)
self.version = QLineEdit(main)
self.version.setPlaceholderText("Installation Status Unknown")
self.version.setReadOnly(True)
self.current = QLineEdit(main)
self.current.setPlaceholderText("Loading Current Version...")
self.current.setReadOnly(True)
self.changelog_frame = QFrame(main)
changelog_vbox = QVBoxLayout(self.changelog_frame)
self.changelog = QTextBrowser(main)
self.changelog.setPlaceholderText("Loading Changelog...")
self.changelog.setReadOnly(True)
changelog_vbox.addWidget(QLabel('Changelog:'))
changelog_vbox.addWidget(self.changelog)
self.changelog_frame.setContentsMargins(0, 20, -7, 0)
grid = QGridLayout()
main.setLayout(grid)
self.dolphin_dir_status = QLabel(main)
self.dolphin_dir_status.setPixmap(self.cancel)
self.version_status = QLabel(main)
self.version_status.setPixmap(self.cancel)
self.current_status = QLabel(main)
self.current_status.setPixmap(QPixmap("res/info.png"))
grid.addWidget(self.dolphin_dir_status, 0, 0, Qt.AlignCenter)
grid.addWidget(QLabel('Dolphin Directory:'), 0, 2)
grid.addWidget(self.dolphin_dir, 0, 3)
grid.addWidget(self.version_status, 1, 0, Qt.AlignCenter)
grid.addWidget(QLabel('Your Version:'), 1, 2)
grid.addWidget(self.version, 1, 3)
grid.addWidget(self.current_status, 2, 0, Qt.AlignCenter)
grid.addWidget(QLabel('Current Version:'), 2, 2)
grid.addWidget(self.current, 2, 3)
grid.addWidget(self.changelog_frame, 3, 0, 1, 4)
grid.setSpacing(10)
grid.setVerticalSpacing(2)
grid.setRowStretch(3, 1)
def init_window(self):
self.update_thread = UpdateThread()
self.update_thread.current.connect(self.update_current)
self.update_thread.changelog.connect(self.update_changelog)
self.update_thread.error.connect(self.show_warning)
self.update_thread.start()
self.download_thread = DownloadThread()
self.download_thread.status.connect(self.update_version)
self.download_thread.error.connect(self.show_warning)
open_action = QAction(QIcon('res/open.png'), '&Open', self)
open_action.setShortcut('Ctrl+O')
open_action.setStatusTip('Select Dolphin Folder')
open_action.triggered.connect(self.select_dolphin_folder)
#.........这里部分代码省略.........