(filename, dimensions=None)
return image
Takes a path to an image file and returns an NSImage object.
Takes a path to an image file and returns an NSImage object.
Takes a path to an image file and returns an NSImage object .
def _nsimage_from_file(filename, dimensions=None):
    """
    Takes a path to an image file and returns an NSImage object.
    """
    try:
        _log('attempting to open image at {}'.format(filename))
        with open(filename):
            pass
    except IOError:  # literal file path didn't work -- try to locate image based on main script path
        try:
            from __main__ import __file__ as main_script_path
            main_script_path = os.path.dirname(main_script_path)
            filename = os.path.join(main_script_path, filename)
        except ImportError:
            pass
        _log('attempting (again) to open image at {}'.format(filename))
        with open(filename):  # file doesn't exist
            pass              # otherwise silently errors in NSImage which isn't helpful for debugging
    image = NSImage.alloc().initByReferencingFile_(filename)
    image.setScalesWhenResized_(True)
    image.setSize_((20, 20) if dimensions is None else dimensions)
    return image
def _nsimage_from_file ( filename , dimensions = None ) : try : _log ( 'attempting to open image at {}' . format ( filename ) ) with open ( filename ) : pass except IOError : # literal file path didn't work -- try to locate image based on main script path try : from __main__ import __file__ as main_script_path main_script_path = os . path . dirname ( main_script_path ) filename = os . path . join ( main_script_path , filename ) except ImportError : pass _log ( 'attempting (again) to open image at {}' . format ( filename ) ) with open ( filename ) : # file doesn't exist pass # otherwise silently errors in NSImage which isn't helpful for debugging image = NSImage . alloc ( ) . initByReferencingFile_ ( filename ) image . setScalesWhenResized_ ( True ) image . setSize_ ( ( 20 , 20 ) if dimensions is None else dimensions ) return image