コード例 #1
0
    def run(*args, **kwargs):
        import mainthread

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

        return mainthread.run_sync(_run)
コード例 #2
0
def open_url(url):
    """
    Opens the given URL.
    
    Args:
        url: URL to open. Can be a String or an Objective-C `NSURL`.
    """
    def __openURL__() -> None:
        __UIApplication__.sharedApplication.openURL(__url__)

    if (type(url) is str):
        __url__ = __NSURL__.URLWithString(url)
        mainthread.run_sync(__openURL__)
    elif (__PySharingHelper__.isURL(url)):
        __url__ = url
        mainthread.run_sync(__openURL__)
    else:
        raise ValueError('url musts be a String or an Objective-C `NSURL`.')
コード例 #3
0
def open_url(url: str):
    """
    Opens the given URL.

    :param url: URL to open. Can be a String or an Objective-C ``NSURL``.
    """

    __url__ = None

    def __openURL__() -> None:
        __UIApplication__.sharedApplication.openURL(__url__)

    if type(url) is str:
        __url__ = NSURL.URLWithString(url)
        mainthread.run_sync(__openURL__)
    elif __PySharingHelper__.isURL(url):
        __url__ = url
        mainthread.run_sync(__openURL__)
    else:
        raise ValueError("url musts be a String or an Objective-C ``NSURL``.")
コード例 #4
0
def suspend():
    def runSuspend() -> None:
        UIApplication.sharedApplication.suspend()

    mainthread.run_sync(runSuspend)
コード例 #5
0
    label.frame = CGRect(CGPoint(0, 0), CGSize(size.width, 50))
    label.center = CGPoint(size.width / 2, (size.height / 2) - 60)


# MARK: - Showing the UI


def main() -> None:
    """
  Ran on main thread for presenting the View controller.
  
  IMPORTANT: All functions that will be sent to Objective-C must be fully annotated. For example, this function returns `None`, so add "-> None" at the end. For parameters, write ": ObjCInstance" to represent any Objective-C instance.
  
  Returns: `None`
  """

    global viewController
    viewController = UIViewController.new()

    navigationController = UINavigationController.new()
    navigationController.setViewControllers([viewController])
    ui.show_view_controller(navigationController, setupView)


# Runs `main` on main thread.
mainthread.run_sync(main)

# This will stop the current thread until the View controller is hidden. Very important to avoid crashes on actions!
ui.main_loop()
コード例 #6
0
ファイル: Tint Color.py プロジェクト: freemotionstudios/Pyto
"""
Changes the tint color of the app to red.
"""

from UIKit import UIColor, UIApplication
import mainthread

# Code here


def changeTintColor() -> None:
    UIApplication.sharedApplication.keyWindow.tintColor = UIColor.redColor


mainthread.run_sync(changeTintColor)