本文整理汇总了Python中PyQt4.Qt.QTextBrowser类的典型用法代码示例。如果您正苦于以下问题:Python QTextBrowser类的具体用法?Python QTextBrowser怎么用?Python QTextBrowser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextBrowser类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ViewLog
class ViewLog(QDialog): # {{{
def __init__(self, title, html, parent=None):
QDialog.__init__(self, parent)
self.l = l = QVBoxLayout()
self.setLayout(l)
self.tb = QTextBrowser(self)
self.tb.setHtml('<pre style="font-family: monospace">%s</pre>' % html)
l.addWidget(self.tb)
self.bb = QDialogButtonBox(QDialogButtonBox.Ok)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
self.copy_button = self.bb.addButton(_('Copy to clipboard'),
self.bb.ActionRole)
self.copy_button.setIcon(QIcon(I('edit-copy.png')))
self.copy_button.clicked.connect(self.copy_to_clipboard)
l.addWidget(self.bb)
self.setModal(False)
self.resize(QSize(700, 500))
self.setWindowTitle(title)
self.setWindowIcon(QIcon(I('debug.png')))
self.show()
def copy_to_clipboard(self):
txt = self.tb.toPlainText()
QApplication.clipboard().setText(txt)
示例2: __init__
def __init__(self, *args):
QTextBrowser.__init__(self, *args)
self.setStyleSheet("background:white;color:black;")
try:
self.setText(codecs.open(self.loadFile(), "r", "UTF-8").read())
except Exception, msg:
raise GUIError(msg)
示例3: __init__
def __init__(self, log, parent=None):
QDialog.__init__(self, parent)
self.log = log
self.l = l = QVBoxLayout()
self.setLayout(l)
self.tb = QTextBrowser(self)
l.addWidget(self.tb)
self.bb = QDialogButtonBox(QDialogButtonBox.Close)
l.addWidget(self.bb)
self.copy_button = self.bb.addButton(_('Copy to clipboard'),
self.bb.ActionRole)
self.copy_button.clicked.connect(self.copy_to_clipboard)
self.copy_button.setIcon(QIcon(I('edit-copy.png')))
self.bb.rejected.connect(self.reject)
self.bb.accepted.connect(self.accept)
self.setWindowTitle(_('Download log'))
self.setWindowIcon(QIcon(I('debug.png')))
self.resize(QSize(800, 400))
self.keep_updating = True
self.last_html = None
self.finished.connect(self.stop)
QTimer.singleShot(100, self.update_log)
self.show()
示例4: __init__
def __init__(self, text, parent=None, clicked_func=None, caption="(caption)", size=None):
QDialog.__init__(self, parent)
self.setWindowTitle(caption)
self.setWindowIcon(QtGui.QIcon("ui/border/MainWindow"))
self.setObjectName("WikiHelpBrowser")
TextBrowserLayout = QGridLayout(self)
TextBrowserLayout.setSpacing(5)
TextBrowserLayout.setMargin(2)
self.text_browser = QTextBrowser(self)
self.text_browser.setOpenExternalLinks(True)
self.text_browser.setObjectName("text_browser")
TextBrowserLayout.addWidget(self.text_browser, 0, 0, 1, 0)
self.text_browser.setMinimumSize(400, 200)
# make it pale yellow like a post-it note
self.text_browser.setHtml('<qt bgcolor="#FFFF80">' + text)
self.close_button = QPushButton(self)
self.close_button.setObjectName("close_button")
self.close_button.setText("Close")
TextBrowserLayout.addWidget(self.close_button, 1, 1)
spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
TextBrowserLayout.addItem(spacer, 1, 0)
self.resize(QSize(300, 300).expandedTo(self.minimumSizeHint()))
if size == 1:
self.text_browser.setMinimumSize(200, 400)
self.resize(QSize(300, 550).expandedTo(self.minimumSizeHint()))
if size == 2:
self.resize(QSize(650, 250).expandedTo(self.minimumSizeHint()))
self.connect(self.close_button, SIGNAL("clicked()"), self.close)
return
示例5: __init__
def __init__(self, parent, config_name=None, buttons=[], *args):
"""Creates dialog.
'config_name' is used to get/set default window size from Config object
'buttons' can be a list of names or (QPixmapWrapper,name[,tooltip]) tuples to provide
custom buttons at the bottom of the dialog. When a button is clicked, the dialog
emits SIGNAL("name").
A "Close" button is always provided, this simply hides the dialog.
"""
QDialog.__init__(self, parent, *args)
self.setModal(False)
lo = QVBoxLayout(self)
# create viewer
self.label = QLabel(self)
self.label.setMargin(5)
self.label.setWordWrap(True)
lo.addWidget(self.label)
self.label.hide()
self.viewer = QTextBrowser(self)
lo.addWidget(self.viewer)
# self.viewer.setReadOnly(True)
self.viewer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
QObject.connect(self.viewer, SIGNAL("anchorClicked(const QUrl &)"), self._urlClicked)
self._source = None
lo.addSpacing(5)
# create button bar
btnfr = QFrame(self)
btnfr.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
# btnfr.setMargin(5)
lo.addWidget(btnfr)
lo.addSpacing(5)
btnfr_lo = QHBoxLayout(btnfr)
btnfr_lo.setMargin(5)
# add user buttons
self._user_buttons = {}
for name in buttons:
if isinstance(name, str):
btn = QPushButton(name, btnfr)
elif isinstance(name, (list, tuple)):
if len(name) < 3:
pixmap, name = name
tip = None
else:
pixmap, name, tip = name
btn = QPushButton(pixmap.icon(), name, btnfr)
if tip:
btn.setToolTip(tip)
self._user_buttons[name] = btn
btn._clicked = Kittens.utils.curry(self.emit, SIGNAL(name))
self.connect(btn, SIGNAL("clicked()"), btn._clicked)
btnfr_lo.addWidget(btn, 1)
# add a Close button
btnfr_lo.addStretch(100)
closebtn = QPushButton(pixmaps.grey_round_cross.icon(), "Close", btnfr)
self.connect(closebtn, SIGNAL("clicked()"), self.hide)
btnfr_lo.addWidget(closebtn, 1)
# resize selves
self.config_name = config_name or "html-viewer"
width = Config.getint('%s-width' % self.config_name, 512)
height = Config.getint('%s-height' % self.config_name, 512)
self.resize(QSize(width, height))
示例6: __init__
def __init__(self, movie):
self.movie = movie
QDialog.__init__(self, None)
self.setObjectName("movie_warning")
self.text_browser = QTextBrowser(self)
self.text_browser.setObjectName("movie_warning_textbrowser")
self.text_browser.setMinimumSize(400, 40)
self.setWindowTitle('Rewind your movie?')
self.text_browser.setPlainText(
"You may want to rewind the movie now. If you save the part without " +
"rewinding the movie, the movie file will become invalid because it " +
"depends upon the initial atom positions. The atoms move as the movie " +
"progresses, and saving the part now will save the final positions, " +
"which are incorrect for the movie you just watched.")
self.ok_button = QPushButton(self)
self.ok_button.setObjectName("ok_button")
self.ok_button.setText("Rewind movie")
self.cancel_button = QPushButton(self)
self.cancel_button.setObjectName("cancel_button")
self.cancel_button.setText("No thanks")
layout = QGridLayout(self)
layout.addWidget(self.text_browser,0,0,0,1)
layout.addWidget(self.ok_button,1,0)
layout.addWidget(self.cancel_button,1,1)
self.connect(self.ok_button,SIGNAL("clicked()"),self.rewindMovie)
self.connect(self.cancel_button,SIGNAL("clicked()"),self.noThanks)
示例7: __init__
def __init__(self, movie):
self.movie = movie
QDialog.__init__(self, None)
self.setObjectName("movie_warning")
self.text_browser = QTextBrowser(self)
self.text_browser.setObjectName("movie_warning_textbrowser")
self.text_browser.setMinimumSize(400, 40)
self.setWindowTitle('Rewind your movie?')
self.text_browser.setPlainText( #bruce 080827 revised text
"You may want to rewind the movie now. The atoms move as the movie "
"progresses, and saving the part without rewinding will save the "
"current positions, which is sometimes useful, but will make the "
"movie invalid, because .dpb files only store deltas relative to "
"the initial atom positions, and don't store the initial positions "
"themselves." )
self.ok_button = QPushButton(self)
self.ok_button.setObjectName("ok_button")
self.ok_button.setText("Rewind movie")
self.cancel_button = QPushButton(self)
self.cancel_button.setObjectName("cancel_button")
self.cancel_button.setText("Exit command without rewinding") #bruce 080827 revised text
# Note: this is not, in fact, a cancel button --
# there is no option in the caller to prevent exiting the command.
# There is also no option to "forward to final position",
# though for a minimize movie, that might be most useful.
# [bruce 080827 comment]
layout = QGridLayout(self)
layout.addWidget(self.text_browser, 0, 0, 0, 1)
layout.addWidget(self.ok_button, 1, 0)
layout.addWidget(self.cancel_button, 1, 1)
self.connect(self.ok_button, SIGNAL("clicked()"), self.rewindMovie)
self.connect(self.cancel_button, SIGNAL("clicked()"), self.noThanks)
示例8: LogViewer
class LogViewer(QDialog): # {{{
def __init__(self, log, parent=None):
QDialog.__init__(self, parent)
self.log = log
self.l = l = QVBoxLayout()
self.setLayout(l)
self.tb = QTextBrowser(self)
l.addWidget(self.tb)
self.bb = QDialogButtonBox(QDialogButtonBox.Close)
l.addWidget(self.bb)
self.copy_button = self.bb.addButton(_('Copy to clipboard'),
self.bb.ActionRole)
self.copy_button.clicked.connect(self.copy_to_clipboard)
self.copy_button.setIcon(QIcon(I('edit-copy.png')))
self.bb.rejected.connect(self.reject)
self.bb.accepted.connect(self.accept)
self.setWindowTitle(_('Download log'))
self.setWindowIcon(QIcon(I('debug.png')))
self.resize(QSize(800, 400))
self.keep_updating = True
self.last_html = None
self.finished.connect(self.stop)
QTimer.singleShot(100, self.update_log)
self.show()
def copy_to_clipboard(self):
QApplication.clipboard().setText(''.join(self.log.plain_text))
def stop(self, *args):
self.keep_updating = False
def update_log(self):
if not self.keep_updating:
return
html = self.log.html
if html != self.last_html:
self.last_html = html
self.tb.setHtml('<pre style="font-family:monospace">%s</pre>'%html)
QTimer.singleShot(1000, self.update_log)
示例9: __init__
def __init__(self, win):
self.xmlfile = os.path.join(_sponsordir, 'sponsors.xml')
self.win = win
self.needToAsk = False
self.downloadSponsors = False
threading.Thread.__init__(self)
if not self.refreshWanted():
return
if env.prefs[sponsor_permanent_permission_prefs_key]:
# We have a permanent answer so no need for a dialog
if env.prefs[sponsor_download_permission_prefs_key]:
self.downloadSponsors = True
return
self.needToAsk = True
QDialog.__init__(self, None)
self.setObjectName("Permission")
self.setModal(True) #This fixes bug 2296. Mitigates bug 2297
layout = QGridLayout()
self.setLayout(layout)
layout.setMargin(0)
layout.setSpacing(0)
layout.setObjectName("PermissionLayout")
self.text_browser = QTextBrowser(self)
self.text_browser.setObjectName("text_browser")
layout.addWidget(self.text_browser,0,0,1,4)
self.text_browser.setMinimumSize(400, 80)
self.setWindowTitle('May we use your network connection?')
self.setWindowIcon(geticon('ui/border/MainWindow.png'))
self.text_browser.setPlainText(self.text)
self.accept_button = QPushButton(self)
self.accept_button.setObjectName("accept_button")
self.accept_button.setText("Always OK")
self.accept_once_button = QPushButton(self)
self.accept_once_button.setObjectName("accept_once_button")
self.accept_once_button.setText("OK now")
self.decline_once_button = QPushButton(self)
self.decline_once_button.setObjectName("decline_once_button")
self.decline_once_button.setText("Not now")
self.decline_always_button = QPushButton(self)
self.decline_always_button.setObjectName("decline_always_button")
self.decline_always_button.setText("Never")
layout.addWidget(self.accept_button,1,0)
layout.addWidget(self.accept_once_button,1,1)
layout.addWidget(self.decline_once_button,1,2)
layout.addWidget(self.decline_always_button,1,3)
self.connect(self.accept_button,SIGNAL("clicked()"),self.acceptAlways)
self.connect(self.accept_once_button,SIGNAL("clicked()"),self.acceptJustOnce)
self.connect(self.decline_once_button,SIGNAL("clicked()"),self.declineJustOnce)
self.connect(self.decline_always_button,SIGNAL("clicked()"),self.declineAlways)
示例10: __init__
def __init__(self, parent):
QTextBrowser.__init__(self, parent.centralWidget())
self.view = parent.splitter
self.setGeometry(self.view.geometry())
self.setWordWrap(True)
self.setVisible(False)
示例11: PermissionDialog
class PermissionDialog(QDialog, threading.Thread):
# Politely explain what we're doing as clearly as possible. This will be the
# user's first experience of the sponsorship system and we want to use the
# Google axiom of "Don't be evil".
text = ("We would like to use your network connection to update a list of our " +
"sponsors. This enables us to recoup some of our development costs " +
"by putting buttons with sponsor logos on some dialogs. If you click " +
"on a sponsor logo button, you will get a small window with some " +
"information about that sponsor. May we do this? Otherwise we'll " +
"just use buttons with our own Nanorex logo.")
def __init__(self, win):
self.xmlfile = os.path.join(_sponsordir, 'sponsors.xml')
self.win = win
self.needToAsk = False
self.downloadSponsors = False
threading.Thread.__init__(self)
if not self.refreshWanted():
return
if env.prefs[sponsor_permanent_permission_prefs_key]:
# We have a permanent answer so no need for a dialog
if env.prefs[sponsor_download_permission_prefs_key]:
self.downloadSponsors = True
return
self.needToAsk = True
QDialog.__init__(self, None)
self.setObjectName("Permission")
self.setModal(True) #This fixes bug 2296. Mitigates bug 2297
layout = QGridLayout()
self.setLayout(layout)
layout.setMargin(0)
layout.setSpacing(0)
layout.setObjectName("PermissionLayout")
self.text_browser = QTextBrowser(self)
self.text_browser.setObjectName("text_browser")
layout.addWidget(self.text_browser,0,0,1,4)
self.text_browser.setMinimumSize(400, 80)
self.setWindowTitle('May we use your network connection?')
self.setWindowIcon(geticon('ui/border/MainWindow.png'))
self.text_browser.setPlainText(self.text)
self.accept_button = QPushButton(self)
self.accept_button.setObjectName("accept_button")
self.accept_button.setText("Always OK")
self.accept_once_button = QPushButton(self)
self.accept_once_button.setObjectName("accept_once_button")
self.accept_once_button.setText("OK now")
self.decline_once_button = QPushButton(self)
self.decline_once_button.setObjectName("decline_once_button")
self.decline_once_button.setText("Not now")
self.decline_always_button = QPushButton(self)
self.decline_always_button.setObjectName("decline_always_button")
self.decline_always_button.setText("Never")
layout.addWidget(self.accept_button,1,0)
layout.addWidget(self.accept_once_button,1,1)
layout.addWidget(self.decline_once_button,1,2)
layout.addWidget(self.decline_always_button,1,3)
self.connect(self.accept_button,SIGNAL("clicked()"),self.acceptAlways)
self.connect(self.accept_once_button,SIGNAL("clicked()"),self.acceptJustOnce)
self.connect(self.decline_once_button,SIGNAL("clicked()"),self.declineJustOnce)
self.connect(self.decline_always_button,SIGNAL("clicked()"),self.declineAlways)
def acceptAlways(self):
env.prefs[sponsor_download_permission_prefs_key] = True
env.prefs[sponsor_permanent_permission_prefs_key] = True
self.downloadSponsors = True
self.close()
def acceptJustOnce(self):
env.prefs[sponsor_permanent_permission_prefs_key] = False
self.downloadSponsors = True
self.close()
def declineAlways(self):
env.prefs[sponsor_download_permission_prefs_key] = False
env.prefs[sponsor_permanent_permission_prefs_key] = True
self.close()
def declineJustOnce(self):
env.prefs[sponsor_permanent_permission_prefs_key] = False
self.close()
def run(self):
#
# Implements superclass's threading.Thread.run() function
#
if self.downloadSponsors:
_download_xml_file(self.xmlfile)
self.finish()
env.prefs[sponsor_md5_mismatch_flag_key] = self.md5Mismatch()
def refreshWanted(self):
if not os.path.exists(self.xmlfile):
return True
#.........这里部分代码省略.........
示例12: HTMLViewerDialog
class HTMLViewerDialog(QDialog):
"""This class implements a dialog to view a piece of HTML text."""
def __init__(self, parent, config_name=None, buttons=[], *args):
"""Creates dialog.
'config_name' is used to get/set default window size from Config object
'buttons' can be a list of names or (QPixmapWrapper,name[,tooltip]) tuples to provide
custom buttons at the bottom of the dialog. When a button is clicked, the dialog
emits SIGNAL("name").
A "Close" button is always provided, this simply hides the dialog.
"""
QDialog.__init__(self, parent, *args)
self.setModal(False)
lo = QVBoxLayout(self)
# create viewer
self.label = QLabel(self)
self.label.setMargin(5)
self.label.setWordWrap(True)
lo.addWidget(self.label)
self.label.hide()
self.viewer = QTextBrowser(self)
lo.addWidget(self.viewer)
# self.viewer.setReadOnly(True)
self.viewer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
QObject.connect(self.viewer, SIGNAL("anchorClicked(const QUrl &)"), self._urlClicked)
self._source = None
lo.addSpacing(5)
# create button bar
btnfr = QFrame(self)
btnfr.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
# btnfr.setMargin(5)
lo.addWidget(btnfr)
lo.addSpacing(5)
btnfr_lo = QHBoxLayout(btnfr)
btnfr_lo.setMargin(5)
# add user buttons
self._user_buttons = {}
for name in buttons:
if isinstance(name, str):
btn = QPushButton(name, btnfr)
elif isinstance(name, (list, tuple)):
if len(name) < 3:
pixmap, name = name
tip = None
else:
pixmap, name, tip = name
btn = QPushButton(pixmap.icon(), name, btnfr)
if tip:
btn.setToolTip(tip)
self._user_buttons[name] = btn
btn._clicked = Kittens.utils.curry(self.emit, SIGNAL(name))
self.connect(btn, SIGNAL("clicked()"), btn._clicked)
btnfr_lo.addWidget(btn, 1)
# add a Close button
btnfr_lo.addStretch(100)
closebtn = QPushButton(pixmaps.grey_round_cross.icon(), "Close", btnfr)
self.connect(closebtn, SIGNAL("clicked()"), self.hide)
btnfr_lo.addWidget(closebtn, 1)
# resize selves
self.config_name = config_name or "html-viewer"
width = Config.getint('%s-width' % self.config_name, 512)
height = Config.getint('%s-height' % self.config_name, 512)
self.resize(QSize(width, height))
def resizeEvent(self, ev):
QDialog.resizeEvent(self, ev)
sz = ev.size()
Config.set('%s-width' % self.config_name, sz.width())
Config.set('%s-height' % self.config_name, sz.height())
def setDocument(self, filename, empty=""):
"""Sets the HTML text to be displayed. """
self._source = QUrl.fromLocalFile(filename)
if os.path.exists(filename):
self.viewer.setSource(self._source)
else:
self.viewer.setText(empty)
def _urlClicked(self, url):
path = str(url.path())
if path:
self.emit(SIGNAL("viewPath"), path)
# to make sure it keeps displaying the same thing
self.viewer.setSource(self._source)
def reload(self):
self.viewer.reload()
def setLabel(self, label=None):
if label is None:
self.label.hide()
else:
self.label.setText(label)
self.label.show()