def __init__(self, ui_file_path): NSBundle.bundleWithPath_( '/System/Library/Frameworks/MediaPlayer.framework').load() self._player = ObjCClass('MPMusicPlayerController').systemMusicPlayer() self._nc = NotificationController(self) self._uic = UIController(self, ui_file_path) self._npc = NowPlayingController() self.thumb_size = 0
def bundleForClass(cls): if type(cls) == str: try: cls = ObjCClass(cls) except: return None try: b = NSBundle.bundleForClass_(cls) return Bundle(b) except ValueError: return None
def perform_backup(quiet=True): try: from urllib2 import urlopen except: try: from urllib.request import urlopen except: pass try: urlopen('http://s3.amazonaws.com') except: if quiet: return else: sys.exit('ERROR: Unable to connect to s3.amazonaws.com') doc_path = os.path.expanduser('~/Documents') os.chdir(doc_path) backup_path = os.path.join(doc_path, 'Backup.zip') if os.path.exists(backup_path): os.remove(backup_path) print('Creating backup archive...') shutil.make_archive(os.path.join(tempfile.gettempdir(), 'Backup'), 'zip') shutil.move(os.path.join(tempfile.gettempdir(), 'Backup.zip'), backup_path) print('Backup archive created, uploading to S3 ...') date_text = time.strftime('%Y-%b-%d') time_text = time.strftime('%I-%M-%S-%p') info_dict_version_key = 'CFBundleShortVersionString' main_bundle = NSBundle.mainBundle() app_version = str( main_bundle.objectForInfoDictionaryKey_(info_dict_version_key))[0] AWS_ACCESS_KEY_ID = keychain.get_password('aws', 'AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = keychain.get_password('aws', 'AWS_SECRET_ACCESS_KEY') bucket_name = 'lukaskollmer' def percent_cb(complete, total): reprint('{}'.format(round(float(complete) / float(total) * 100, 2))) s3 = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) bucket = s3.get_bucket(bucket_name) filename = 'Backup-{}.zip'.format(time_text) k = Key(bucket) k.storage_class = 'REDUCED_REDUNDANCY' k.key = '/Backup/Pythonista{}/{}/{}'.format(app_version, date_text, filename) print('0.0 %') k.set_contents_from_filename('Backup.zip', cb=percent_cb, num_cb=10) print('Successfully uploaded') os.remove(backup_path)
def perform_backup(quiet=True): try: from urllib2 import urlopen except: try: from urllib.request import urlopen except: pass try: urlopen('http://s3.amazonaws.com') except: if quiet: return else: sys.exit('ERROR: Unable to connect to s3.amazonaws.com') doc_path = os.path.expanduser('~/Documents') os.chdir(doc_path) backup_path = os.path.join(doc_path, 'Backup.zip') if os.path.exists(backup_path): os.remove(backup_path) print('Creating backup archive...') shutil.make_archive(os.path.join(tempfile.gettempdir(), 'Backup'), 'zip') shutil.move(os.path.join(tempfile.gettempdir(), 'Backup.zip'), backup_path) print('Backup archive created, uploading to S3 ...') date_text = time.strftime('%Y-%b-%d') time_text = time.strftime('%I-%M-%S-%p') info_dict_version_key = 'CFBundleShortVersionString' main_bundle = NSBundle.mainBundle() app_version = str(main_bundle.objectForInfoDictionaryKey_(info_dict_version_key))[0] AWS_ACCESS_KEY_ID = keychain.get_password('aws', 'AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = keychain.get_password('aws', 'AWS_SECRET_ACCESS_KEY') bucket_name = 'lukaskollmer' def percent_cb(complete, total): reprint('{}'.format(round(float(complete) / float(total) * 100, 2))) s3 = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) bucket = s3.get_bucket(bucket_name) filename = 'Backup-{}.zip'.format(time_text) k = Key(bucket) k.storage_class = 'REDUCED_REDUNDANCY' k.key = '/Backup/Pythonista{}/{}/{}'.format(app_version, date_text, filename) print('0.0 %') k.set_contents_from_filename('Backup.zip', cb=percent_cb, num_cb=10) print('Successfully uploaded') os.remove(backup_path)
def pythonista_version(): try: # Try reading Info.plist using plistlib; could fail if Info.plist is binary plist = plistlib.readPlist( os.path.abspath(os.path.join(sys.executable, '..', 'Info.plist'))) return '{CFBundleShortVersionString} ({CFBundleVersion})'.format( **plist) except: try: # Use objc_util to access Info.plist via native APIs; will fail for versions < 2.0 (objc_util/ctypes weren't available) from objc_util import NSBundle return str(NSBundle.mainBundle().infoDictionary() ['CFBundleShortVersionString']) except ImportError: # For older versions (1.x), determine the version by checking for capabilities (modules that were added) version = None try: import ui version = '1.5' except ImportError: pass if not version: try: import contacts version = '1.4' except ImportError: pass if not version: try: import photos version = '1.3' except ImportError: pass if not version: try: import PIL version = '1.2' except ImportError: pass if not version: try: import editor version = '1.1' except ImportError: pass if not version: version = '1.0' return version
#coding: utf-8 # Put your script (and all resources that it needs for running) in this folder. # The filename of the main script should be "main.py". from objc_util import NSBundle info = NSBundle.mainBundle().infoDictionary() version = str(info['CFBundleVersion']) short_version = str(info['CFBundleShortVersionString']) print(version) print(short_version) print('Hello World')
# https://github.com/jbking/pythonista-misc/blob/master/spritekit/skview-demo.py import random import ui from objc_util import (UIColor, CGRect, CGPoint, CGSize, ObjCClass, ObjCInstance, NSBundle, create_objc_class) NSBundle.bundleWithPath_( "/System/Library/Frameworks/SpriteKit.framework").load() SKView = ObjCClass('SKView') SKScene = ObjCClass('SKScene') SKShapeNode = ObjCClass('SKShapeNode') SKPhysicsBody = ObjCClass('SKPhysicsBody') def create_circle_shape(point): radius = random.randint(25, 45) node = SKShapeNode.shapeNodeWithCircleOfRadius_(radius) node.position = point node.physicsBody = SKPhysicsBody.bodyWithCircleOfRadius_(radius) return node def create_box_shape(point): width = random.randint(42, 80) height = random.randint(42, 80) size = CGSize(width, height) node = SKShapeNode.shapeNodeWithRectOfSize_(size) node.position = point node.physicsBody = SKPhysicsBody.bodyWithRectangleOfSize_(size)
from objc_util import ObjCClass, NSBundle, uiimage_to_png, nsurl, ObjCInstance, ns from io import BytesIO from PIL import Image from urllib.parse import urlparse from objc_tools.device import osVersion from objc_tools.backports.enum_backport import IntEnum, Flag from objc_tools.foundation.error import ObjcErrorHandler media_player_bundle = NSBundle.bundleWithPath_('/System/Library/Frameworks' '/MediaPlayer.framework') media_player_bundle.load() iOS_version = osVersion()[0] + (osVersion()[1] / 10) del media_player_bundle, osVersion MPMediaLibrary = ObjCClass("MPMediaLibrary") MPMediaQuery = ObjCClass('MPMediaQuery') MPMusicPlayerController = ObjCClass('MPMusicPlayerController') file_handler = ObjCClass('AVAudioFile').alloc() MPMediaPropertyPredicate = ObjCClass("MPMediaPropertyPredicate") MPMediaItem = ObjCClass('MPMediaItem') class RepeatMode(IntEnum): default = 0 # We use lowercase none to seperate it from the keyword None none = 1 one = 2 all = 3 class ShuffleMode(IntEnum): default = 0
def getBundleWithID(bid): return Bundle(NSBundle.bundleWithIdentifier_(bid))
from objc_util import ObjCClass, NSBundle, uiimage_to_png, nsurl, ObjCInstance, ns from io import BytesIO from PIL import Image from urllib.parse import urlparse from objc_tools.device import osVersion from objc_tools.backports.enum_backport import IntEnum, Flag from objc_tools.foundation.error import ObjcErrorHandler media_player_bundle = NSBundle.bundleWithPath_('/System/Library/Frameworks' '/MediaPlayer.framework') media_player_bundle.load() iOS_version = osVersion()[0]+(osVersion()[1]/10) del media_player_bundle, osVersion MPMediaLibrary = ObjCClass("MPMediaLibrary") MPMediaQuery = ObjCClass('MPMediaQuery') MPMusicPlayerController = ObjCClass('MPMusicPlayerController') file_handler = ObjCClass('AVAudioFile').alloc() MPMediaPropertyPredicate = ObjCClass("MPMediaPropertyPredicate") MPMediaItem = ObjCClass('MPMediaItem') class RepeatMode (IntEnum): default = 0 # We use lowercase none to seperate it from the keyword None none = 1 one = 2 all = 3 class ShuffleMode (IntEnum): default = 0
def getLoadedFrameworks(): blist = [] for i in NSBundle.allFrameworks(): if i.isLoaded(): blist += [Bundle(i)] return blist
def mainBundle(): return Bundle(NSBundle.mainBundle())
def getBundleWithPath(path): return Bundle(NSBundle.bundleWithPath_(path))
def bundleForObjcClass(objc): return Bundle(NSBundle.bundleForClass_(objc))
# coding: utf-8 # https://gist.github.com/filippocld/c0deb6714a9aff9f1da9 from objc_util import NSBundle, ObjCClass, on_main_thread NSBundle.bundleWithPath_( '/System/Library/Frameworks/MediaPlayer.framework').load() MPVolumeView = ObjCClass('MPVolumeView') volume_view = MPVolumeView.new().autorelease() @on_main_thread def set_system_volume(value): volume_view.subviews()[0].value = value @on_main_thread def get_system_volume(): return volume_view.subviews()[0].value() def upAction(): #Volume Up button has been pressed print('Up!') def downAction(): #Volume Down button has been pressed print('Down!')
# coding: utf-8 # https://forum.omz-software.com/topic/2743/new-xcode-template-on-github/13 from __future__ import print_function from objc_util import NSBundle info = NSBundle.mainBundle().infoDictionary() version = str(info['CFBundleVersion']) short_version = str(info['CFBundleShortVersionString']) print(version)
# coding: utf-8 from ElementBase import ElementBase from ElementParameter import ElementParameter from ElementValue import ElementValue from objc_util import NSBundle, ObjCClass, on_main_thread NSBundle.bundleWithPath_('/System/Library/Frameworks/MediaPlayer.framework').load() MPVolumeView = ObjCClass('MPVolumeView') class SetVolume(ElementBase): def __init__(self): self.status = 'running' self.output = None self.params = None self.type = 'Standard' self.setup_params() def can_handle_list(self): return False def setup_params(self): pass def get_status(self): return self.status def get_input_type(self): return 'number' def get_output(self): return self.output