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


Python AppKit.NSMenu类代码示例

本文整理汇总了Python中AppKit.NSMenu的典型用法代码示例。如果您正苦于以下问题:Python NSMenu类的具体用法?Python NSMenu怎么用?Python NSMenu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setupUI

    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)
开发者ID:barrabinfc,项目名称:ZeroNet,代码行数:34,代码来源:tray_osx.py

示例2: applicationDidFinishLaunching_

  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()
开发者ID:Ku2f,项目名称:btbatstat,代码行数:33,代码来源:BtBatStat.py

示例3: _create_menu

    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)
开发者ID:jone,项目名称:unison-tray,代码行数:34,代码来源:tray.py

示例4: __init__

 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
开发者ID:karlmatthew,项目名称:pygtk-craigslist,代码行数:7,代码来源:Menu.py

示例5: applicationDidFinishLaunching_

    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)
开发者ID:SkyRaker,项目名称:GoAgentX,代码行数:30,代码来源:goagent-osx.py

示例6: applicationDidFinishLaunching_

    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()
开发者ID:arnaudruffin,项目名称:OsxProxyToggler,代码行数:30,代码来源:ToggleProxy.py

示例7: setupAppleMenu

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)
开发者ID:deavid,项目名称:soyamirror,代码行数:8,代码来源:macosx.py

示例8: setupStatusBar

    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();
开发者ID:Mondego,项目名称:pyreco,代码行数:46,代码来源:allPythonContent.py

示例9: setupWindowMenu

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)
开发者ID:deavid,项目名称:soyamirror,代码行数:9,代码来源:macosx.py

示例10: setupUI

    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)
开发者ID:0ks3ii,项目名称:GoAgentX,代码行数:56,代码来源:goagent-osx.py

示例11: setItems

 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)
开发者ID:LettError,项目名称:vanilla,代码行数:10,代码来源:vanillaPopUpButton.py

示例12: __setitem__

    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)
开发者ID:mjhea0,项目名称:rumps,代码行数:11,代码来源:rumps.py

示例13: _makeMenuForGlyphRecord

 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
开发者ID:andyclymer,项目名称:defconAppKit,代码行数:12,代码来源:glyphLineView.py

示例14: finishLaunching

    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()
开发者ID:jmatt,项目名称:cartel,代码行数:53,代码来源:cartel.py

示例15: executeVanillaTest

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()
开发者ID:schriftgestalt,项目名称:vanilla,代码行数:39,代码来源:testTools.py


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