Python PyQt4.QtCore 模块,QByteArray() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用PyQt4.QtCore.QByteArray()

项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def createDragData(self):
        if not self.selection: return
        start = self.selection[0]
        end = self.selection[-1]
        if start == end:
            self.waveobj_list[start].preview_rect.setSelected(True)
        self.drag = QtGui.QDrag(self)
        data = MimeData()
        data.setData('audio/waves', QtCore.QByteArray('{}:{}'.format(start, end)))
        data.setReferenceData(self.main)
        pixmap = QtGui.QPixmap(int(self.viewport().rect().width() / 64. * (end - start + 1)), self.height())
        pixmap.fill(QtGui.QColor(192, 192, 192, 128))
        qp = QtGui.QPainter(pixmap)
        qp.setRenderHints(qp.Antialiasing)
        x = self.mapFromScene(self.waveobj_list[start].preview_rect.pos()).x()
        width = self.mapFromScene(self.waveobj_list[end].preview_rect.pos()).x() + self.mapFromScene(self.waveobj_list[end].preview_rect.boundingRect().topRight()).x() - x
        self.render(qp, source=QtCore.QRect(x, self.wavegroup.boundingRect().y(), width, self.mapToScene(self.viewport().rect()).boundingRect().height()), mode=QtCore.Qt.IgnoreAspectRatio)
        qp.end()
        self.drag.setPixmap(pixmap)
        self.drag.setMimeData(data)
        self.drag.exec_()
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def __init__(self, waveobj_list, *args, **kwargs):
        QtCore.QBuffer.__init__(self, *args, **kwargs)
        self.waveobj_list = waveobj_list

        self.single_data_list = [QtCore.QByteArray() for b in xrange(64)]
        self.multi_data = QtCore.QByteArray()
        self.multiplier = 6
        self.ratio = 1. / 44100 * 128 * self.multiplier * 1000000

        for wave_obj in waveobj_list:
            wave_obj.changed.connect(self.update)
            wave_obj.selected.connect(self.setCurrentWave)
            self.update(wave_obj)

        self.currentWave = 0
        self.current_data = self.single_data_list[0]
        self.start = 0
        self.delta = 256
        self.full_mode = False
        self.open(QtCore.QIODevice.ReadOnly)
项目:qgis-shapetools-plugin    作者:NationalSecurityAgency    | 项目源码 | 文件源码
def __init__(self, iface, parent):
        super(GeodesicMeasureDialog, self).__init__(parent)
        self.setupUi(self)
        self.iface = iface
        self.canvas = iface.mapCanvas()
        settings = QSettings()

        self.restoreGeometry(settings.value("ShapeTools/MeasureDialogGeometry",
                                        QByteArray(), type=QByteArray))
        self.closeButton.clicked.connect(self.closeDialog)
        self.newButton.clicked.connect(self.newDialog)

        self.unitsComboBox.addItems(UNITS)

        self.tableWidget.setColumnCount(3)
        self.tableWidget.setSortingEnabled(False)
        self.tableWidget.setHorizontalHeaderLabels(['Heading To', 'Heading From', 'Distance'])

        self.unitsComboBox.activated.connect(self.unitsChanged)

        self.capturedPoints = []
        self.distances = []
        self.geod = Geodesic.WGS84
        self.activeMeasuring = True
        self.unitsChanged()
        self.currentDistance = 0.0

        color = QColor(222, 167, 67, 150)
        self.pointRb = QgsRubberBand(self.canvas, QGis.Point)
        self.pointRb.setColor(color)
        self.pointRb.setIconSize(10)
        self.lineRb = QgsRubberBand(self.canvas, QGis.Line)
        self.lineRb.setColor(color)
        self.lineRb.setWidth(3)
        self.tempRb = QgsRubberBand(self.canvas, QGis.Line)
        self.tempRb.setColor(color)
        self.tempRb.setWidth(3)
项目:quartz-browser    作者:ksharindam    | 项目源码 | 文件源码
def __init__(self, networkmanager):
        super(Download, self).__init__(networkmanager)
        self.downloadBuffer = QtCore.QByteArray()
        self.nam = networkmanager
        self.totalsize = 'Unknown'
        self.loadedsize = '- - -'
        self.progress = '- - -'
        self.noerror = True
        self.download_aborted = False
