当前位置: 首页>>代码示例>>Python>>正文


Python NSURL.alloc方法代码示例

本文整理汇总了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)
开发者ID:felixonmars,项目名称:pyfm,代码行数:29,代码来源:notifier.py

示例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))
开发者ID:nst,项目名称:filters,代码行数:47,代码来源:filters.py

示例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')
开发者ID:mynicolas,项目名称:KeyCounter,代码行数:44,代码来源:macos_counter.py

示例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 "------------------------------------------"
开发者ID:bizcoine,项目名称:the-maker,代码行数:23,代码来源:makerProjectManager.py

示例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()
开发者ID:bitsworking,项目名称:blink-cocoa,代码行数:7,代码来源:ChatViewController.py


注:本文中的Foundation.NSURL.alloc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。