Esempio n. 1
0
    def delete_from_disk(self):
        """
        Deletes the bookmark from the disk.
        """

        bm = __stored_bookmarks__()
        del bm[self.__bookmark_name__]
        userkeys.set(bm, __key__)
Esempio n. 2
0
def __reload_descriptors__():
    names = list(store.providers.keys())
    try:
        cached = uk.get("__watch_descriptors__")
    except KeyError:
        cached = []

    if names != cached:
        uk.set(names, "__watch_descriptors__")
        __PyComplication__.reloadDescriptors()
Esempio n. 3
0
    def __init__(self, name: str = None, path: str = None):

        warnings.warn(deprecation_msg, UserWarning)

        check(name, "name", [str, None])
        check(path, "path", [str, None])

        self.__bookmark_name__ = name

        if self.__type__ is None:
            raise NotImplementedError(
                "Initialized an instance of StoredBookmark. Use FileBookmark or FolderBookmark instead."
            )

        if name is not None:
            try:
                value = __stored_bookmarks__()[name]
                data = NSData.alloc().initWithBase64EncodedString(value, options=0)
                url = NSURL.URLByResolvingBookmarkData(
                    data,
                    options=0,
                    relativeToURL=None,
                    bookmarkDataIsStale=None,
                    error=None,
                )
                if url is not None:
                    url.startAccessingSecurityScopedResource()
                    self.path = str(url.path)
                    return
                return
            except KeyError:
                pass

        if path is None:
            picker = sharing.FilePicker()
            picker.file_types = [self.__type__]
            picker.allows_multiple_selection = False
            sharing.pick_documents(picker)
            try:
                self.path = sharing.picked_files()[0]
            except IndexError:
                raise ValueError("No file selected")
        else:
            self.path = os.path.abspath(path)

        if name is None:
            return

        bookmark = NSURL.fileURLWithPath(self.path).bookmarkDataWithOptions(
            1024, includingResourceValuesForKeys=[], relativeToURL=None, error=None
        )
        bookmark = bookmark.base64EncodedStringWithOptions(0)
        bookmarks = __stored_bookmarks__()
        bookmarks[name] = str(bookmark)
        userkeys.set(bookmarks, __key__)
Esempio n. 4
0

NSURL = ObjCClass("NSURL")
NSData = ObjCClass("NSData")

__key__ = "__pyto_bookmarks__"


def __stored_bookmarks__():
    return userkeys.get(__key__)


try:
    __stored_bookmarks__()
except KeyError:
    userkeys.set({}, __key__)


class StoredBookmark:
    """
    A bookmark for storing a file path in the disk.

    The bookmark is identified by its name. When a bookmark is initialized with a name for the first time, a file picker will appear.

    This is a base class and should not be directly used.
    Instead, use :class:`~bookmarks.FileBookmark` or :class:`~bookmarks.FolderBookmark`.
    """

    __type__ = None

    __bookmark_name__ = None