项目:quartz-browser    作者:ksharindam    | 项目源码 | 文件源码
def __init__(self, networkmanager, download_list, useragent=False):
        ''' download_list is like ...
        [['/home/user/file1.txt', 'http://example1.com'], ['/home/user/file2.txt', 'http://example2.com']]'''
        super(DirectDownload, self).__init__(networkmanager)
        self.current_index = 0
        self.downloadBuffer = QtCore.QByteArray()
        self.download_list = download_list
        self.useragent = unicode(useragent)
        self.networkmanager = networkmanager
项目:quartz-browser    作者:ksharindam    | 项目源码 | 文件源码
def importCookies(self):
        """ Window object must contain QSetting object 'self.settings' before calling this"""
        settings = QtCore.QSettings('quartz-browser', 'cookies', self)
        cookiesValue = settings.value("Cookies", QtCore.QByteArray()).toByteArray()
        cookiesList = QtNetwork.QNetworkCookie.parseCookies(cookiesValue)
        self.setAllCookies(cookiesList)
项目:quartz-browser    作者:ksharindam    | 项目源码 | 文件源码
def exportCookies(self):
        cookiesArray = QtCore.QByteArray()
        cookieList = self.allCookies()
        for cookie in cookieList:
            cookiesArray.append( cookie.toRawForm() + "\n" )
        settings = QtCore.QSettings('quartz-browser', 'cookies', self)
        settings.setValue("Cookies", cookiesArray)
项目:Comictagger    作者:dickloraine    | 项目源码 | 文件源码
def fetch( self, url, user_data=None, blocking=False  ):
        """
        If called with blocking=True, this will block until the image is 
        fetched.

        If called with blocking=False, this will run the fetch in the 
        background, and emit a signal when done
        """

        self.user_data = user_data
        self.fetched_url = url

        # first look in the DB
        image_data = self.get_image_from_cache( url )

        if blocking:
            if image_data is None:
                try:
                    image_data = urllib.urlopen(url).read()
                except Exception as e:
                    print e
                    raise ImageFetcherException("Network Error!")

            # save the image to the cache
            self.add_image_to_cache( self.fetched_url, image_data ) 
            return image_data

        else:

            # if we found it, just emit the signal asap
            if image_data is not None:
                self.fetchComplete.emit( QByteArray(image_data), self.user_data )
                return

            # didn't find it.  look online
            self.nam = QNetworkAccessManager()
            self.nam.finished.connect(self.finishRequest)
            self.nam.get(QNetworkRequest(QUrl(url)))

            #we'll get called back when done...
项目:Comictagger    作者:dickloraine    | 项目源码 | 文件源码
def finishRequest(self, reply):

        # read in the image data
        image_data = reply.readAll()

        # save the image to the cache
        self.add_image_to_cache( self.fetched_url, image_data ) 

        self.fetchComplete.emit( QByteArray(image_data), self.user_data )
