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


Python AppKit.NSMenuItem类代码示例

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


在下文中一共展示了NSMenuItem类的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.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

示例3: inject

    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
开发者ID:GLOP1978,项目名称:quotefixformac,代码行数:31,代码来源:menu.py

示例4: 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

示例5: _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

示例6: 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

示例7: 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

示例8: 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

示例9: _initialize_menu

    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')
开发者ID:smartstudy,项目名称:project_cron,代码行数:15,代码来源:main.py

示例10: initialize

    def initialize(cls):
        # Register ourselves as a Mail.app plugin and add an entry for our
        # 'Fill Text' and Wrap Text' actions to the Edit menu.

        application = NSApplication.sharedApplication()
        bundle = NSBundle.bundleWithIdentifier_('uk.me.cdw.MailWrap')
        cls.registerBundle()

        editmenu = application.mainMenu().itemAtIndex_(2).submenu()
        editmenu.addItem_(NSMenuItem.separatorItem())

        mask = NSCommandKeyMask | NSAlternateKeyMask
        editmenu.addItemWithTitle_action_keyEquivalent_('Fill Text',
            'fillText', '\\').setKeyEquivalentModifierMask_(mask)

        mask = NSCommandKeyMask
        editmenu.addItemWithTitle_action_keyEquivalent_('Wrap Text',
            'wrapText', "\\").setKeyEquivalentModifierMask_(mask)

        # Read our configuration settings if present. Otherwise, set the
        # correct default values.

        defaults = NSUserDefaults.standardUserDefaults()
        defaults = defaults.dictionaryForKey_('MailWrap') or {}
        ComposeViewController._fixAttribution = defaults.get('FixAttribution', False)
        EditingMessageWebView._bulletLists = defaults.get('BulletLists', True)
        EditingMessageWebView._indentWidth = int(defaults.get('IndentWidth', 2))
        EditingMessageWebView._wrapWidth = int(defaults.get('WrapWidth', 72))

        # Report the plugin name and version to the com.apple.mail log.

        version = bundle.objectForInfoDictionaryKey_('CFBundleVersion')
        NSLog('Loaded MailWrap %s' % version)
开发者ID:javigon,项目名称:mailwrap,代码行数:33,代码来源:MailWrap.py

示例11: constructMenu

    def constructMenu(self):
        self.menu.removeAllItems()

        separator_required = False
        if self.is_ip_assigned:
            # For each of the proxyTypes we are concerned with, check to see if any
            # are configured. If so (even if not enabled), create a menuitem for
            # that proxy type.
            for proxy in self.proxyTypes.values():
                enabled = CFDictionaryGetValue(self.prefDict, proxy['prefEnable'])
                if enabled is not None:
                    proxy['menuitem'] = self.menu.addItemWithTitle_action_keyEquivalent_(
                        proxy['title'],
                        proxy['action'],
                        proxy['keyEquivalent']
                    )
                    separator_required = True
                else:
                    proxy['menuitem'] = None
        else:
            self.menu.addItemWithTitle_action_keyEquivalent_("No connection - Please connect to any network before using this tool", None, "")

        if separator_required:
            self.menu.addItem_(NSMenuItem.separatorItem())

         # Need a way to quit
        self.menu.addItemWithTitle_action_keyEquivalent_("Quit", "quitApp:", "q")
开发者ID:arnaudruffin,项目名称:OsxProxyToggler,代码行数:27,代码来源:ToggleProxy.py

示例12: __init__

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

示例13: addToolbarItem

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
开发者ID:muelli,项目名称:CalDAVClientLibrary,代码行数:31,代码来源:WebDAVBrowser.py

示例14: 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

示例15: _getGlyphMenuItem

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


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