예제 #1
0
def mainthread(func):
    """
    A decorator that makes a function run in synchronously on the main thread.

    Example:

    .. code-block:: python

       import mainthread
       from UIKit import UIApplication

       @mainthread.mainthread
       def run_in_background():
           app = UIApplication.sharedApplication
           app.beginBackgroundTaskWithExpirationHandler(None)

       run_in_background()
    """

    check(func, "func", [_func])

    def run(*args, **kwargs):
        import mainthread

        def _run():
            return func(*args, **kwargs)

        return mainthread.run_sync(_run)

    return run
예제 #2
0
def set_images(array: List[Image.Image]):

    _warning = "set_images() is deprecated in favor of set_image(), which now supports a list as a parameter."
    warnings.warn(_warning, DeprecationWarning)

    check(array, "array", [list, None])
    _set_images(array)
예제 #3
0
def set_strings(array: List[str]):

    _warning = "set_strings() is deprecated in favor of set_string(), which now supports a list as a parameter."
    warnings.warn(_warning, DeprecationWarning)

    check(array, "array", [list, None])

    general_pasteboard().strings = array
예제 #4
0
def run_sync(code):

    check(code, "code", [_func])

    def code_() -> None:
        code()

    __PyMainThread__.runSync(code_)
    sleep(0.1)
예제 #5
0
    def wait(self, delay: float):
        """
        Waits n seconds. Does the same thing as ``time.sleep``.

        :param delay: Seconds to wait.
        """

        check(delay, "delay", [float, int])

        sleep(delay)
예제 #6
0
def set_image(image: Image.Image):
    """
    Copy the given image to the pasteboard.

    :param image: The image to copy.
    """

    check(image, "image", [Image.Image, None])

    general_pasteboard().image = __ui_image_from_pil_image__(image)
예제 #7
0
def set_url(url: str):
    """
    Copy the given URL to the pasteboard.

    :param url: The string to copy as an URL.
    """

    check(url, "url", [str, None])

    general_pasteboard().URL = NSURL.alloc().initWithString(url)
예제 #8
0
def set_string(text: str):
    """
    Copy the given text to the pasteboard.

    :param text: The text to copy.
    """

    check(text, "text", [str, None])

    general_pasteboard().string = text
예제 #9
0
def set_strings(array: List[str]):
    """
    Copy the given strings to the pasteboard.

    :param array: A list of strings to copy.
    """

    check(array, "array", [list, None])

    general_pasteboard().strings = array
예제 #10
0
def send(data: str):
    """
    Sends the given string to other connected devices.

    :param data: The string to send.
    """

    check(data, "data", [str])

    PyMultipeerHelper.send(data)
예제 #11
0
파일: photos.py 프로젝트: simon-hibbs/Pyto
def save_image(image: Image.Image):
    """
    Saves the given image to the photos library.

    :param image: A ``PIL`` image to save.
    """

    check(image, "image", [Image.Image])

    PyPhotosHelper.saveImage(__ui_image_from_pil_image__(image))
예제 #12
0
파일: music.py 프로젝트: kanishpatel/Pyto
def set_shuffle_mode(mode: int):
    """
    Sets the shuffle mode of the music player.

    :param mode: The shuffle mode to set. See `Shuffle Mode <music.html#id2>`_ for possible values.
    """

    check(mode, "mode", [int])

    player.shuffleMode = mode
예제 #13
0
파일: music.py 프로젝트: kanishpatel/Pyto
def set_repeat_mode(mode: int):
    """
    Sets the repeat mode of the music player.

    :param mode: The repeat mode to set. See `Repeat Mode <music.html#id1>`_ for possible values.
    """

    check(mode, "mode", [int])

    play.repeatMode = mode
예제 #14
0
파일: music.py 프로젝트: kanishpatel/Pyto
def set_queue_with_store_ids(ids: List[str]):
    """
    Sets a music player's playback queue using with media items identified by the store identifiers.

    :param ids: An array of store identifiers associated with the media items to be added to the queue.
    """

    check(ids, "ids", [list])

    player.setQueueWithStoreIDs(ids)
예제 #15
0
def show_widget(widget: Widget):
    """
    Shows a widget with the given configuration

    :param widget: The widget's configuration.
    """

    check(widget, "widget", [Widget])

    __show_widget__(widget, None)
예제 #16
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__)
예제 #17
0
def cancel_notification(notification: Notification):
    """
    Cancels a pending notification.

    :param notification: The :class:`~notifications.Notification` object returned from :func:`~notifications.get_pending_notifications`.
    """

    check(notification, "notification", [Notification])

    UNUserNotificationCenter.currentNotificationCenter(
    ).removePendingNotificationRequestsWithIdentifiers([notification.__id__])
예제 #18
0
def _schedule_next_reload(time: Union[datetime.timedelta, float]):
    check(time, "time", [datetime.timedelta, float, int])

    seconds = 0

    if isinstance(time, datetime.timedelta):
        seconds = time.total_seconds()
    else:
        seconds = time

    __PyComplication__.updateInterval = seconds
