本文整理汇总了Python中AppKit.NSMenuItem.alloc方法的典型用法代码示例。如果您正苦于以下问题:Python NSMenuItem.alloc方法的具体用法?Python NSMenuItem.alloc怎么用?Python NSMenuItem.alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSMenuItem
的用法示例。
在下文中一共展示了NSMenuItem.alloc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: applicationDidFinishLaunching_
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def applicationDidFinishLaunching_(self, notification):
self.statusbar = NSStatusBar.systemStatusBar()
# Create the statusbar item
self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength)
# Set initial image
raw_data = base64.b64decode(''.join(GOAGENT_ICON_DATA.strip().splitlines()))
self.image_data = NSData.dataWithBytes_length_(raw_data, len(raw_data))
self.image = NSImage.alloc().initWithData_(self.image_data)
self.statusitem.setImage_(self.image)
# Let it highlight upon clicking
self.statusitem.setHighlightMode_(1)
# Set a tooltip
self.statusitem.setToolTip_('GoAgent OSX')
# Build a very simple menu
self.menu = NSMenu.alloc().init()
# Show Menu Item
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Show', 'show:', '')
self.menu.addItem_(menuitem)
# Hide Menu Item
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Hide', 'hide:', '')
self.menu.addItem_(menuitem)
# Rest Menu Item
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Reset', 'reset:', '')
self.menu.addItem_(menuitem)
# Default event
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
self.menu.addItem_(menuitem)
# Bind it to the status item
self.statusitem.setMenu_(self.menu)
示例2: _create_menu
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def _create_menu(self):
self.menu = NSMenu.alloc().init()
self.menu.setAutoenablesItems_(False)
self.trayicon.setMenu_(self.menu)
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
'Status: loading', '', '')
menuitem.setEnabled_(False)
self._menu_items['status'] = menuitem
self.menu.addItem_(menuitem)
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
'Sync now', 'sync:', '')
menuitem.setEnabled_(False)
self._menu_items['sync'] = menuitem
self.menu.addItem_(menuitem)
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
'Resolve conflicts', 'resolve:', '')
menuitem.setEnabled_(False)
self._menu_items['resolve'] = menuitem
self.menu.addItem_(menuitem)
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
app.get().status == interfaces.STATUS_DISABLED \
and 'Enable' or 'Disable',
'enabledisable:', '')
self._menu_items['enable_disable'] = menuitem
self.menu.addItem_(menuitem)
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
'Quit', 'terminate:', '')
self._menu_items['quit'] = menuitem
self.menu.addItem_(menuitem)
示例3: applicationDidFinishLaunching_
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def applicationDidFinishLaunching_(self, notification):
self.noDevice = None
#Create menu
self.menu = NSMenu.alloc().init()
self.barItem = dict()
# Load images
self.noDeviceImage = NSImage.alloc().initByReferencingFile_('icons/no_device.png')
self.barImage = dict(kb = NSImage.alloc().initByReferencingFile_('icons/kb.png'),
magicMouse = NSImage.alloc().initByReferencingFile_('icons/magic_mouse.png'),
mightyMouse = NSImage.alloc().initByReferencingFile_('icons/mighty_mouse.png'),
magicTrackpad = NSImage.alloc().initByReferencingFile_('icons/TrackpadIcon.png'))
#Define menu items
self.statusbar = NSStatusBar.systemStatusBar()
self.menuAbout = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('About BtBatStat', 'about:', '')
self.separator_menu_item = NSMenuItem.separatorItem()
self.menuQuit = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
# Get the timer going
self.timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(start_time, 10.0, self, 'tick:', None, True)
NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
self.timer.fire()
#Add menu items
self.menu.addItem_(self.menuAbout)
self.menu.addItem_(self.separator_menu_item)
self.menu.addItem_(self.menuQuit)
#Check for updates
checkForUpdates()
示例4: setupWindowMenu
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def setupWindowMenu():
windowMenu = NSMenu.alloc().initWithTitle_('Window')
menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Minimize', 'performMiniaturize:', 'm')
windowMenu.addItem_(menuItem)
del menuItem
windowMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Window', None, '')
windowMenuItem.setSubmenu_(windowMenu)
NSApp().mainMenu().addItem_(windowMenuItem)
NSApp().setWindowsMenu_(windowMenu)
示例5: setupUI
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def setupUI(self):
self.statusbar = NSStatusBar.systemStatusBar()
# Create the statusbar item
self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength)
# Set initial image
raw_data = base64.b64decode(''.join(GOAGENT_ICON_DATA.strip().splitlines()))
self.image_data = NSData.dataWithBytes_length_(raw_data, len(raw_data))
self.image = NSImage.alloc().initWithData_(self.image_data)
self.statusitem.setImage_(self.image)
# Let it highlight upon clicking
self.statusitem.setHighlightMode_(1)
# Set a tooltip
self.statusitem.setToolTip_(GOAGENT_TITLE)
# Build a very simple menu
self.menu = NSMenu.alloc().init()
# Show Menu Item
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Show', 'show:', '')
self.menu.addItem_(menuitem)
# Hide Menu Item
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Hide', 'hide2:', '')
self.menu.addItem_(menuitem)
# Rest Menu Item
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Reload', 'reset:', '')
self.menu.addItem_(menuitem)
# Default event
menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'exit:', '')
self.menu.addItem_(menuitem)
# Bind it to the status item
self.statusitem.setMenu_(self.menu)
# Console window
frame = NSMakeRect(0,0,550,350)
self.console_window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(frame, NSClosableWindowMask|NSTitledWindowMask, NSBackingStoreBuffered, False)
self.console_window.setTitle_(GOAGENT_TITLE)
self.console_window.setDelegate_(self)
# Console view inside a scrollview
self.scroll_view = NSScrollView.alloc().initWithFrame_(frame)
self.scroll_view.setBorderType_(NSNoBorder)
self.scroll_view.setHasVerticalScroller_(True)
self.scroll_view.setHasHorizontalScroller_(False)
self.scroll_view.setAutoresizingMask_(NSViewWidthSizable|NSViewHeightSizable)
self.console_view = NSTextView.alloc().initWithFrame_(frame)
self.console_view.setVerticallyResizable_(True)
self.console_view.setHorizontallyResizable_(True)
self.console_view.setAutoresizingMask_(NSViewWidthSizable)
self.scroll_view.setDocumentView_(self.console_view)
contentView = self.console_window.contentView()
contentView.addSubview_(self.scroll_view)
# Hide dock icon
NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
示例6: finishLaunching
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def finishLaunching(self):
# Make statusbar item
statusbar = NSStatusBar.systemStatusBar()
self.statusitem = statusbar.statusItemWithLength_(
NSVariableStatusItemLength)
# Thanks Matthias Kretschmann
# at http://kremalicious.com/coffee-cup-icon/
icon_path = NSBundle.mainBundle()\
.pathForResource_ofType_(
ICON_BASE, ICON_EXT)
if not icon_path:
icon_path = ICON_FILE
self.icon = NSImage.alloc()\
.initByReferencingFile_(icon_path)
self.icon.setScalesWhenResized_(True)
self.icon.setSize_((20, 20))
self.statusitem.setImage_(self.icon)
# Make the menu
self.menubarMenu = NSMenu.alloc().init()
self.menuItem = NSMenuItem.alloc()\
.initWithTitle_action_keyEquivalent_(
'Connect', 'connectAndCloseCNA:', '')
self.menubarMenu.addItem_(self.menuItem)
self.quit = NSMenuItem.alloc()\
.initWithTitle_action_keyEquivalent_(
'Quit', 'terminate:', '')
self.menubarMenu.addItem_(self.quit)
# Add menu to statusitem
self.statusitem.setMenu_(self.menubarMenu)
self.statusitem.setToolTip_('Cartel')
self.statusitem.setHighlightMode_(True)
# Get the default notification center.
self.workspace = NSWorkspace.sharedWorkspace()
self.default_center = NSNotificationCenter.defaultCenter()
# Create the handler
self.rhandler = ReachabilityHandler.new()
self.rhandler.app = self
self.default_center.addObserver_selector_name_object_(
self.rhandler,
"handleChange:",
kReachabilityChangedNotification,
None)
# Create the reachability object and start notifactions.
self.reachability = Reachability()
self.reachability.startNotifier()
示例7: _initialize_menu
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def _initialize_menu(self):
self.menubarMenu = NSMenu.alloc().init()
for schedule in self._schedules:
menu_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(schedule.name, 'execute:', '')
self._menu_items.append(menu_item)
self.menubarMenu.addItem_(menu_item)
menu_item = NSMenuItem.separatorItem()
self.menubarMenu.addItem_(menu_item)
self.quit = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
self.menubarMenu.addItem_(self.quit)
self.statusitem.setMenu_(self.menubarMenu)
self.statusitem.setToolTip_('Crow')
示例8: inject
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def inject(self):
try:
# necessary because of the menu callbacks
self.retain()
# get application menu instance
appmenu = NSApplication.sharedApplication().mainMenu().itemAtIndex_(0).submenu()
# make a new menu item
self.item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
"QuoteFix",
"toggleState:",
"")
self.item.setToolTip_(self.get_string("QUOTEFIX_TOOLTIP", ""))
self.set_state_and_title(self.item)
self.item.setTarget_(self)
# add separator and new item
appmenu.insertItem_atIndex_(NSMenuItem.separatorItem(), 1)
appmenu.insertItem_atIndex_(self.item, 2)
# observe changes for active state
NSUserDefaultsController.sharedUserDefaultsController().addObserver_forKeyPath_options_context_(
self,
"values.QuoteFixDisabled",
NSKeyValueObservingOptionNew,
None
)
except Exception, e:
raise e
示例9: __init__
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def __init__(self, title, callback=None, key='', icon=None, dimensions=None):
self._menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(str(title), None, '')
if callable(callback):
self.set_callback(callback, key)
self._submenu = self._icon = None
self.set_icon(icon, dimensions)
super(MenuItem, self).__init__()
示例10: addToolbarItem
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def addToolbarItem(aController, anIdentifier, aLabel, aPaletteLabel,
aToolTip, aTarget, anAction, anItemContent, aMenu):
"""
Add a toolbar button of some kind.
"""
toolbarItem = NSToolbarItem.alloc().initWithItemIdentifier_(anIdentifier)
toolbarItem.setLabel_(aLabel)
toolbarItem.setPaletteLabel_(aPaletteLabel)
toolbarItem.setToolTip_(aToolTip)
toolbarItem.setTarget_(aTarget)
if anAction:
toolbarItem.setAction_(anAction)
if type(anItemContent) == NSImage:
toolbarItem.setImage_(anItemContent)
else:
toolbarItem.setView_(anItemContent)
bounds = anItemContent.bounds()
minSize = (bounds[1][0], bounds[1][1])
maxSize = (bounds[1][0], bounds[1][1])
toolbarItem.setMinSize_(minSize)
toolbarItem.setMaxSize_(maxSize)
if aMenu:
menuItem = NSMenuItem.alloc().init()
menuItem.setSubmenu_(aMenu)
menuItem.setTitle_(aMenu.title())
toolbarItem.setMenuFormRepresentation_(menuItem)
aController._toolbarItems[anIdentifier] = toolbarItem
示例11: setupStatusBar
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [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();
示例12: setupAppleMenu
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def setupAppleMenu():
appleMenuController = objc.lookUpClass('NSAppleMenuController').alloc().init()
appleMenu = NSMenu.alloc().initWithTitle_('')
appleMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('', None, '')
appleMenuItem.setSubmenu_(appleMenu)
NSApp().mainMenu().addItem_(appleMenuItem)
appleMenuController.controlMenu_(appleMenu)
NSApp().mainMenu().removeItem_(appleMenuItem)
示例13: _init_menu
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def _init_menu(self):
menu = NSMenu.alloc().init()
# App name menu
appname_menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( # noqa
u'{} {}'.format(unicode(sc.name), sc.version), None, ''
)
menu.addItem_(appname_menuitem)
# Quit menu
# action `xxx:` will bind to `xxx_` method of delegate
quit_menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( # noqa
unicode('Quit'), 'quit:', 'q'
)
quit_menuitem.setTarget_(sc)
menu.addItem_(quit_menuitem)
self.nsstatusitem.setMenu_(menu)
示例14: __init__
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def __init__(self, title, callback=None, key='', icon=None, dimensions=None):
if isinstance(title, MenuItem): # don't initialize already existing instances
return
self._menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(str(title), None, '')
if callable(callback):
self.set_callback(callback, key)
self._menu = self._icon = None
self.set_icon(icon, dimensions)
super(MenuItem, self).__init__()
示例15: _getGlyphMenuItem
# 需要导入模块: from AppKit import NSMenuItem [as 别名]
# 或者: from AppKit.NSMenuItem import alloc [as 别名]
def _getGlyphMenuItem(self, glyph):
name = glyph.name
menuItem = NSMenuItem.alloc().init()
image = glyph.getRepresentation("defconAppKit.MenuImage")
menuItem.setImage_(image)
menuItem.setTitle_(name)
menuItem.setTarget_(self)
menuItem.setAction_("_dummyAction:")
return menuItem