Beispiel #1
0
    def make_bookmark(self, spath):
        if self.written:
            return

        if not os.path.exists(self.config_path):
            #do not write shortcuts if file was not created by Qt5 himself
            return

        url = pathlib.Path(spath).as_uri()

        settings_qt5 = QSettings(self.config_path, QSettings.IniFormat)
        if not settings_qt5.isWritable():
            return

        shortcuts = ray.get_list_in_settings(settings_qt5,
                                             'FileDialog/shortcuts')

        for sc in shortcuts:
            sc_url = QUrl(sc)
            if sc_url.isLocalFile() and sc_url.toLocalFile() == spath:
                return

        shortcuts.append(url)

        settings_qt5.setValue('FileDialog/shortcuts', shortcuts)
        settings_qt5.sync()
        self.written = True
Beispiel #2
0
    def removeBookmark(self, spath):
        if not self.written:
            return

        if not os.path.exists(self.config_path):
            self.written = False
            return

        url = pathlib.Path(spath).as_uri()

        settings_qt5 = QSettings(self.config_path, QSettings.IniFormat)
        shortcuts = ray.getListInSettings(settings_qt5, 'FileDialog/shortcuts')

        for sc in shortcuts:
            sc_url = QUrl(sc)
            if sc_url.isLocalFile() and sc_url.toLocalFile() == spath:
                shortcuts.remove(sc)
                break
        else:
            self.written = False
            return

        settings_qt5.setValue('FileDialog/shortcuts', shortcuts)
        settings_qt5.sync()
        self.written = False
Beispiel #3
0
    def _read_m3u_or_similar(file):
        item_to_remove = FileItem(file)
        item_list = [item_to_remove]
        # Try to read the file:
        try:
            item_to_remove.status = EncoderStatus.REMOVE
            with open(file, "r") as reader:
                for line in reader:
                    line = line.strip()
                    if not line.startswith("#"):
                        url = QUrl(line)
                        if url.isLocalFile() and os.path.exists(line):
                            # TODO: check with file_dir + line
                            item_list.append(FileItem(line))
                        elif url.authority() != "":
                            item_list.append(FileItem(file=file, url=line))
        except (UnicodeDecodeError, OSError):
            TransCoda.logger.warn(
                f"Could not open/read file:{file}. Transcoda will skip this file"
            )
            item_to_remove.status = EncoderStatus.ERROR
            item_list = [item_to_remove]
            return item_list

        return item_list
Beispiel #4
0
    def convert(self, pathToFile):
        pathToFile = QUrl(pathToFile).toLocalFile()
        images = []
        for i in self._listOfImg:
            url = QUrl()
            url.setUrl(i)

            if url.isLocalFile():
                img = Image.open(url.toLocalFile())
            else:
                img = Image.open(urlopen(i))

            if img.mode == "RGBA":
                img = img.convert('RGB')
            images.append(img)

        images.pop(0).save(pathToFile,
                           "PDF",
                           append_images=images,
                           save_all=True)
Beispiel #5
0
    def remove_bookmark(self, spath):
        if not self.written:
            return

        if not os.path.exists(self.config_path):
            self.written = False
            return

        url = pathlib.Path(spath).as_uri()

        settings_qt4 = QSettings(self.config_path, QSettings.IniFormat)
        if not settings_qt4.isWritable():
            self.written = False
            return

        data = settings_qt4.value('Qt/filedialog')
        stream = QDataStream(data, QIODevice.ReadOnly)

        magic = stream.readUInt32()
        version = stream.readUInt32()
        if not (magic == QFileDialogMagic and version == 3):
            self.written = False
            return

        split_states = stream.readBytes()

        bookmark_found = False
        bookmarks_len = stream.readUInt32()
        bookmarks = []
        for bm in range(bookmarks_len):
            qUrl = QUrl()
            stream >> qUrl

            if qUrl.isLocalFile() and qUrl.toLocalFile() == spath:
                bookmark_found = True
            else:
                bookmarks.append(qUrl)

        if not bookmark_found:
            self.written = False
            return

        history_len = stream.readUInt32()
        history = []
        for h in range(history_len):
            his = stream.readQString()
            history.append(his)

        current_dir = stream.readQString()
        header_data = stream.readBytes()
        view_mode = stream.readUInt32()

        #now rewrite bytes

        new_data = QByteArray()
        new_stream = QDataStream(new_data, QIODevice.WriteOnly)

        new_stream.writeUInt32(magic)
        new_stream.writeUInt32(3)
        new_stream.writeBytes(split_states)
        new_stream.writeUInt32(bookmarks_len-1)
        for bm in bookmarks:
            new_stream << bm

        qUrl = QUrl(url)
        new_stream << qUrl

        new_stream.writeQStringList(history)
        new_stream.writeQString(current_dir)
        new_stream.writeBytes(header_data)
        new_stream.writeUInt32(view_mode)

        settings_qt4.setValue('Qt/filedialog', new_data)
        settings_qt4.sync()

        self.written = False