项目:pyDashboard    作者:jtsmith2    | 项目源码 | 文件源码
def wxfinished(self):
        if self.wxreply.error() != QNetworkReply.NoError:
            #print "get radar error "+self.myname+":"+str(self.wxreply.error())
            self.lastwx = 0
            return
        #print "radar map received:"+self.myname+":"+time.ctime()
        self.wxmovie.stop()
        self.wxdata = QtCore.QByteArray(self.wxreply.readAll())
        self.wxbuff = QtCore.QBuffer(self.wxdata)
        self.wxbuff.open(QtCore.QIODevice.ReadOnly)
        mov = QMovie(self.wxbuff, 'GIF')
        #print "radar map frame count:"+self.myname+":"+str(mov.frameCount())
        if mov.frameCount() > 2:
            self.lastwx = time.time()
        else:
            # radar image retreval failed
            self.lastwx = 0
            # retry in 5 seconds
            QtCore.QTimer.singleShot(5*1000, self.getwx)
            return
        self.wxmovie = mov
        if self.satellite:
            self.setMovie( self.wxmovie)
        else:
            self.wwx.setMovie( self.wxmovie)
        if self.parent().isVisible():
            self.wxmovie.start()
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def play_toggle(self, state):
        if not self.stream: return
        if not state:
            self.output.stop()
            self.pause_btn.setEnabled(False)
            self.pause_btn.setChecked(False)
            if self.output:
                try:
                    self.output.deleteLater()
                except:
                    pass
            return
        format = QtMultimedia.QAudioFormat()
        format.setChannels(self.stream.getnchannels())
        format.setFrequency(self.stream.getframerate())
        format.setSampleSize(self.stream.getsampwidth()*8)
        format.setCodec("audio/pcm")
        format.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
        format.setSampleType(QtMultimedia.QAudioFormat.SignedInt)
        if self.output:
            try:
                self.output.deleteLater()
            except:
                pass
        self.output = QtMultimedia.QAudioOutput(format, self)
        self.output.stateChanged.connect(self.stop)
        buffer = QtCore.QBuffer(self)
        data = QtCore.QByteArray()
        self.stream.rewind()
        data.append(self.stream.readframes(float('inf')))
        buffer.setData(data)
        buffer.open(QtCore.QIODevice.ReadOnly)
        buffer.seek(0)
        self.output.start(buffer)
        self.pause_btn.setEnabled(True)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def update(self, wave_obj):
        data = QtCore.QByteArray()
        for s in range(128):
            data.append(struct.pack('<h', int(wave_obj.values[s] * .03125)))
        index = wave_obj.index
        self.single_data_list[index].replace(0, 65536, data * 256)
        self.multi_data.replace(index * 256 * self.multiplier, 256 * self.multiplier, str(data) * self.multiplier)
#        self.multi_data.replace((126 + index) * 256 * self.multiplier, 256 * self.multiplier, str(data) * self.multiplier)
#        if index not in (0, 63):
#            self.multi_data.replace((126 - index) * 256 * self.multiplier, 256 * self.multiplier, str(data) * self.multiplier)
#            self.multi_data.replace((252 - index) * 256 * self.multiplier, 256 * self.multiplier, str(data) * self.multiplier)
        self.multi_data.replace((127 - index) * 256 * self.multiplier, 256 * self.multiplier, str(data) * self.multiplier)
        self.multi_data.replace((128 + index) * 256 * self.multiplier, 256 * self.multiplier, str(data) * self.multiplier)
        self.multi_data.replace((255 - index) * 256 * self.multiplier, 256 * self.multiplier, str(data) * self.multiplier)
项目:remotefreebox-gui    作者:MaximeCheramy    | 项目源码 | 文件源码
def __init__(self, url, label=None, btn=None):
        QNetworkAccessManager.__init__(self)
        self.messageBuffer = QByteArray()
        self.label = label
        self.btn = btn
        self.frmt = "PNG" if url.rsplit('.', 1)[1] == 'png' else "JPG"
        request = QNetworkRequest(QUrl(url))
        self.reply = self.get(request)
        self.reply.finished.connect(self.slotFinished)
        self.reply.readyRead.connect(self.slotReadData)
项目:motion-capture    作者:Vermeille    | 项目源码 | 文件源码
def blend(self, c):
        return QtCore.QByteArray('<?xml version="1.0" encoding="UTF-8" standalone="no"?>'+ self.root.blend(c))
项目:isogeo-plugin-qgis    作者:isogeo    | 项目源码 | 文件源码
def ask_for_token(self, c_id, c_secret):
        """Ask a token from Isogeo API authentification page.

        This send a POST request to Isogeo API with the user id and secret in
        its header. The API should return an access token
        """
        # check if API access are already set
        if self.api_id != 0 and self.api_secret != 0:
            logger.info("User_authentication function is trying "
                        "to get a token from the id/secret")
            self.request_status_clear = 1
            pass
        else:
            logger.error("No id/secret.")
            return 0

        # API token request
        headervalue = "Basic " + base64.b64encode(c_id + ":" + c_secret)
        data = urlencode({"grant_type": "client_credentials"})
        databyte = QByteArray()
        databyte.append(data)
        url = QUrl("https://id.api.isogeo.com/oauth/token")
        request = QNetworkRequest(url)
        request.setRawHeader("Authorization", headervalue)
        if self.request_status_clear:
            self.request_status_clear = 0
            token_reply = self.manager.post(request, databyte)
            token_reply.finished.connect(
                partial(self.handle_token, answer=token_reply))
            QgsMessageLog.logMessage("Authentication succeeded", "Isogeo")
        else:
            pass