本文整理汇总了Python中PySide.QtGui.QTextEdit.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.clear方法的具体用法?Python QTextEdit.clear怎么用?Python QTextEdit.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SummarySection
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import clear [as 别名]
class SummarySection(QTabWidget):
"""
Represents the summary section.
Takes reply data from main ui and updates it's tabs
Keeps track of cumulative summary data.
"""
def __init__(self, parent=None):
super(SummarySection, self).__init__(parent)
self.text_edit_summary = QTextEdit()
self.text_edit_summary.setReadOnly(True)
self.addTab(self.text_edit_summary, "Output")
self.ball_grid = BallGrid(30, 30, 2)
self.addTab(self.ball_grid, "Led View")
self.tab_summary = SummaryTab()
self.addTab(self.tab_summary, "Summary")
#some private fields, keep track of accumulated summary data
self.current_ip = 0 #we take reply data for ips in order
self.sent_packets = 0
self.received_packets = 0
self.average_delay = 0
def setIPs(self, ips):
#this indicates the start of a new ping, could be treated
#as a pingStarted signal
self.current_ip = 0
self.sent_packets = 0
self.received_packets = 0
self.average_delay = 0
self.text_edit_summary.clear()
self.ball_grid.layoutForIps(ips)
self.tab_summary.zeroOut()
def takeReplyData(self, replyData, sentPackets): #sent packets is passed in as extra
"""
Update the output text area with the replyData string representation
Set proper widget states on the BallGrid
Calculate summaries cumulatively and set them for display on the summary tab
"""
self.text_edit_summary.append(str(replyData))
packets_lost = replyData.packets_lost
if packets_lost:
self.ball_grid.setStateAt(self.current_ip, BallWidget.UNREACHABLE)
else:
self.ball_grid.setStateAt(self.current_ip, BallWidget.REACHABLE)
self.current_ip += 1
self.sent_packets += sentPackets
self.received_packets = self.sent_packets - replyData.packets_lost
self.average_delay += (replyData.rtt / self.current_ip) #the current_ip reflects the overall number of replies
summary_data = SummaryData(self.sent_packets, self.received_packets, self.average_delay)
self.tab_summary.setSummaryData(summary_data)
def pingingStoppedHandler(self):
self.ball_grid.pingingCancelledHandler()
示例2: Console
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import clear [as 别名]
class Console():
def __init__(self, targetLayoutContainer):
self.textarea = QTextEdit()
self.commits = QListWidget()
self.commits.addAction(QAction('Rollback to this revision', self.commits, triggered=self.rollback))
self.commits.setContextMenuPolicy(Qt.ActionsContextMenu)
self.widget = QTabWidget()
self.widget.addTab(self.textarea, 'Log')
self.widget.addTab(self.commits, 'Commits')
targetLayoutContainer.addWidget(self.widget)
def color(self, module, function, color, *args):
print module, function, args
prettyString = '<font color="' + color + '"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>'
self.textarea.append(''.join(prettyString))
def info(self, module, function, *args):
print module, function, args
prettyString = '<font color="black"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>'
self.textarea.append(''.join(prettyString))
def error(self, module, function, *args):
print module, function, args
prettyString = '<font color="red"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>'
self.textarea.append(''.join(prettyString))
def warn(self, module, function, *args):
print module, function, args
prettyString = '<font color="#BE9900"><b>', module, '</b><i>::', function, '</i> --> ', ''.join(args), '</font>'
self.textarea.append(''.join(prettyString))
def set_commits(self, commits):
self.commits.clear()
for commit in commits:
self.commits.addItem(commit)
def clear(self):
self.textarea.clear()
def rollback(self):
targetCommit = self.commits.currentItem().text().split(' ')[0]
if QMessageBox.warning(None, 'Rollback to commit?', 'All commits after ' + targetCommit + ' will be lost, proceed?', QMessageBox.Yes, QMessageBox.No) == QMessageBox.Yes:
rollback(targetCommit)
示例3: Prozor
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import clear [as 别名]
class Prozor(QWidget):
def __init__(self,element):
#kreiramo prozor
QWidget.__init__(self)
self.element = element
#iskljucujemo polja za uvecanje i minimizaciju
self.setWindowFlags(self.windowFlags() & ~Qt.WindowMaximizeButtonHint & ~Qt.WindowMinimizeButtonHint)
#Podesavamo naslov
self.setWindowTitle(self.element.ime)
self.focusWidget()
#editor teksta
self.textEditor = QTextEdit()
self.textEditor.setText(self.element.data)
#dodajemo dugmad za primenu i odbacivanje promena
#i povezujemo ih sa odgovarajucim funkcijama
self.dugmeOk = QPushButton("Potvrdi")
self.dugmeOtkazi = QPushButton("Otkazi")
self.connect(self.dugmeOk,SIGNAL('clicked()'),self,SLOT('podesi()'))
self.connect(self.dugmeOtkazi,SIGNAL('clicked()'),self,SLOT('zatvori()'))
#formiramo raspored
raspored = QFormLayout()
raspored.addRow(self.textEditor)
raspored.addRow(self.dugmeOtkazi,self.dugmeOk)
self.setLayout(raspored)
def zatvori(self):
'''
Funkcija za dugme otkazi promene, vraca parametre liste na trenutno stanje aplikacije
'''
self.textEditor.clear()
self.textEditor.setText(self.element.data)
self.hide()
def podesi(self):
'''
Funkcija za dugme potvrdi promene, poziva akcije za izmenu jezika i izgleda
'''
self.element.data = self.textEditor.toPlainText()
self.hide()
def closeEvent(self, event):
self.zatvori()
示例4: MainWindow
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import clear [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
# QMainWindow.__init__(self)
super().__init__() # use super() to avoid explicit dependency on the base class name
# Note: must not pass the self reference to __init__ in this case!
self.resize(800, 600)
# Create the main content widget
mainWidget = QWidget(self)
self.setCentralWidget(mainWidget)
# Create a text component at the top area of the main widget
self.output = QTextEdit(mainWidget)
self.output.setReadOnly(True)
self.output.setLineWrapMode(QTextEdit.NoWrap);
# set the font
font = self.output.font()
font.setFamily("Courier")
font.setPointSize(10)
self.output.setFont(font)
# Set the background color
# self.output.setTextBackgroundColor(Qt.red) # Only sets the background color for the text itself, not for the whole widget
pal = self.output.palette()
pal.setColor(QPalette.Base, Qt.black)
self.output.setPalette(pal)
mainLayout = QVBoxLayout(mainWidget)
mainLayout.addWidget(self.output)
# Create buttons in a grid layout below the top area
buttonWidget = QWidget(mainWidget)
self.buttonLayout = QGridLayout(buttonWidget)
mainLayout.addWidget(buttonWidget)
# Add some buttons to execute python code
self.row = 0
self.column = 0
self.addButton("Clear console", lambda : self.output.clear())
self.newRow()
# Add buttons for all the examples - attention: do not make "examples"
# a local variable - otherwise, the Examples object would be destroyed
# at the end of __init__ !!!
self.examples = samplePackage.SampleModule.Examples(self)
for example in self.examples.getExamples():
if example is None:
self.newRow()
else:
self.addButton(example.label, example.function)
# In a Python program, sys.excepthook is called just before the program exits.
# So we can catch all fatal, uncaught exceptions and log them.
# NOTE: we must be sure not to set the excepthook BEFORE we an actually
# log something!!
sys.excepthook = self.logException
self.writelnColor(Qt.magenta,
"Python version: {0}.{1}.{2} ({3})".format(
sys.version_info[0],
sys.version_info[1],
sys.version_info[2],
sys.version_info[3]))
self.writelnColor(Qt.magenta,
"Qt version : {0}".format(qVersion()))
def logException(self, exctype, value, tb):
self.writelnColor(Qt.red,
("\nFATAL ERROR: Uncaught exception\n"
" {}: {}\n"
"{}\n".format(exctype.__name__, value, ''.join(traceback.format_tb(tb)))) )
def addButton(self, label, function):
theButton = QPushButton(label)
theButton.clicked.connect(function)
self.buttonLayout.addWidget(theButton, self.row, self.column)
self.column += 1
def newRow(self):
self.row += 1
self.column = 0
def writeColor(self, color, *text):
theText = ' '.join(map(str, text))
self.output.setTextColor(color)
# Note: append() adds a new paragraph!
#self.output.append(theText)
self.output.textCursor().movePosition(QTextCursor.End)
self.output.insertPlainText(theText)
# scroll console window to bottom
sb = self.output.verticalScrollBar()
sb.setValue(sb.maximum())
#.........这里部分代码省略.........
示例5: TransferPanel
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import clear [as 别名]
class TransferPanel(QWidget):
'''
Transfer Panel
This Panel is the main dialog box for the Dive Computer Transfer GUI
'''
def __init__(self, parent=None):
super(TransferPanel, self).__init__(parent)
self._logbook = None
self._logbookName = 'None'
self._logbookPath = None
self._createLayout()
self._readSettings()
self.setWindowTitle(self.tr('DC Transfer - %s') % self._logbookName)
def _createLayout(self):
'Create the Widget Layout'
self._txtLogbook = QLineEdit()
self._txtLogbook.setReadOnly(True)
self._lblLogbook = QLabel(self.tr('&Logbook File:'))
self._lblLogbook.setBuddy(self._txtLogbook)
self._btnBrowse = QPushButton('...')
self._btnBrowse.clicked.connect(self._btnBrowseClicked)
self._btnBrowse.setStyleSheet('QPushButton { min-width: 24px; max-width: 24px; }')
self._btnBrowse.setToolTip(self.tr('Browse for a Logbook'))
self._cbxComputer = QComboBox()
self._lblComputer = QLabel(self.tr('Dive &Computer:'))
self._lblComputer.setBuddy(self._cbxComputer)
self._btnAddComputer = QPushButton(QPixmap(':/icons/list-add.png'), self.tr(''))
self._btnAddComputer.setStyleSheet('QPushButton { min-width: 24px; min-height: 24; max-width: 24px; max-height: 24; }')
self._btnAddComputer.clicked.connect(self._btnAddComputerClicked)
self._btnRemoveComputer = QPushButton(QPixmap(':/icons/list-remove.png'), self.tr(''))
self._btnRemoveComputer.setStyleSheet('QPushButton { min-width: 24px; min-height: 24; max-width: 24px; max-height: 24; }')
self._btnRemoveComputer.clicked.connect(self._btnRemoveComputerClicked)
hbox = QHBoxLayout()
hbox.addWidget(self._btnAddComputer)
hbox.addWidget(self._btnRemoveComputer)
gbox = QGridLayout()
gbox.addWidget(self._lblLogbook, 0, 0)
gbox.addWidget(self._txtLogbook, 0, 1)
gbox.addWidget(self._btnBrowse, 0, 2)
gbox.addWidget(self._lblComputer, 1, 0)
gbox.addWidget(self._cbxComputer, 1, 1)
gbox.addLayout(hbox, 1, 2)
gbox.setColumnStretch(1, 1)
self._pbTransfer = QProgressBar()
self._pbTransfer.reset()
self._txtStatus = QTextEdit()
self._txtStatus.setReadOnly(True)
self._btnTransfer = QPushButton(self.tr('&Transfer Dives'))
self._btnTransfer.clicked.connect(self._btnTransferClicked)
self._btnExit = QPushButton(self.tr('E&xit'))
self._btnExit.clicked.connect(self.close)
hbox = QHBoxLayout()
hbox.addWidget(self._btnTransfer)
hbox.addStretch()
hbox.addWidget(self._btnExit)
vbox = QVBoxLayout()
vbox.addLayout(gbox)
vbox.addWidget(self._pbTransfer)
vbox.addWidget(self._txtStatus)
vbox.addLayout(hbox)
self.setLayout(vbox)
def _closeLogbook(self):
'Close the current Logbook'
if self._logbook is None:
return
self._logbook = None
self._logbookName = 'None'
self._logbookPath = None
self._txtLogbook.clear()
self._cbxComputer.setModel(None)
self._writeSettings()
self.setWindowTitle(self.tr('DC Transfer - %s') % self._logbookName)
def _openLogbook(self, path):
'Open an existing Logbook'
if self._logbook is not None:
self._closeLogbook()
if not os.path.exists(path):
QMessageBox.critical(self, self.tr('Missing Logbook'),
self.tr('Logbook File "%s" does not exist.') % path)
#.........这里部分代码省略.........
示例6: MainWindow
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import clear [as 别名]
#.........这里部分代码省略.........
##### Edit Menu #######################################################
a['edit-cut'] = QAction("Cu&t", self, shortcut=QKeySequence.Cut,
triggered=self.editor.cut)
a['edit-copy'] = QAction("&Copy", self, shortcut=QKeySequence.Copy,
triggered=self.editor.copy)
a['edit-paste'] = QAction("&Paste", self, shortcut=QKeySequence.Paste,
triggered=self.editor.paste)
a['edit-cut'].setEnabled(False)
a['edit-copy'].setEnabled(False)
self.editor.copyAvailable.connect(a['edit-cut'].setEnabled)
self.editor.copyAvailable.connect(a['edit-copy'].setEnabled)
##### Tool Menu #######################################################
# This is the fun part.
a['addon-manager'] = QAction("&Add-ons", self, shortcut="Ctrl+Shift+A",
statusTip="Display the Add-ons manager.",
triggered=addons.show)
a['view-refresh'] = QAction("&Reload Style", self,
shortcut="Ctrl+Shift+R",
statusTip="Reload the style.",
triggered=style.reload)
##### Menus! ##############################################################
def init_menus(self):
self.menuBar().clear()
a = self.actions
file = self.menuBar().addMenu("&File")
file.addAction(a['document-new'])
file.addAction(a['document-open'])
file.addAction(a['document-save'])
file.addSeparator()
file.addAction(a['application-exit'])
edit = self.menuBar().addMenu("&Edit")
edit.addAction(a['edit-cut'])
edit.addAction(a['edit-copy'])
edit.addAction(a['edit-paste'])
tools = self.menuBar().addMenu("&Tools")
tools.addAction(a['addon-manager'])
tools.addAction(a['view-refresh'])
##### Explosions! #########################################################
##### Toolbars! ###########################################################
def init_toolbars(self):
a = self.actions
file = self.addToolBar("File")
file.setObjectName('filebar')
file.addAction(a['document-new'])
file.addAction(a['document-open'])
file.addAction(a['document-save'])
edit = self.addToolBar("Edit")
示例7: qNotebook
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import clear [as 别名]
class qNotebook(QVBoxLayout):
def __init__(self):
QVBoxLayout.__init__(self)
self._teditor = QTextEdit()
self._teditor.setMinimumWidth(500)
self._teditor.setStyleSheet("font: 12pt \"Courier\";")
button_layout = QHBoxLayout()
self.addLayout(button_layout)
self.clear_but = qmy_button(button_layout, self.clear_all, "clear")
self.copy_but = qmy_button(button_layout, self._teditor.copy, "copy")
qmy_button(button_layout, self._teditor.selectAll, "select all")
qmy_button(button_layout, self._teditor.undo, "undo")
qmy_button(button_layout, self._teditor.redo, "redo")
search_button = qButtonWithArgumentsClass("search", self.search_for_text, {"search_text": ""})
button_layout.addWidget(search_button)
qmy_button(button_layout, self.save_as_html, "save notebook")
self.addWidget(self._teditor)
self._teditor.document().setUndoRedoEnabled(True)
self.image_counter = 0
self.image_dict = {}
self.image_data_dict = {}
def append_text(self, text):
self._teditor.append(str(text))
def search_for_text(self, search_text = " "):
self._teditor.find(search_text)
def clear_all(self):
self._teditor.clear()
self.image_dict = {}
self.image_counter = 0
# newdoc = QTextDocument()
# self._teditor.setDocument(newdoc)
def append_image(self, fig=None):
#This assumes that an image is there waiting to be saved from matplotlib
self.imgdata = StringIO.StringIO()
if fig is None:
pyplot.savefig(self.imgdata, transparent = False, format = img_format)
else:
fig.savefig(self.imgdata, transparent = False, format = img_format)
self.abuffer = QBuffer()
self.abuffer.open(QBuffer.ReadWrite)
self.abuffer.write(self.imgdata.getvalue())
self.abuffer.close()
self.abuffer.open(QBuffer.ReadOnly)
iReader = QImageReader(self.abuffer, img_format )
the_image = iReader.read()
# the_image = the_image0.scaledToWidth(figure_width)
# save the image in a file
imageFileName = "image" + str(self.image_counter) + "." + img_format
self.image_data_dict[imageFileName] = self.imgdata
self.image_counter +=1
imageFormat = QTextImageFormat()
imageFormat.setName(imageFileName)
imageFormat.setWidth(image_width)
self.image_dict[imageFileName] = the_image
#insert the image in the text document
text_doc = self._teditor.document()
text_doc.addResource(QTextDocument.ImageResource, QUrl(imageFileName), the_image)
cursor = self._teditor.textCursor()
cursor.movePosition(QTextCursor.End)
cursor.insertImage(imageFormat)
def add_image_data_resource(self, imgdata, imageFileName):
self.abuffer = QBuffer()
self.abuffer.open(QBuffer.ReadWrite)
self.abuffer.write(imgdata.getvalue())
self.abuffer.close()
self.abuffer.open(QBuffer.ReadOnly)
iReader = QImageReader(self.abuffer, img_format )
the_image = iReader.read()
# the_image = the_image0.scaledToWidth(figure_width)
# save the image in a file
# imageFileName = "image" + str(self.image_counter) + "." + img_format
self.image_data_dict[imageFileName] = imgdata
# self.image_counter +=1
imageFormat = QTextImageFormat()
imageFormat.setName(imageFileName)
imageFormat.setWidth(image_width)
self.image_dict[imageFileName] = the_image
#insert the image in the text document
text_doc = self._teditor.document()
text_doc.addResource(QTextDocument.ImageResource, QUrl(imageFileName), the_image)
def append_html_table_from_array(self, a, header_rows=0, precision = 3, caption = None, cmap = None):
nrows = len(a)
ncols = len(a[0])
#.........这里部分代码省略.........