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


Python NSURL.fileURLWithPath_方法代码示例

本文整理汇总了Python中Foundation.NSURL.fileURLWithPath_方法的典型用法代码示例。如果您正苦于以下问题:Python NSURL.fileURLWithPath_方法的具体用法?Python NSURL.fileURLWithPath_怎么用?Python NSURL.fileURLWithPath_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Foundation.NSURL的用法示例。


在下文中一共展示了NSURL.fileURLWithPath_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LoadImageFromPath

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def LoadImageFromPath( path ):

    url = NSURL.fileURLWithPath_(path)
    NSLog( "LoadImageFromPath( %@ )",  url  );

    #
    #   Create image source from URL
    #
    #   An image source abstracts the data-access task and eliminates the need for you to manage data through a raw memory buffer. 
    #   An image source can contain more than one image, thumbnail images, and properties for each image and the image file. 
    #   When you are working with image data and your application runs in Mac OS X v10.4 or later, image 
    #     sources are the preferred way to move image data into your application.
    #
    #   CGImageSource objects, available in Mac OS X v10.4 or later, abstract the data-reading task. An image source can 
    #     read image data from a   URL, a CFData object, or a data consumer. After creating a CGImageSource object for the 
    #     appropriate source, you can obtain images, thumbnails, image properties, and other image information using CGImageSource functions.
    #
    #   CGImageSourceCreateWithURL ==> Creates an image source that reads from a location specified by a URL.
    #
    #   CGImageSourceCreateImageAtIndex ==> Creates a CGImage object for the image data associated with the specified index in an image source.
    #     Create an image from the first item in the image source.                                                   
    
    imagesrc = CGImageSourceCreateWithURL(url, None)        
#    NSLog( "LoadImageFromPath: imagesrc is %r" % (imagesrc,) )

    theImage = CGImageSourceCreateImageAtIndex(imagesrc, 0, None);
#    NSLog( "LoadImageFromPath: theImage is %r" % (theImage,) )
    
    return theImage
开发者ID:donbro,项目名称:openworld,代码行数:31,代码来源:CGImageUtils.py

示例2: set_background

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def set_background(image_file):
    from AppKit import NSWorkspace, NSScreen
    from Foundation import NSURL
    file_url = NSURL.fileURLWithPath_(image_file)
    ws = NSWorkspace.sharedWorkspace()
    for screen in NSScreen.screens():
        ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, {}, None)
开发者ID:viveksjain,项目名称:bing-potd,代码行数:9,代码来源:potd.py

示例3: exportAllInstances

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def exportAllInstances():
	'''
	This will export all instances of the font at 'path' as TrueType fonts.
	'''
	path = os.path.expanduser("~/Desktop/test/file.glyphs")
	doc = Glyphs.openDocumentWithContentsOfFile_display_(path, False)
	print "Exporting:", doc.displayName()
	font = doc.font()
	for instance in font.instances():
		print "Instance:", instance
		instance.generate_({
			'ExportFormat': "TTF",
			'ExportContainer': "woff",
			'Destination': NSURL.fileURLWithPath_(os.path.expanduser("~/Desktop/test/"))
		})
		
	'''
	possible keys:
		ExportContainer: "woff", "woff2", "eot"
		Destination: NSURL
		autoHint: bool (default = true)
		removeOverlap: bool (default = true)
		useSubroutines: bool (default = true)
		useProductionNames: bool (default = true)
	'''
	
	doc.close()
	print "Ready!"
开发者ID:schriftgestalt,项目名称:GlyphsSDK,代码行数:30,代码来源:testExternal.py

示例4: change_desktop_background

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def change_desktop_background(file, desk_id):
    """Function that applies the named file as wallaper for the specified
    monitor (desk_id)"""
    file_url = NSURL.fileURLWithPath_(file)
    screen   = NSScreen.screens()[desk_id]
    ws       = NSWorkspace.sharedWorkspace()
    ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, {}, None)
开发者ID:bcwolven,项目名称:pychgwp,代码行数:9,代码来源:chgwp.py

示例5: next_image

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
    def next_image(self, _):

        if not os.path.exists(self.media_dir):
            os.makedirs(self.media_dir)

        url = 'https://unsplash.it/'
        if self.gray_mood: url += 'g/'
        url += '{w}/{h}/?random'
        if self.blur: url += '&blur'

        url = url.format(w=self.screen_width, h=self.screen_height)
        file_name = self.media_dir + datetime.datetime.now().strftime("%H:%M:%S.%f") + '.jpg'

        try:
            self.icon = 'img/wait.png'
            urllib.urlretrieve(url, file_name)
            file_url = NSURL.fileURLWithPath_(file_name)

            # Get shared workspace
            ws = NSWorkspace.sharedWorkspace()

            # Iterate over all screens
            for screen in NSScreen.screens():
                # Tell the workspace to set the desktop picture
                (result, error) = ws.setDesktopImageURL_forScreen_options_error_(
                    file_url, screen, {}, None)
            self.icon = 'img/icon.png'
        except IOError:
            print('Service unavailable, check your internet connection.')
            rumps.alert(title='Connection Error', message='Service unavailable\n'
                                                          'Please, check your internet connection')
