Example #1
0
def image_and_format_from_data(data):
    ' Create an image object from the specified data which should be a bytsestring and also return the format of the image '
    ba = QByteArray(data)
    buf = QBuffer(ba)
    buf.open(QBuffer.ReadOnly)
    r = QImageReader(buf)
    fmt = bytes(r.format()).decode('utf-8')
    return r.read(), fmt
Example #2
0
def verify_theme(report):
    must_use_qt()
    report.bad = bad = {}
    for name, path in iteritems(report.name_map):
        reader = QImageReader(os.path.join(report.path, path))
        img = reader.read()
        if img.isNull():
            bad[name] = reader.errorString()
    return bool(bad)
Example #3
0
    def _insert_image(self):
        filedialog = QFileDialog(self)
        filedialog.setOption(QFileDialog.DontUseNativeDialog)
        filedialog.setDefaultSuffix("*.jpg")
        filedialog.setDirectory(self._cfg.get(
            "TextEditor/LastPath", ".", system=True))

        type_files = (
            self.tr("JPEG (*.jpg)"),
            self.tr("GIF (*.gif)"),
            self.tr("PNG (*.png)"),
            self.tr("BMP (*.bmp)"),
            self.tr("All files (*)"),
        )
        filedialog.setNameFilters(type_files)

        if filedialog.exec_():
            path = filedialog.selectedFiles()[0]
            fmt = path.split(".")[-1]
            image = QImageReader(path).read()
            self._doc.ins_image(image, fmt, image.width(), image.height())
            self._cfg["SYSTEM", "TextEditor/LastPath"] = (
                os.path.dirname(path))