Python objc.loadBundle() Examples
The following are 8
code examples of objc.loadBundle().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
objc
, or try the search function
.
Example #1
Source File: wifi_ssid.py From unearth with Apache License 2.0 | 6 votes |
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}
Example #2
Source File: bluetooth_sharing.py From unearth with Apache License 2.0 | 6 votes |
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}
Example #3
Source File: wifi_status.py From unearth with Apache License 2.0 | 6 votes |
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}
Example #4
Source File: _lazyimport.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 6 votes |
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
Example #5
Source File: update.py From EDMarketConnector with GNU General Public License v2.0 | 5 votes |
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
Example #6
Source File: mac_wifi.py From salt-osx with MIT License | 5 votes |
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
Example #7
Source File: updater.py From vorta with GNU General Public License v3.0 | 5 votes |
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
Example #8
Source File: global_hotkey_mac.py From FeelUOwn with GNU General Public License v3.0 | 4 votes |
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 []