开发者ID:Egregors,项目名称:pySplash,代码行数:33,代码来源:splsh.py

示例6: set_desktop_background

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def set_desktop_background(desktop_picture_path):
    file_url = NSURL.fileURLWithPath_(desktop_picture_path)
    ws = NSWorkspace.sharedWorkspace()

    screens = NSScreen.screens()
    for screen in screens:
        ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, {}, None)
开发者ID:acannon828,项目名称:NatGeo-Downloader,代码行数:9,代码来源:downloader.py

示例7: export

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
    def export(self, canvasname, file, format='pdf', force=False, is_checksum=False):
        """
        Exports one canvas named {@code canvasname}
        """

        format = format.lower()

        chksum = None
        if os.path.isfile(file) and not force:
            existing_chksum = checksum(file) if format != 'pdf' \
                                             else checksum_pdf(file)
            new_chksum = self.compute_canvas_checksum(canvasname)

            if existing_chksum == new_chksum and existing_chksum != None:
                logging.debug('No exporting - canvas %s not changed' % 
                              canvasname)
                return False
            else:
                chksum = new_chksum

        elif format == 'pdf':
            chksum = self.compute_canvas_checksum(canvasname)

        win = self.og.windows.first()

        canvas = [c for c in self.doc.canvases() if c.name() == canvasname]
        if len(canvas) == 1:
            canvas = canvas[0]
        else:
            logging.warn('Canvas %s does not exist in %s' % 
                         (canvasname, self.schemafile))
            return False

        self.og.set(win.canvas, to=canvas)

        export_format = OmniGraffleSchema.EXPORT_FORMATS[format]
        if (export_format == None):
            self.doc.save(in_=file)
        else:
            self.doc.save(as_=export_format, in_=file)

        if not is_checksum and self.options.verbose:
            print "%s" % file

        logging.debug("Exported `%s' into `%s' as %s" % (canvasname, file, format))

        if format == 'pdf':
            # save the checksum
            url = NSURL.fileURLWithPath_(file)
            pdfdoc = PDFKit.PDFDocument.alloc().initWithURL_(url)
            attrs = NSMutableDictionary.alloc().initWithDictionary_(pdfdoc.documentAttributes())

            attrs[PDFKit.PDFDocumentSubjectAttribute] = \
                '%s%s' % (OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE, chksum)

            pdfdoc.setDocumentAttributes_(attrs)
            pdfdoc.writeToFile_(file)

        return True
开发者ID:nhooey,项目名称:omnigraffle-export,代码行数:61,代码来源:__init__.py

示例8: update_appcast

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def update_appcast(oldVersion, newVersion, appcastSignature, tarballName, fileSize, minimumSystemVersion, download_url):
    
    appcastDate = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())

    # creating this from a string is easier than manipulating NSXMLNodes...
    newItemString = """<?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"  xmlns:dc="http://purl.org/dc/elements/1.1/">
       <channel>
       <item>
            <title>Version """ + newVersion + """</title>
            <description>
    	    <h3>Changes Since """ + str(oldVersion) + """</h3>
    	        <li></li>
    	        <li></li>
            </description>
            <pubDate>""" + appcastDate + """</pubDate>
            <sparkle:minimumSystemVersion>""" + minimumSystemVersion + """</sparkle:minimumSystemVersion>
            <enclosure url=\"""" + download_url + """\" sparkle:version=\"""" + newVersion + """\" length=\"""" + fileSize + """\" type="application/octet-stream" sparkle:dsaSignature=\"""" + appcastSignature + """\" />
        </item>
        </channel>
    </rss>"""

    # read from the source directory
    appcastURL = NSURL.fileURLWithPath_(APPCAST_PATH)

    # xml doc from the current appcast
    (oldDoc, error) = NSXMLDocument.alloc().initWithContentsOfURL_options_error_(appcastURL, 0, None)
    assert oldDoc is not None, error

    # xml doc from the new appcast string
    (newDoc, error) = NSXMLDocument.alloc().initWithXMLString_options_error_(newItemString, 0, None)
    assert newDoc is not None, error

    # get an arry of the current item titles
    (oldTitles, error) = oldDoc.nodesForXPath_error_("//item/title", None)
    assert oldTitles.count > 0, "oldTitles had no elements"

    # now get the title we just created
    (newTitles, error) = newDoc.nodesForXPath_error_("//item/title", None)
    assert newTitles.count() is 1, "newTitles must have a single element"

    # easy test to avoid duplicating items
    if oldTitles.containsObject_(newTitles.lastObject()) is False:

        # get the parent node we'll be inserting to
        (parentChannel, error) = oldDoc.nodesForXPath_error_("//channel", None)
        assert parentChannel.count() is 1, "channel count must be one"
        parentChannel = parentChannel.lastObject()

        # now get the new node
        (newNodes, error) = newDoc.nodesForXPath_error_("//item", None)
        assert newNodes is not None, error

        # insert a copy of the new node
        parentChannel.addChild_(newNodes.lastObject().copy())

        # write to NSData, since pretty printing didn't work with NSXMLDocument writing
        oldDoc.XMLDataWithOptions_(NSXMLNodePrettyPrint).writeToURL_atomically_(appcastURL, True)
