Exemple #1
0
def storePixmap(pixmap, filetype='PNG'):
    import_qt(globals())

    arr = QtCore.QByteArray()
    buf = QtCore.QBuffer()
    buf.setBuffer(arr)
    buf.open(QtCore.QBuffer.WriteOnly)
    pixmap.save(buf, filetype)
    buf.close()

    return binascii.b2a_base64(nativestring(arr))
Exemple #2
0
    def restoreValue(self, xelem):
        """
        Stores the value for the inptued instance to the given xml element.
        
        :param      xelem | <xml.etree.Element>
        
        :return     <variant>
        """
        typ = xelem.get('type')

        if typ == 'color':
            return QtGui.QColor(xelem.text)

        elif typ == 'point':
            return QtCore.QPoint(*map(int, xelem.text.split(',')))

        elif typ == 'pointf':
            return QtCore.QPointF(*map(float, xelem.text.split(',')))

        elif typ == 'rect':
            return QtCore.QRectF(*map(int, xelem.text.split(',')))

        elif typ == 'rectf':
            return QtCore.QRectF(*map(float, xelem.text.split(',')))

        elif typ == 'bytea':
            return QtCore.QByteArray(cPickle.loads(xelem.text))

        elif typ == 'pickle':
            return cPickle.loads(xelem.text)

        elif typ == 'xml':
            return xelem[0]

        elif typ in ('str', 'unicode'):
            return xelem.text

        else:
            try:
                return eval('{0}({1})'.format(typ, xelem.text))
            except:
                return None