本文整理汇总了Python中AppKit.NSMenu.alloc方法的典型用法代码示例。如果您正苦于以下问题:Python NSMenu.alloc方法的具体用法?Python NSMenu.alloc怎么用?Python NSMenu.alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSMenu
的用法示例。
在下文中一共展示了NSMenu.alloc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupUI
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu import alloc [as 别名]
def setupUI(self):
self.statusbar = NSStatusBar.systemStatusBar()
self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength) #NSSquareStatusItemLength #NSVariableStatusItemLength
# Set initial image icon
icon_path = os.path.join(current_path, "../trayicon.ico")
image = NSImage.alloc().initByReferencingFile_(icon_path)
image.setScalesWhenResized_(True)
image.setSize_((20, 20))
self.statusitem.setImage_(image)
# Let it highlight upon clicking
self.statusitem.setHighlightMode_(1)
self.statusitem.setToolTip_("ZeroNet")
# Build a very simple menu
self.menu = NSMenu.alloc().init()
self.menu.setAutoenablesItems_(False)
#self.create_menu_item( 'ip_external', 'IP: %s' % INFO['ip_external'], 'info:')
self.menu.addItem_( NSMenuItem.separatorItem() )
# Links
self.create_menu_item( 'open_zeronet', 'Open ZeroNet', 'open:')
self.create_menu_item( 'open_reddit', 'Zeronet Reddit Community', 'openreddit:')
self.create_menu_item( 'open_gh', 'Report issues/feature requests', 'opengithub:')
self.menu.addItem_( NSMenuItem.separatorItem() )
self.create_menu_item( 'quit_zeronet', 'Quit ZeroNet', 'windowWillClose:' )
# Bind it to the status item and hide dock icon
self.statusitem.setMenu_(self.menu)
NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
示例2: applicationDidFinishLaunching_
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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()
示例3: _create_menu
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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)
示例4: __init__
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu import alloc [as 别名]
def __init__(self, title, items, **kwds):
#print "Menu: creating with items", items ###
GMenu.__init__(self, title, items, **kwds)
ns_menu = NSMenu.alloc().initWithTitle_(title)
ns_menu.setAutoenablesItems_(False)
ns_menu.setDelegate_(Globals.ns_application)
self._ns_menu = ns_menu
示例5: applicationDidFinishLaunching_
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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)
示例6: applicationDidFinishLaunching_
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu import alloc [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()
示例7: setupAppleMenu
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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)
示例8: setupStatusBar
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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();
示例9: setupWindowMenu
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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)
示例10: setupUI
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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)
示例11: setItems
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu import alloc [as 别名]
def setItems(self, items):
"""
Set the items to appear in the pop up list.
"""
self._callbackWrappers = []
self._nsObject.removeAllItems()
menu = NSMenu.alloc().init()
menu.addItem_(self.getFirstItem())
VanillaMenuBuilder(self, items, menu)
self._nsObject.setMenu_(menu)
示例12: __setitem__
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu import alloc [as 别名]
def __setitem__(self, key, value):
if key in self:
return
if not isinstance(value, MenuItem):
raise TypeError('values must be instances of MenuItem class; given {}'.format(type(value)))
if self._submenu is None:
self._submenu = NSMenu.alloc().init()
self._menuitem.setSubmenu_(self._submenu)
self._submenu.addItem_(value._menuitem)
super(MenuItem, self).__setitem__(key, value)
示例13: _makeMenuForGlyphRecord
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu import alloc [as 别名]
def _makeMenuForGlyphRecord(self, index):
glyphRecord = self._glyphRecords[index]
glyph = glyphRecord.glyph
font = glyph.getParent()
if font is None:
return None
menu = NSMenu.alloc().init()
for alternateName in glyphRecord.alternates:
alternate = font[alternateName]
item = self._getGlyphMenuItem(alternate)
menu.addItem_(item)
return menu
示例14: finishLaunching
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu 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()
示例15: executeVanillaTest
# 需要导入模块: from AppKit import NSMenu [as 别名]
# 或者: from AppKit.NSMenu import alloc [as 别名]
def executeVanillaTest(cls, nibPath=None, calls=None, **kwargs):
"""
Execute a Vanilla UI class in a mini application.
"""
app = NSApplication.sharedApplication()
delegate = _VanillaMiniAppDelegate.alloc().init()
app.setDelegate_(delegate)
if nibPath:
NSBundle.loadNibFile_externalNameTable_withZone_(nibPath, {}, None)
else:
mainMenu = NSMenu.alloc().initWithTitle_("Vanilla Test")
fileMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("File", None, "")
fileMenu = NSMenu.alloc().initWithTitle_("File")
fileMenuItem.setSubmenu_(fileMenu)
mainMenu.addItem_(fileMenuItem)
editMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Edit", None, "")
editMenu = NSMenu.alloc().initWithTitle_("Edit")
editMenuItem.setSubmenu_(editMenu)
mainMenu.addItem_(editMenuItem)
helpMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Help", None, "")
helpMenu = NSMenu.alloc().initWithTitle_("Help")
helpMenuItem.setSubmenu_(helpMenu)
mainMenu.addItem_(helpMenuItem)
app.setMainMenu_(mainMenu)
if cls is not None:
cls(**kwargs)
if calls is not None:
for call, kwargs in calls:
call(**kwargs)
app.activateIgnoringOtherApps_(True)
AppHelper.runEventLoop()