开发者ID:amaxwell,项目名称:tlutility,代码行数:60,代码来源:build_tlu.py

示例9: renderTemplate

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def renderTemplate(webView: WebView, name: str, **values):
    html = render_template(name, **values)
    frame = webView.mainFrame()
    resource_path = os.environ.get('RESOURCEPATH', os.path.dirname(__file__))
    logger.debug('resource_path = %r', resource_path)
    baseUrl = NSURL.fileURLWithPath_(
        os.path.join(resource_path, 'static', '')
    )
    frame.loadHTMLString_baseURL_(html, baseUrl)
开发者ID:earthreader,项目名称:mac,代码行数:11,代码来源:main.py

示例10: removePage

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def removePage(filename):
	filename = filename.decode('utf-8')
	pdfURL = NSURL.fileURLWithPath_(filename)
	pdfDoc = PDFDocument.alloc().initWithURL_(pdfURL)
	if pdfDoc:
		pageNum = pdfDoc.pageCount()
		if pageNum > 1:
			pdfDoc.removePageAtIndex_(0)
			pdfDoc.writeToFile_(filename)
	return
开发者ID:benwiggy,项目名称:PDFsuite,代码行数:12,代码来源:removePage.py

示例11: setBackgroundOSX

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def setBackgroundOSX(fullPath):
    # generate a fileURL for the desktop picture
    file_path = NSURL.fileURLWithPath_(fullPath)
    # get shared workspace
    ws = NSWorkspace.sharedWorkspace()
    # iterate over all screens
    for screen in NSScreen.screens():
        # tell the workspace to set the desktop picture
        (result, error) = ws.setDesktopImageURL_forScreen_options_error_(
            file_path, screen, {}, None)
开发者ID:jasonmc,项目名称:cabin-porn,代码行数:12,代码来源:cabin-porn-it.py

示例12: set_wallpaper_image

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def set_wallpaper_image(imgs, mode='stretched'):
    """Set the given file as wallpaper."""
    if not len(imgs):
        return

    default_image = imgs[0]
    file_url = NSURL.fileURLWithPath_(default_image)
    options = {}
    ws = NSWorkspace.sharedWorkspace()
    for screen in NSScreen.screens():
      (result, error) = ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, options, None)
开发者ID:HappySolo,项目名称:Wallpaper-Downloader-and-Rotator-for-Gnome,代码行数:13,代码来源:macos.py

示例13: checksum_pdf

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def checksum_pdf(filepath):
    assert os.path.isfile(filepath), '%s is not a file' % filepath

    url = NSURL.fileURLWithPath_(filepath)
    pdfdoc = PDFKit.PDFDocument.alloc().initWithURL_(url)
    assert pdfdoc != None
    chksum = pdfdoc.documentAttributes()[PDFKit.PDFDocumentSubjectAttribute]

    if not chksum.startswith(OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE):
        return None
    else:
        return chksum[len(OmniGraffleSchema.PDF_CHECKSUM_ATTRIBUTE):]
开发者ID:sjlehtin,项目名称:omnigraffle-export,代码行数:14,代码来源:omnigraffle_export.py

示例14: checkLock

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def checkLock(infile):
	pdfURL = NSURL.fileURLWithPath_(infile)
	myPDF = Quartz.PDFDocument.alloc().initWithURL_(pdfURL)
	if myPDF:
		if myPDF.isLocked:
			print "Locked"
			password = getTextFromDialog()
			if myPDF.unlockWithPassword_(password):
				print infile, "Unlocked!"
			else:
				print "Unable to unlock", infile
	else:
		print "No PDF data retrieved from", infile
开发者ID:benwiggy,项目名称:PDFsuite,代码行数:15,代码来源:password.py

示例15: getDocInfo

# 需要导入模块: from Foundation import NSURL [as 别名]
# 或者: from Foundation.NSURL import fileURLWithPath_ [as 别名]
def getDocInfo(file):
	file = file.decode('utf-8')
	pdfURL = NSURL.fileURLWithPath_(file)
	pdfDoc = Quartz.PDFDocument.alloc().initWithURL_(pdfURL)
	if pdfDoc:
		metadata = pdfDoc.documentAttributes()
	if "Keywords" in metadata:
		keys = metadata["Keywords"]
		mutableMetadata = metadata.mutableCopy()
		mutableMetadata["Keywords"] = tuple(keys)
		return mutableMetadata
	else:
		return metadata
开发者ID:benwiggy,项目名称:PDFsuite,代码行数:15,代码来源:graphpaper.py


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