本文整理汇总了Python中PyQt4.QtCore.QByteArray.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QByteArray.clear方法的具体用法?Python QByteArray.clear怎么用?Python QByteArray.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QByteArray
的用法示例。
在下文中一共展示了QByteArray.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Window
# 需要导入模块: from PyQt4.QtCore import QByteArray [as 别名]
# 或者: from PyQt4.QtCore.QByteArray import clear [as 别名]
class Window(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
format = QAudioFormat()
format.setChannels(1)
format.setFrequency(22050)
format.setSampleSize(16)
format.setCodec("audio/pcm")
format.setByteOrder(QAudioFormat.LittleEndian)
format.setSampleType(QAudioFormat.SignedInt)
self.output = QAudioOutput(format, self)
self.frequency = 440
self.volume = 0
self.buffer = QBuffer()
self.data = QByteArray()
self.deviceLineEdit = QLineEdit()
self.deviceLineEdit.setReadOnly(True)
self.deviceLineEdit.setText(QAudioDeviceInfo.defaultOutputDevice().deviceName())
self.pitchSlider = QSlider(Qt.Horizontal)
self.pitchSlider.setMaximum(100)
self.volumeSlider = QSlider(Qt.Horizontal)
self.volumeSlider.setMaximum(32767)
self.volumeSlider.setPageStep(1024)
self.playButton = QPushButton(self.tr("&Play"))
self.pitchSlider.valueChanged.connect(self.changeFrequency)
self.volumeSlider.valueChanged.connect(self.changeVolume)
self.playButton.clicked.connect(self.play)
formLayout = QFormLayout()
formLayout.addRow(self.tr("Device:"), self.deviceLineEdit)
formLayout.addRow(self.tr("P&itch:"), self.pitchSlider)
formLayout.addRow(self.tr("&Volume:"), self.volumeSlider)
buttonLayout = QVBoxLayout()
buttonLayout.addWidget(self.playButton)
buttonLayout.addStretch()
horizontalLayout = QHBoxLayout(self)
horizontalLayout.addLayout(formLayout)
horizontalLayout.addLayout(buttonLayout)
def changeFrequency(self, value):
self.frequency = 440 + (value * 2)
def play(self):
if self.output.state() == QAudio.ActiveState:
self.output.stop()
if self.buffer.isOpen():
self.buffer.close()
self.createData()
self.buffer.setData(self.data)
self.buffer.open(QIODevice.ReadOnly)
self.buffer.seek(0)
self.output.start(self.buffer)
def changeVolume(self, value):
self.volume = value
def createData(self):
# Create 2 seconds of data with 22050 samples per second, each sample
# being 16 bits (2 bytes).
self.data.clear()
for i in xrange(2 * 22050):
t = i / 22050.0
value = int(self.volume * sin(2 * pi * self.frequency * t))
self.data.append(struct.pack("<h", value))
示例2: Level
# 需要导入模块: from PyQt4.QtCore import QByteArray [as 别名]
# 或者: from PyQt4.QtCore.QByteArray import clear [as 别名]
#.........这里部分代码省略.........
self.view.setMaximumSize(self.screenSize[0], self.screenSize[1])
self.scene.setSceneRect(0, 0, self.screenSize[0], self.screenSize[1])
def offerSave(self):
if (Dirty and QMessageBox.question(self,
"Designer - Unsaved Changes",
"Save unsaved changes?",
QMessageBox.Yes|QMessageBox.No) ==
QMessageBox.Yes):
self.save()
def position(self):
point = self.mapFromGlobal(QCursor.pos())
if not self.view.geometry().contains(point):
coord = random.randint(36, 144)
point = QPoint(coord, coord)
else:
if point == self.prevPoint:
point += QPoint(self.addOffset, self.addOffset)
self.addOffset += 5
else:
self.addOffset = 5
self.prevPoint = point
return self.view.mapToScene(point)
def selectedItem(self):
items = self.scene.selectedItems()
if len(items) == 1:
return items[0]
return None
def current(self,item):
self.scene.clearSelection()
sceneItems = self.scene.items()
for items in sceneItems:
if(items != item):
item.setSelected(False)
if(item.isConnected()):
self.propertyBar.disconnectText(item)
item.setConnected(False)
self.currentItem = item
self.currentItem.setConnected(True)
self.currentItem.setSelected(True)
self.propertyBar.connectText(self.currentItem)
self.propertyBar.initText(self.currentItem)
def addText(self):
item = TextItem("SomeText", self.position())
self.connect(item, SIGNAL("current"),self.current)
self.connect(item, SIGNAL("copy"),self.copy)
self.connect(item, SIGNAL("cut"),self.cut)
self.connect(item, SIGNAL("paste"),self.paste)
self.connect(item, SIGNAL("delete"),self.delete)
#self.current(item)
self.scene.addItem(item)
def copy(self):
item = self.selectedItem()
if item is None:
return
self.copiedItem.clear()
self.pasteOffset = 5
stream = QDataStream(self.copiedItem, QIODevice.WriteOnly)
示例3: ServicoScreenshot
# 需要导入模块: from PyQt4.QtCore import QByteArray [as 别名]
# 或者: from PyQt4.QtCore.QByteArray import clear [as 别名]
class ServicoScreenshot(ServicoInformacao):
telaRecebida = pyqtSignal(str, QPixmap)
ENVIANDO_PARTE_IMAGEM = 40
ENVIANDO_FINAL_IMAGEM = 41
PARTE_RECEBIDA = 42
def __init__(self, portaReceber=4002, portaResponder=4003, parent=None):
super().__init__(portaReceber=portaReceber, portaResponder=portaResponder, parent=parent)
self._arrayEnviar = QByteArray()
self._recebendoPartesImagem = []
def _receberInformacaoTipoValor(self, de, tipo, valor):
# Recebendo
print(tipo)
if tipo == ServicoScreenshot.ENVIANDO_PARTE_IMAGEM:
self.setPara(de)
self._arrayEnviar.append(valor)
print("ENVIANDO RECEBIDA")
self.enviarInformacaoTipoValor(ServicoScreenshot.PARTE_RECEBIDA, None)
elif tipo == ServicoScreenshot.ENVIANDO_FINAL_IMAGEM:
imagem = self._imagemByteArray(self._arrayEnviar)
self._arrayEnviar.clear()
self.telaRecebida.emit(de, imagem)
# Enviando
elif tipo == ServicoScreenshot.PARTE_RECEBIDA:
self._enviarParte()
super()._receberInformacaoTipoValor(de, tipo, valor)
def _imagemByteArray(self, array):
data = QDataStream(array)
image = QPixmap()
data >> image
return image
def _dividirArray(self, array, tam=30000):
lista = []
partes = int(array.length() / tam)
for i in range(partes):
lista.append(array.mid(tam * i, tam))
if tam * partes != array.length():
lista.append(array.mid(tam * partes))
return lista
def _enviarParte(self):
self.enviarInformacaoTipoValor(ServicoScreenshot.ENVIANDO_PARTE_IMAGEM, self._recebendoPartesImagem.pop(0))
print("PARTE")
if not self._recebendoPartesImagem:
print("FINAL")
self.enviarInformacaoTipoValor(ServicoScreenshot.ENVIANDO_FINAL_IMAGEM, None)
def enviarScreenshot(self):
self.enviarImagem(QPixmap.grabWindow(QApplication.desktop().winId()))
def enviarImagem(self, imagem):
array = QByteArray()
data = QDataStream(array, QIODevice.WriteOnly)
data << imagem
self._recebendoPartesImagem = self._dividirArray(array)
self._enviarParte()