本文整理汇总了Python中Foundation.NSURL.alloc方法的典型用法代码示例。如果您正苦于以下问题:Python NSURL.alloc方法的具体用法?Python NSURL.alloc怎么用?Python NSURL.alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foundation.NSURL
的用法示例。
在下文中一共展示了NSURL.alloc方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pyobjc_notify
# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import alloc [as 别名]
def _pyobjc_notify(message, title=None, subtitle=None, appIcon=None, contentImage=None, open_URL=None, delay=0, sound=False):
swizzle(objc.lookUpClass('NSBundle'),
b'bundleIdentifier',
swizzled_bundleIdentifier)
notification = NSUserNotification.alloc().init()
notification.setInformativeText_(message)
if title:
notification.setTitle_(title)
if subtitle:
notification.setSubtitle_(subtitle)
if appIcon:
url = NSURL.alloc().initWithString_(appIcon)
image = NSImage.alloc().initWithContentsOfURL_(url)
notification.set_identityImage_(image)
if contentImage:
url = NSURL.alloc().initWithString_(contentImage)
image = NSImage.alloc().initWithContentsOfURL_(url)
notification.setContentImage_(image)
if sound:
notification.setSoundName_(
"NSUserNotificationDefaultSoundName")
notification.setDeliveryDate_(
NSDate.dateWithTimeInterval_sinceDate_(delay, NSDate.date()))
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(
notification)
示例2: apply_cifilter_with_name
# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import alloc [as 别名]
def apply_cifilter_with_name(filter_name, orientation, in_path, out_path, dry_run=False):
print "-- in: ", in_path
print "-- out:", out_path
assert in_path
assert out_path
assert filter_name in ["CIPhotoEffectTonal", "CIPhotoEffectMono", "CIPhotoEffectInstant", "CIPhotoEffectTransfer",
"CIPhotoEffectProcess", "CIPhotoEffectChrome", "CIPhotoEffectNoir", "CIPhotoEffectFade",
"CIPhotoEffect3DDramatic", "CIPhotoEffect3DVivid", "CIPhotoEffect3DDramaticCool", "CIPhotoEffect3DNoir"]
url = NSURL.alloc().initFileURLWithPath_(in_path)
ci_image = CIImage.imageWithContentsOfURL_(url)
assert ci_image
in_creation_timestamp = os.path.getmtime(in_path)
print time.ctime(in_creation_timestamp)
if orientation != None and orientation != 1:
print "-- orientation:", orientation
ci_image = ci_image.imageByApplyingOrientation_(orientation)
ci_filter = CIFilter.filterWithName_(filter_name)
assert ci_filter
ci_filter.setValue_forKey_(ci_image, "inputImage")
ci_filter.setDefaults()
ci_image_result = ci_filter.outputImage()
assert ci_image_result
bitmap_rep = NSBitmapImageRep.alloc().initWithCIImage_(ci_image_result)
assert bitmap_rep
properties = { "NSImageCompressionFactor" : 0.9 }
data = bitmap_rep.representationUsingType_properties_(3, properties) # 3 for JPEG
if dry_run:
print "-- dryrun, don't write", out_path
return
assert data.writeToFile_atomically_(out_path, True)
os.utime(out_path, (time.time(), in_creation_timestamp))
示例3: _check_for_access
# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import alloc [as 别名]
def _check_for_access(self):
'''Check for accessibility permission'''
# Because unsigned bundle will fail to call
# AXIsProcessTrustedWithOptions with a segment falt, we're
# not currently stepping into this function.
return
self.log('Begin checking for accessibility')
core_services = objc.loadBundle(
'CoreServices',
globals(),
bundle_identifier='com.apple.ApplicationServices'
)
objc.loadBundleFunctions(
core_services,
globals(),
[('AXIsProcessTrustedWithOptions', b'[email protected]')]
)
objc.loadBundleFunctions(
core_services,
globals(),
[('kAXTrustedCheckOptionPrompt', b'@')]
)
self.log('Bundle com.apple.ApplicationServices loaded')
try:
if not AXIsProcessTrustedWithOptions( # noqa
{kAXTrustedCheckOptionPrompt: False} # noqa
):
self.log('Requesting access, Opening syspref window')
NSWorkspace.sharedWorkspace().openURL_(
NSURL.alloc().initWithString_(
'x-apple.systempreferences:'
'com.apple.preference.security'
'?Privacy_Accessibility'
)
)
except:
# Unsigned bundle will fail to call AXIsProcessTrustedWithOptions
self.log((
'Error detecting accessibility permission status, '
'KeyCounter might not work'
))
self.log('Access already granted')
示例4: setSecurityScopedBookmark
# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import alloc [as 别名]
def setSecurityScopedBookmark(self, path):
#=======================================================================
# Security Scoped Bookmark
#=======================================================================
try:
dirURL = NSURL.alloc().initFileURLWithPath_(path)
myData = dirURL.bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error_(NSURLBookmarkCreationWithSecurityScope,
None,
None,
None)
theBytes = myData[0].bytes().tobytes()
self.bookmarks.append(theBytes)
except Exception, e:
print "Unable to create security-scoped-bookmarks"
print str(e)
print "------------------------------------------"
示例5: setContentFile_
# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import alloc [as 别名]
def setContentFile_(self, path):
self.finishedLoading = False
request = NSURLRequest.alloc().initWithURL_(NSURL.alloc().initFileURLWithPath_(path))
self.outputView.mainFrame().loadRequest_(request)
assert self.outputView.preferences().isJavaScriptEnabled()