本文整理汇总了Python中AppKit.NSImage.imageNamed_方法的典型用法代码示例。如果您正苦于以下问题:Python NSImage.imageNamed_方法的具体用法?Python NSImage.imageNamed_怎么用?Python NSImage.imageNamed_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSImage
的用法示例。
在下文中一共展示了NSImage.imageNamed_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: applicationDidFinishLaunching_
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def applicationDidFinishLaunching_(self, notification):
#activate logging with ToggleProxy -logging 1
self.shouldLog = NSUserDefaults.standardUserDefaults().boolForKey_("logging")
# load icon files
self.active_image = NSImage.imageNamed_("StatusBarImage")
self.inactive_image = NSImage.imageNamed_("StatusBarImage-inactive")
self.no_network_image = NSImage.imageNamed_("StatusBarImage-noNetwork")
self.active_image.setTemplate_(True)
self.inactive_image.setTemplate_(True)
self.no_network_image.setTemplate_(True)
# make status bar item
self.statusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
self.statusitem.retain()
self.statusitem.setHighlightMode_(False)
self.statusitem.setEnabled_(True)
# insert a menu into the status bar item
self.menu = NSMenu.alloc().init()
self.statusitem.setMenu_(self.menu)
# open connection to the dynamic (configuration) store
self.store = SCDynamicStoreCreate(None, "name.klep.toggleproxy", self.dynamicStoreCallback, None)
self.prefDict = SCNetworkProtocolGetConfiguration(SCNetworkServiceCopyProtocol(self.service, kSCNetworkProtocolTypeProxies))
self.constructMenu()
self.watchForProxyOrIpChanges()
self.updateUI()
self.setEnvVariables()
示例2: __init__
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def __init__(self, posSize,
imagePath=None, imageNamed=None, imageObject=None,
title=None, bordered=True, imagePosition="top", callback=None, sizeStyle="regular"):
super(ImageButton, self).__init__(posSize, title=title, callback=callback, sizeStyle=sizeStyle)
image = None
if imagePath is not None:
image = NSImage.alloc().initWithContentsOfFile_(imagePath)
elif imageNamed is not None:
image = NSImage.imageNamed_(imageNamed)
elif imageObject is not None:
image = imageObject
if image is not None:
self._nsObject.setImage_(image)
self._nsObject.setBordered_(bordered)
if title is None:
position = NSImageOnly
else:
position= _imagePositionMap[imagePosition]
if imagePosition == "left":
self._nsObject.setAlignment_(NSRightTextAlignment)
elif imagePosition == "right":
self._nsObject.setAlignment_(NSLeftTextAlignment)
if not bordered:
self._nsObject.cell().setHighlightsBy_(NSNoCellMask)
self._nsObject.setImagePosition_(position)
示例3: openSplash
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def openSplash():
global splash
splash = NSWindow.alloc()
rect = NSMakeRect(0,0,240,420)
styleMask = 0
splash.initWithContentRect_styleMask_backing_defer_(rect, styleMask, NSBackingStoreBuffered, False)
# http://stackoverflow.com/questions/19437580/splash-screen-in-osx-cocoa-app
splashImage = NSImageView.alloc().initWithFrame_(rect)
splashImage.setImageScaling_(NSScaleToFit)
splashImage.setImage_(NSImage.imageNamed_('ottosplash.png'))
#[customView addSubview:splashImage];
#splash.setContentView_(webview)
splash.setContentView_(splashImage)
splash.setHasShadow_(True)
splash.setOpaque_(False)
splash.setBackgroundColor_(NSColor.clearColor())
# xPos = NSWidth([[splashWindow screen] frame])/2 - NSWidth([splashWindow frame])/2;
#CGFloat yPos = NSHeight([[splashWindow screen] frame])/2 - NSHeight([splashWindow frame])/2;
#[splashWindow setFrame:NSMakeRect(xPos, yPos, NSWidth([splashWindow frame]), NSHeight([splashWindow frame])) display:YES];
splash.center()
splash.orderFrontRegardless()
示例4: __init__
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def __init__(self, posSize, segmentDescriptions, callback=None, selectionStyle="one", sizeStyle="small"):
self._setupView(self.nsSegmentedControlClass, posSize)
if self.nsSegmentedCellClass != NSSegmentedCell:
self._nsObject.setCell_(self.nsSegmentedCellClass.alloc().init())
if callback is not None:
self._setCallback(callback)
self._setSizeStyle(sizeStyle)
nsObject = self._nsObject
nsObject.setSegmentCount_(len(segmentDescriptions))
nsObject.cell().setTrackingMode_(_trackingModeMap[selectionStyle])
for segmentIndex, segmentDescription in enumerate(segmentDescriptions):
width = segmentDescription.get("width", 0)
title = segmentDescription.get("title", "")
enabled = segmentDescription.get("enabled", True)
imagePath = segmentDescription.get("imagePath")
imageNamed = segmentDescription.get("imageNamed")
imageTemplate = segmentDescription.get("imageTemplate")
imageObject = segmentDescription.get("imageObject")
# create the NSImage if needed
if imagePath is not None:
image = NSImage.alloc().initWithContentsOfFile_(imagePath)
elif imageNamed is not None:
image = NSImage.imageNamed_(imageNamed)
elif imageObject is not None:
image = imageObject
else:
image = None
nsObject.setWidth_forSegment_(width, segmentIndex)
nsObject.setLabel_forSegment_(title, segmentIndex)
nsObject.setEnabled_forSegment_(enabled, segmentIndex)
if image is not None:
if imageTemplate is not None:
# only change the image template setting if its either True or False
image.setTemplate_(imageTemplate)
nsObject.setImage_forSegment_(image, segmentIndex)
示例5: setupStatusBar
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def setupStatusBar(self):
statusbar = NSStatusBar.systemStatusBar()
statusitem = statusbar.statusItemWithLength_(20).retain()
icon = NSImage.imageNamed_('status')
icon.setSize_((20, 20))
statusitem.setImage_(icon)
iconHighlight = NSImage.imageNamed_('status-hi')
iconHighlight.setSize_((20, 20))
statusitem.setAlternateImage_(iconHighlight)
statusitem.setHighlightMode_(1)
# TODO: Put this whole menu creation stuff into interface builder!
menu = NSMenu.alloc().init()
linkMenu = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Post a Link', 'doLink:', '')
linkMenu.setTarget_(self);
# Make it possible to invoke the link menu via a keyboard shortcut.
linkMenu.setKeyEquivalentModifierMask_(NSShiftKeyMask | NSCommandKeyMask)
linkMenu.setKeyEquivalent_('l')
menu.addItem_(linkMenu)
menu.addItem_(NSMenuItem.separatorItem())
previewMenu = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Update Preview', 'doPreview:', '')
previewMenu.setTarget_(self);
menu.addItem_(previewMenu)
publishMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Publish', None, '')
publishMenu = NSMenu.alloc().init();
s3MenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('S3', 'doPublish:', '')
s3MenuItem.setTarget_(self);
publishMenu.addItem_(s3MenuItem)
publishMenuItem.setSubmenu_(publishMenu)
menu.addItem_(publishMenuItem)
menu.addItem_(NSMenuItem.separatorItem())
quitMenu = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
menu.addItem_(quitMenu)
statusitem.setMenu_(menu)
menu.release();
示例6: refreshWithSender_
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def refreshWithSender_(self, sender):
if self.crawlTask is not None:
return self.stopRefreshWithSender_(sender)
logger.debug('%r refreshWithSender:%r', self, sender)
sender.setImage_(NSImage.imageNamed_(NSImageNameStopProgressTemplate))
self.crawlTask = NSThread.alloc().initWithTarget_selector_object_(
self, 'crawlWithSender:', sender
)
self.crawlTask.start()
示例7: _createToolbarItem
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def _createToolbarItem(self, itemData):
itemIdentifier = itemData.get("itemIdentifier")
if itemIdentifier is None:
raise VanillaError("toolbar item data must contain a unique itemIdentifier string")
if itemIdentifier in self._toolbarItems:
raise VanillaError("toolbar itemIdentifier is not unique: %r" % itemIdentifier)
if itemIdentifier not in self._toolbarAllowedItemIdentifiers:
self._toolbarAllowedItemIdentifiers.append(itemIdentifier)
if itemData.get("visibleByDefault", True):
self._toolbarDefaultItemIdentifiers.append(itemIdentifier)
if itemIdentifier.startswith("NS"):
# no need to create an actual item for a standard Cocoa toolbar item
return
label = itemData.get("label")
paletteLabel = itemData.get("paletteLabel", label)
toolTip = itemData.get("toolTip", label)
imagePath = itemData.get("imagePath")
imageNamed = itemData.get("imageNamed")
imageObject = itemData.get("imageObject")
imageTemplate = itemData.get("imageTemplate")
view = itemData.get("view")
callback = itemData.get("callback", None)
# create the NSImage if needed
if imagePath is not None:
image = NSImage.alloc().initWithContentsOfFile_(imagePath)
elif imageNamed is not None:
image = NSImage.imageNamed_(imageNamed)
elif imageObject is not None:
image = imageObject
else:
image = None
toolbarItem = NSToolbarItem.alloc().initWithItemIdentifier_(itemIdentifier)
toolbarItem.setLabel_(label)
toolbarItem.setPaletteLabel_(paletteLabel)
toolbarItem.setToolTip_(toolTip)
if image is not None:
if imageTemplate is not None:
# only change the image template setting if its either True or False
image.setTemplate_(imageTemplate)
toolbarItem.setImage_(image)
elif view is not None:
toolbarItem.setView_(view)
toolbarItem.setMinSize_(view.frame().size)
toolbarItem.setMaxSize_(view.frame().size)
if callback is not None:
target = VanillaCallbackWrapper(callback)
toolbarItem.setTarget_(target)
toolbarItem.setAction_("action:")
self._toolbarCallbackWrappers[itemIdentifier] = target
if itemData.get("selectable", False):
self._toolbarSelectableItemIdentifiers.append(itemIdentifier)
self._toolbarItems[itemIdentifier] = toolbarItem
示例8: getFirstItem
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def getFirstItem(self):
actionImage = NSImage.imageNamed_(NSImageNameActionTemplate).copy()
sizeStyle = _reverseSizeStyleMap[self._nsObject.cell().controlSize()]
if sizeStyle == "small":
actionImage.setSize_((10, 10))
elif sizeStyle == "mini":
actionImage.setSize_((10, 10))
firstActionItem = NSMenuItem.alloc().init()
firstActionItem.setImage_(actionImage)
firstActionItem.setTitle_("")
return firstActionItem
示例9: createToolbarItems
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def createToolbarItems(self):
"""
Create the toolbar item and define the default and allowed set.
"""
addToolbarItem(self, kServerToolbarItemIdentifier,
"Server", "Server", "Reset Server", self,
"resetServer:", NSImage.imageNamed_("NSNetwork"), None,)
addToolbarItem(self, kRefreshToolbarItemIdentifier,
"Refresh", "Refresh", "Refresh Display", self,
"refreshData:", NSImage.imageNamed_("NSRefresh"), None,)
addToolbarItem(self, kBrowserViewToolbarItemIdentifier,
"Browser", "Browser", "Browser View", self,
"changeBrowserView:", self.toolbarBrowserViewButton, None,)
addToolbarItem(self, kDataViewToolbarItemIdentifier,
"View", "View", "Data View", self,
"changeDataView:", self.toolbarDataViewButton, None,)
self._toolbarDefaultItemIdentifiers = [
kServerToolbarItemIdentifier,
kBrowserViewToolbarItemIdentifier,
kDataViewToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
kRefreshToolbarItemIdentifier,
]
self._toolbarAllowedItemIdentifiers = [
kServerToolbarItemIdentifier,
kBrowserViewToolbarItemIdentifier,
kDataViewToolbarItemIdentifier,
kRefreshToolbarItemIdentifier,
NSToolbarSeparatorItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarPrintItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
]
示例10: _drawDirtyStateImage
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def _drawDirtyStateImage(value):
if value:
imageName = "defconAppKitFontListDirtyStateTrue"
else:
imageName = "defconAppKitFontListDirtyStateFalse"
image = NSImage.imageNamed_(imageName)
if image is None:
# make the image
width = 13
height = 17
image = NSImage.alloc().initWithSize_((width, height))
image.lockFocus()
# draw if dirty
if value:
rect = ((2, 4), (9, 9))
path = NSBezierPath.bezierPathWithOvalInRect_(rect)
path.addClip()
# colors
color1 = NSColor.colorWithCalibratedRed_green_blue_alpha_(1.0, 0.1, 0.1, 1)
color2 = NSColor.colorWithCalibratedRed_green_blue_alpha_(0.5, 0.0, 0.0, 1)
# fill
color1.set()
path.fill()
# shadow
try:
gradient = NSGradient.alloc().initWithColors_([color1, color2])
gradient.drawInBezierPath_angle_(path, -90)
except NameError:
pass
# stroke
color2.set()
path.setLineWidth_(2)
path.stroke()
image.unlockFocus()
image.setName_(imageName)
image = NSImage.imageNamed_(imageName)
return image
示例11: setImage
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def setImage(self, imagePath=None, imageNamed=None, imageObject=None):
"""
Set the image in the button.
**imagePath** A file path to an image.
**imageNamed** The name of an image already load as a *NSImage* by the application.
**imageObject** A *NSImage* object.
*Only one of imagePath, imageNamed, imageObject should be set.*
"""
if imagePath is not None:
image = NSImage.alloc().initWithContentsOfFile_(imagePath)
elif imageNamed is not None:
image = NSImage.imageNamed_(imageNamed)
elif imageObject is not None:
image = imageObject
else:
raise ValueError("no image source defined")
self._nsObject.setImage_(image)
示例12: create_image
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def create_image(self):
image = NSImage.imageNamed_("ExtensionIcon")
self.w.image = ImageView((15, 15, 80, 80), scale="fit")
self.w.image.setImage(imageObject=image)
示例13: insertFeatureToolbarImage
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def insertFeatureToolbarImage():
im = NSImage.imageNamed_("toolbarFeatures")
return ufoApps.createToolbarIcon(im)
示例14: LevelIndicatorListCell
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def LevelIndicatorListCell(style="discrete",
minValue=0, maxValue=10, warningValue=None, criticalValue=None,
imagePath=None, imageNamed=None, imageObject=None):
"""
An object that displays a level indicator in a List column.
**This object should only be used in the *columnDescriptions* argument
during the construction of a List.**::
from vanilla import *
class LevelIndicatorListCellDemo(object):
def __init__(self):
self.w = Window((340, 140))
items = [
{"discrete": 3, "continuous": 4, "rating": 1, "relevancy": 9},
{"discrete": 8, "continuous": 3, "rating": 5, "relevancy": 5},
{"discrete": 3, "continuous": 7, "rating": 3, "relevancy": 4},
{"discrete": 2, "continuous": 5, "rating": 4, "relevancy": 7},
{"discrete": 6, "continuous": 9, "rating": 3, "relevancy": 2},
{"discrete": 4, "continuous": 0, "rating": 6, "relevancy": 8},
]
columnDescriptions = [
{"title": "discrete",
"cell": LevelIndicatorListCell(style="discrete", warningValue=7, criticalValue=9)},
{"title": "continuous",
"cell": LevelIndicatorListCell(style="continuous", warningValue=7, criticalValue=9)},
{"title": "rating",
"cell": LevelIndicatorListCell(style="rating", maxValue=6)},
{"title": "relevancy",
"cell": LevelIndicatorListCell(style="relevancy")},
]
self.w.list = List((0, 0, -0, -0), items=items,
columnDescriptions=columnDescriptions)
self.w.open()
LevelIndicatorListCellDemo()
**style** The style of the level indicator. The options are:
+--------------+-----------------------------------------+
| "continuous" | A continuous bar. |
+--------------+-----------------------------------------+
| "discrete" | A segmented bar. |
+--------------+-----------------------------------------+
| "rating" | A row of stars. Similar to the rating |
| | indicator in iTunes. |
+--------------+-----------------------------------------+
| "relevancy" | A row of lines. Similar to the search |
| | result relevancy indicator in Mail. |
+--------------+-----------------------------------------+
**minValue** The minimum value allowed by the level indicator.
**maxValue** The maximum value allowed by the level indicator.
**warningValue** The value at which the filled portions of the
level indicator should display the warning color. Applies only to
discrete and continuous level indicators.
**criticalValue** The value at which the filled portions of the
level indicator should display the critical color. Applies only to
discrete and continuous level indicators.
"""
cell = NSLevelIndicatorCell.alloc().init()
cell.setLevelIndicatorStyle_(_levelIndicatorStyleMap[style])
cell.setMinValue_(minValue)
cell.setMaxValue_(maxValue)
if warningValue is not None:
cell.setWarningValue_(warningValue)
if criticalValue is not None:
cell.setCriticalValue_(criticalValue)
if imagePath is not None:
image = NSImage.alloc().initWithContentsOfFile_(imagePath)
elif imageNamed is not None:
image = NSImage.imageNamed_(imageNamed)
elif imageObject is not None:
image = imageObject
if imageObject is not None:
cell.setImage_(image)
return cell
示例15: __init__
# 需要导入模块: from AppKit import NSImage [as 别名]
# 或者: from AppKit.NSImage import imageNamed_ [as 别名]
def __init__(self, drawGrid=False):
self.w = Window((600, 500), "List Test", minSize=(400, 400))
simpleList = List((0, 0, 0, 0), listOptions, enableTypingSensitivity=True)
multiItems = [
{"name": name, "path": os.path.basename(getattr(module, "__file__", "Unknown"))}
for name, module in sys.modules.items()
]
columnDescriptions = [
{"title": "Module Name", "key": "name"},
{"title": "File Name", "key": "path"}
]
multiList = List((0, 0, 0, 0), multiItems, columnDescriptions=columnDescriptions, enableTypingSensitivity=True)
if iconPath:
image = NSImage.alloc().initWithContentsOfFile_(iconPath)
else:
image = NSImage.imageNamed_(iconName)
miscItems = [
{"slider": 50, "sliderWithTicks" : 50, "checkBox": False, "image" : image, "segment" : 0},
{"slider": 20, "sliderWithTicks" : 20, "checkBox": True, "image" : image, "segment" : 1},
{"slider": 70, "sliderWithTicks" : 70, "checkBox": False, "image" : image, "segment" : 2},
{"slider": 20, "sliderWithTicks" : 20, "checkBox": True, "image" : image, "segment" : 0},
{"slider": 10, "sliderWithTicks" : 10, "checkBox": True, "image" : image, "segment" : 1},
{"slider": 90, "sliderWithTicks" : 90, "checkBox": False, "image" : image, "segment" : 2},
]
columnDescriptions = [
{"title": "SliderListCell", "key": "slider", "cell": SliderListCell()},
{"title": "SliderListCell", "key": "sliderWithTicks", "cell": SliderListCell(tickMarkCount=10, stopOnTickMarks=True)},
{"title": "CheckBoxListCell", "key": "checkBox", "cell": CheckBoxListCell()},
{"title": "ImageListCell", "key": "image", "cell": ImageListCell()},
{"title": "SegmentedButtonListCell", "key": "segment", "cell": SegmentedButtonListCell([dict(title="0"), dict(title="1"), dict(title="2")]), "binding": "selectedIndex"},
]
miscCellList = List((0, 0, 0, 0), items=miscItems, columnDescriptions=columnDescriptions)
paneDescriptions = [
dict(view=simpleList, identifier="simpleList"),
dict(view=multiList, identifier="multiList"),
dict(view=miscCellList, identifier="miscCellList"),
]
# only add the ListIndicator tests if the controls are available
try:
listIndicatorItems = [
{"discrete": 3, "continuous": 4, "rating": 1, "relevancy": 9},
{"discrete": 8, "continuous": 3, "rating": 5, "relevancy": 5},
{"discrete": 3, "continuous": 7, "rating": 3, "relevancy": 4},
{"discrete": 2, "continuous": 5, "rating": 4, "relevancy": 7},
{"discrete": 6, "continuous": 9, "rating": 3, "relevancy": 2},
{"discrete": 4, "continuous": 0, "rating": 6, "relevancy": 8},
]
columnDescriptions = [
{"title": "discrete",
"cell": LevelIndicatorListCell(style="discrete", warningValue=7, criticalValue=9)},
{"title": "continuous",
"cell": LevelIndicatorListCell(style="continuous", warningValue=7, criticalValue=9)},
{"title": "rating",
"cell": LevelIndicatorListCell(style="rating", maxValue=6)},
{"title": "relevancy",
"cell": LevelIndicatorListCell(style="relevancy")},
]
levelIndicatorList = List((0, 0, 0, 0), items=listIndicatorItems, columnDescriptions=columnDescriptions)
paneDescriptions.append(dict(view=levelIndicatorList, identifier="levelIndicatorList"))
except NameError:
pass
self.w.splitView = SplitView((0, 0, -0, -0), paneDescriptions, isVertical=False)
if drawGrid:
self.drawGrid()
self.w.open()