當前位置: 首頁>>代碼示例>>Python>>正文


Python objc.loadBundle方法代碼示例

本文整理匯總了Python中objc.loadBundle方法的典型用法代碼示例。如果您正苦於以下問題:Python objc.loadBundle方法的具體用法?Python objc.loadBundle怎麽用?Python objc.loadBundle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在objc的用法示例。


在下文中一共展示了objc.loadBundle方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fact

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def fact():
    """Returns the wifi ssid of the Mac"""
    wifi_ssid = None

    objc.loadBundle(
        "CoreWLAN",
        bundle_path="/System/Library/Frameworks/CoreWLAN.framework",
        module_globals=globals(),
    )

    wifi = CWInterface.interfaceNames()
    if wifi:
        for iname in wifi:
            interface = CWInterface.interfaceWithName_(iname)
        if interface:
            try:
                wifi_ssid = interface.ssid()
            except AttributeError:
                pass

    return {factoid: wifi_ssid} 
開發者ID:chilcote,項目名稱:unearth,代碼行數:23,代碼來源:wifi_ssid.py

示例2: fact

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def fact():
    """Returns the current bluetooth sharing"""

    result = "None"

    objc.loadBundle(
        "IOBluetooth",
        globals(),
        bundle_path=objc.pathForFramework(
            u"/System/Library/Frameworks/IOBluetooth.framework"
        ),
    )
    btprefs = IOBluetoothPreferences.alloc().init()
    result = bool(btprefs.fileTransferServicesEnabled())

    return {factoid: result} 
開發者ID:chilcote,項目名稱:unearth,代碼行數:18,代碼來源:bluetooth_sharing.py

示例3: fact

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def fact():
    """Returns the wifi power status of the Mac"""
    wifi_status = None
    objc.loadBundle(
        "CoreWLAN",
        bundle_path="/System/Library/Frameworks/CoreWLAN.framework",
        module_globals=globals(),
    )

    wifi = CWInterface.interfaceNames()
    if wifi:
        for iname in wifi:
            interface = CWInterface.interfaceWithName_(iname)
        try:
            wifi_status = "On" if interface.powerOn() == 1 else "Off"
        except AttributeError:
            wifi_status = None
    return {factoid: wifi_status} 
開發者ID:chilcote,項目名稱:unearth,代碼行數:20,代碼來源:wifi_status.py

示例4: _loadBundle

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def _loadBundle(frameworkName, frameworkIdentifier, frameworkPath):
    if frameworkIdentifier is None:
        bundle = loadBundle(
            frameworkName, {}, bundle_path=frameworkPath, scan_classes=False
        )

    else:
        try:
            bundle = loadBundle(
                frameworkName,
                {},
                bundle_identifier=frameworkIdentifier,
                scan_classes=False,
            )

        except ImportError:
            bundle = loadBundle(
                frameworkName, {}, bundle_path=frameworkPath, scan_classes=False
            )

    return bundle 
開發者ID:mass-immersion-approach,項目名稱:MIA-Dictionary-Addon,代碼行數:23,代碼來源:_lazyimport.py

示例5: __init__

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def __init__(self, master):
            try:
                objc.loadBundle('Sparkle', globals(), join(dirname(sys.executable.decode(sys.getfilesystemencoding())), os.pardir, 'Frameworks', 'Sparkle.framework'))
                self.updater = SUUpdater.sharedUpdater()
            except:
                # can't load framework - not frozen or not included in app bundle?
                self.updater = None 
開發者ID:EDCD,項目名稱:EDMarketConnector,代碼行數:9,代碼來源:update.py

示例6: _load_objc_framework

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def _load_objc_framework(framework_name):
    """Load an ObjC Framework bundle.

    :param str framework_name: framework_name (str): The name of the
        framework to load.

    :return: Generic class instance with public framework contents
        attached as attributes and methods.

    :rtype: object
    """
    log.trace('wifi._load_objc_framework: loading {}.'.format(framework_name))
    loaded_classes = dict()
    framework_bundle = objc.loadBundle(
        framework_name,
        bundle_path=os.path.dirname(ctypes.util.find_library(framework_name)),
        module_globals=loaded_classes)

    class AttributedFramework():
        pass

    framework = AttributedFramework()
    for name, loaded_class in loaded_classes.items():
        if not name.startswith('_'):
            setattr(framework, name, loaded_class)
    return framework 
