Exemple #1
0
def register_app_launchservices(uniform_type_identifier="public.python-script",
                                role='editor'):
    """
    Register app to the Apple launch services so it can open Python files
    """
    app = QApplication.instance()
    # If top frame is MAC_APP_NAME, set ourselves to open files at startup
    origin_filename = get_origin_filename()
    if MAC_APP_NAME in origin_filename:
        bundle_idx = origin_filename.find(MAC_APP_NAME)
        old_handler = als.get_bundle_identifier_for_path(
            origin_filename[:bundle_idx] + MAC_APP_NAME)
    else:
        # Else, just restore the previous handler
        old_handler = als.get_UTI_handler(uniform_type_identifier, role)

    app._original_handlers[(uniform_type_identifier, role)] = old_handler

    # Restore previous handle when quitting
    app.aboutToQuit.connect(restore_launchservices)

    if not app._never_shown:
        bundle_identifier = als.get_bundle_identifier()
        als.set_UTI_handler(uniform_type_identifier, role, bundle_identifier)
        return

    # Wait to be visible to set ourselves as the UTI handler
    def handle_applicationStateChanged(state):
        if state == Qt.ApplicationActive and app._never_shown:
            app._never_shown = False
            bundle_identifier = als.get_bundle_identifier()
            als.set_UTI_handler(uniform_type_identifier, role,
                                bundle_identifier)

    app.applicationStateChanged.connect(handle_applicationStateChanged)
Exemple #2
0
def register_app_launchservices(
        uniform_type_identifier="public.python-script",
        role='editor'):
    """
    Register app to the Apple launch services so it can open Python files
    """
    app = QApplication.instance()

    old_handler = als.get_UTI_handler(uniform_type_identifier, role)

    app._original_handlers[(uniform_type_identifier, role)] = old_handler

    # Restore previous handle when quitting
    app.aboutToQuit.connect(restore_launchservices)

    if not app._never_shown:
        bundle_identifier = als.get_bundle_identifier()
        als.set_UTI_handler(
            uniform_type_identifier, role, bundle_identifier)
        return

    # Wait to be visible to set ourselves as the UTI handler
    def handle_applicationStateChanged(state):
        if state == Qt.ApplicationActive and app._never_shown:
            app._never_shown = False
            bundle_identifier = als.get_bundle_identifier()
            als.set_UTI_handler(
                uniform_type_identifier, role, bundle_identifier)

    app.applicationStateChanged.connect(handle_applicationStateChanged)
 def handle_applicationStateChanged(state):
     if state == Qt.ApplicationActive and app._starting:
         app._starting = False
         bundle_identifier = als.get_bundle_identifier()
         als.set_UTI_handler(uniform_type_identifier, role,
                             bundle_identifier)
         als.set_URL_scheme_handler(url_scheme, bundle_identifier)
Exemple #4
0
 def handle_applicationStateChanged(state):
     if state == Qt.ApplicationActive and app._never_shown:
         app._never_shown = False
         bundle_identifier = als.get_bundle_identifier()
         als.set_UTI_handler(uniform_type_identifier, role,
                             bundle_identifier)
Exemple #5
0
def restore_launchservices():
    """Restore LaunchServices to the previous state"""
    app = QApplication.instance()
    for key, handler in app._original_handlers.items():
        UTI, role = key
        als.set_UTI_handler(UTI, role, handler)
 def reset_handlers():
     als.set_UTI_handler(uniform_type_identifier, role, old_UTI_handler)
     als.set_URL_scheme_handler(url_scheme, old_URL_handler)