예제 #19
0
    def set_link(self, link: str):
        """
        When a widget is tapped, the widget is executed in app and the ``link`` attribute is passed to data:`~widgets.WidgetComponent.link`.

        Links on entire widgets take effect on small widgets unlike links on UI elements.
        
        :param link: A string that will be passed to the widget script when the widget is tapped.
        """

        check(link, "link", [str, None])

        self.__widget_view__.link = link
예제 #20
0
def save_widget(widget: Widget, key: str):
    """
    Saves a widget that will be selectable to show in a widget and can be updated in app.

    :param widget: The widget's configuration.
    :param key: The name of the widget. When a new widget is saved with an existing key, it will be updated.
    """

    check(widget, "widget", [Widget])
    check(key, "key", [str])

    __show_widget__(widget, key)
예제 #21
0
    def set_background_color(self, color: Color):
        """
        Sets the background color of the widget layout.

        :param color: A :class:`~widgets.Color` object.
        """

        check(color, "color", [Color, __pyto_ui_color__(), None])

        try:
            self.__widget_view__.backgroundColor = color.__py_color__.managed
        except (AttributeError, ValueError):
            self.__widget_view__.backgroundColor = COLOR_CLEAR
예제 #22
0
def set_string(text: Union[str, List[str]]):
    """
    Copies the given text to the pasteboard.

    :param text: A string or a list of strings.
    """

    check(text, "text", [str, list, None])

    if isinstance(text, list):
        general_pasteboard().strings = text
    else:
        general_pasteboard().string = text
예제 #23
0
def set_image(image: Union[Image.Image, List[Image.Image]]):
    """
    Copies the given image to the pasteboard.

    :param image: A PIL image or a list of PIL images.
    """

    check(image, "image", [Image.Image, None])

    if isinstance(image, list):
        _set_images(image)
    else:
        general_pasteboard().image = __ui_image_from_pil_image__(image)
예제 #24
0
def set_url(url: Union[str, List[str]]):
    """
    Copies the given URL to the pasteboard.

    :param url: A string or a list of strings.
    """

    check(url, "url", [str, None])

    if isinstance(url, list):
        _set_urls(url)
    else:
        general_pasteboard().URL = NSURL.alloc().initWithString(url)
예제 #25
0
def run_async(code):
    """
    Runs the given code asynchronously on the main thread.

    :param code: Code to execute in the main thread.
    """

    check(code, "code", [_func])

    def code_() -> None:
        code()

    __PyMainThread__.runAsync(code_)
예제 #26
0
def set_theme(theme: Theme):
    """
    Sets the current editor's theme.
    This will not install the theme, so if it was created by another device, the theme will disappear after choosing another one.
    To install it just go to the settings and create a new theme, that will copy the current one.

    :param theme: The theme to be set.
    """

    check(theme, "theme", [Theme])

    if not __py_core__.setTheme(theme.data):
        raise ValueError("Invalid theme!")
예제 #27
0
    def __init__(
        self,
        background_color: Color = None,
        corner_radius: float = 0,
        padding: Union[PADDING, Padding] = None,
        link: str = None,
    ):

        check(background_color, "background_color",
              [Color, __pyto_ui_color__(), None])
        check(corner_radius, "corner_radius", [float, int])
        check(padding, "padding", [int, Padding, None])
        check(link, "link", [str, None])

        if background_color is None:
            self.background_color = COLOR_CLEAR
        else:
            self.background_color = background_color

        self.corner_radius = corner_radius

        if padding is None:
            self.padding = PADDING_NONE
        else:
            self.padding = padding

        self.link = link
예제 #28
0
    def bold_system_font_of_size(cls, size: float) -> Font:
        """
        Returns the font object used for standard interface items that are rendered in boldface type in the specified size

        :param size: The size (in points) for the font. This value must be greater than 0.0.

        :rtype: pyto_ui.Font
        """

        check(size, "size", [float, int])

        font = cls(None, None)
        font.__ui_font__ = __UIFont__.boldSystemFontOfSize(CGFloat(size))
        return font
예제 #29
0
    def font_with_style(cls, style: FONT_TEXT_STYLE) -> Font:
        """
        Returns an instance of the system font for the specified text style and scaled appropriately for the user's selected content size category.

        :param style: The text style for which to return a font. See `Font Text Style <constants.html#font-text-style>`_ constants for possible values.

        :rtype: pyto_ui.Font
        """

        check(style, "style", [str])

        font = cls(None, None)
        font.__ui_font__ = __UIFont__.preferredFontForTextStyle(style)
        return font
예제 #30
0
    def system_font_of_size(cls, size: float) -> Font:
        """
        Returns the font object used for standard interface items in the specified size.

        :param size: The size (in points) to which the font is scaled. This value must be greater than 0.0.

        :rtype: pyto_ui.Font
        """

        check(size, "size", [float, int])

        font = cls(None, None)
        font.__ui_font__ = __UIFont__.systemFontOfSize(CGFloat(size))
        return font