開發者ID:mosen,項目名稱:salt-osx,代碼行數:28,代碼來源:mac_wifi.py

示例7: get_updater

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def get_updater():
    if sys.platform == 'darwin' and getattr(sys, 'frozen', False):
        """
        Use Sparkle framework on macOS.

        Settings: https://sparkle-project.org/documentation/customization/
        Examples: https://programtalk.com/python-examples/objc.loadBundle/

        To debug:
        $ defaults read com.borgbase.client.macos
        """

        import objc
        import Cocoa
        bundle_path = os.path.join(os.path.dirname(sys.executable), os.pardir, 'Frameworks', 'Sparkle.framework')
        objc.loadBundle('Sparkle', globals(), bundle_path)
        sparkle = SUUpdater.sharedUpdater()  # noqa: F821

        # A default Appcast URL is set in vorta.spec, when setting it here it's saved to defaults,
        # so we need both cases.
        if SettingsModel.get(key='updates_include_beta').value:
            appcast_nsurl = Cocoa.NSURL.URLWithString_('https://borgbase.github.io/vorta/appcast-pre.xml')
        else:
            appcast_nsurl = Cocoa.NSURL.URLWithString_('https://borgbase.github.io/vorta/appcast.xml')

        sparkle.setFeedURL_(appcast_nsurl)

        if SettingsModel.get(key='check_for_updates').value:
            sparkle.setAutomaticallyChecksForUpdates_(True)
            sparkle.checkForUpdatesInBackground()

        sparkle.setAutomaticallyDownloadsUpdates_(False)
        return sparkle

    else:  # TODO: implement for Linux
        return None 
開發者ID:borgbase,項目名稱:vorta,代碼行數:38,代碼來源:updater.py

示例8: run_event_loop

# 需要導入模塊: import objc [as 別名]
# 或者: from objc import loadBundle [as 別名]
def run_event_loop():
    logger.info('try to load mac hotkey event loop')
    # Set up a tap, with type of tap, location, options and event mask

    def create_tap():
        return Quartz.CGEventTapCreate(
            Quartz.kCGSessionEventTap,  # Session level is enough for our needs
            Quartz.kCGHeadInsertEventTap,  # Insert wherever, we do not filter
            Quartz.kCGEventTapOptionDefault,
            # NSSystemDefined for media keys
            Quartz.CGEventMaskBit(NSSystemDefined),
            keyboard_tap_callback,
            None
        )
    tap = create_tap()
    if tap is None:
        logger.error('Error occurred when trying to listen global hotkey. '
                     'trying to popup a prompt dialog to ask for permission.')
        # we do not use pyobjc-framework-ApplicationServices directly, since it
        # causes segfault when call AXIsProcessTrustedWithOptions function
        import objc
        AS = objc.loadBundle('CoreServices', globals(),
                             '/System/Library/Frameworks/ApplicationServices.framework')
        objc.loadBundleFunctions(AS, globals(),
                                 [('AXIsProcessTrustedWithOptions', b'Z@')])
        objc.loadBundleVariables(AS, globals(),
                                 [('kAXTrustedCheckOptionPrompt', b'@')])
        trusted = AXIsProcessTrustedWithOptions({kAXTrustedCheckOptionPrompt: True})  # noqa
        if not trusted:
            logger.info('Have popuped a prompt dialog to ask for accessibility.'
                        'You can restart feeluown after you grant access to it.')
        else:
            logger.warning('Have already grant accessibility, '
                           'but we still can not listen global hotkey,'
                           'theoretically, this should not happen.')
        return

    run_loop_source = Quartz.CFMachPortCreateRunLoopSource(
        None, tap, 0)
    Quartz.CFRunLoopAddSource(
        Quartz.CFRunLoopGetCurrent(),
        run_loop_source,
        Quartz.kCFRunLoopDefaultMode
    )
    # Enable the tap
    Quartz.CGEventTapEnable(tap, True)
    # and run! This won't return until we exit or are terminated.
    Quartz.CFRunLoopRun()
    logger.error('mac hotkey event loop exit')
    return [] 
開發者ID:feeluown,項目名稱:FeelUOwn,代碼行數:52,代碼來源:global_hotkey_mac.py


注:本文中的objc.loadBundle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。