Esempio n. 1
0
    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)
Esempio n. 2
0
    def initializeStatusBar(self):
        _log(self)
        self.nsstatusitem = NSStatusBar.systemStatusBar(
        ).statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)
        self.mainmenu = NSMenu.alloc().init()
        self.nsstatusitem.setMenu_(
            self.mainmenu)  # mainmenu of our status bar spot
        self.quit = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'terminate:', '')

        _log(self.mainmenu)

        if self._app['_icon'] is not None:
            self.setStatusBarIcon()
            _log('creating icon')
            if self._app['_title'] is not None:
                self.setStatusBarTitle()
        else:
            self.setStatusBarTitle()

        if self._app['_menu'] is not None:
            for item in self._app['_menu'].itervalues():
                self.mainmenu.addItem_(
                    item()
                )  # calling works for separators and getting NSMenuItem from MenuItem objs
        self.mainmenu.addItem_(self.quit)
Esempio n. 3
0
	def applicationDidFinishLaunching_(self, notification):

		icon = NSImage.alloc().initByReferencingFile_('images/[email protected]')
		icon.setScalesWhenResized_(True)
		icon.setSize_((20, 20))

		self.status_item = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
		self.status_item.setImage_(icon)
		self.status_item.setHighlightMode_(True)

		menu = NSMenu.alloc().init()
		self.toggle_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Toggle lights', 'toggle:', '')
		menu.addItem_(self.toggle_item)
		self.status_item.setMenu_(menu)

		self.lights = lifx.get_lights()
		self.toggle_item.setState_(self.lights[0].power)

		submenu =  NSMenu.alloc().init()
		item =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'Colours', '', '')
		item.setSubmenu_( submenu )
		menu.addItem_( item )
		subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'White', 'setColour:', '')
		subitem.setRepresentedObject_( 'White' )
		submenu.addItem_( subitem )
		subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'Bright White', 'setColour:', '')
		subitem.setRepresentedObject_( 'BrightWhite' )
		submenu.addItem_( subitem )
		subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'Red', 'setColour:', '')
		subitem.setRepresentedObject_( 'Red' )
		submenu.addItem_( subitem )
		subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'Green', 'setColour:', '')
		subitem.setRepresentedObject_( 'Green' )
		submenu.addItem_( subitem )
		subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'Blue', 'setColour:', '')
		subitem.setRepresentedObject_( 'Blue' )
		submenu.addItem_( subitem )

		for bulb in self.lights:
			bulb.get_info()
			submenu =  NSMenu.alloc().init()
			#name =  bulb.get_addr()
			#bulb.get_label()
			name = bulb.bulb_label
			item =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( name, '', '')
			item.setSubmenu_( submenu )
			menu.addItem_( item )
			subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'Toggle light', 'toggleBulb:', '')
			subitem.setRepresentedObject_( bulb )
			subitem.setState_(bulb.power)
			submenu.addItem_( subitem )
			subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'Soft light', 'softBulb:', '')
			subitem.setRepresentedObject_( bulb )
			submenu.addItem_( subitem )
			subitem =  NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( 'bright light', 'brightBulb:', '')
			subitem.setRepresentedObject_( bulb )
			submenu.addItem_( subitem )

		quit_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
		menu.addItem_(quit_item)
Esempio n. 4
0
    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)
Esempio n. 5
0
  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()
Esempio n. 6
0
    def applicationDidFinishLaunching_(self, _n):
        self.statusbar = NSStatusBar.systemStatusBar()

        self.statusitem = self.statusbar.statusItemWithLength_(NSVariableStatusItemLength)
        self.image = NSImage.alloc().initByReferencingFile_("mydock.icns")
        for i in self.toggles:
            self.toggle_images[i] = NSImage.alloc().initByReferencingFile_(i+".png")

        #self.statusitem.setTitle_(u"Set up %s" % NAME)
        self.statusitem.setImage_(self.image)
        self.statusitem.setHighlightMode_(1)
        self.statusitem.setToolTip_("Docker tray tool")


        self.menu = NSMenu.alloc().init()

        # menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Kill', 'killornot:', '')
        # menuitem.setState_(NSOnState if not self.kill else NSOffState)
        # self.menu.addItem_(menuitem)

        # menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Docker instances', 'instances:', '')
        # self.menu.addItem_(menuitem)
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
        self.menu.addItem_(menuitem)

        self.statusitem.setMenu_(self.menu)

        # Get config if there is any
        self.restore_config()

        #print("interval: %s" % self.interval)
        self.timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(start_time, self.interval, self, 'loop:', None, True)
        getattr(self, self.loop_func)("Bs?")
    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()
Esempio n. 8
0
            def initializeStatusBar(self):
                self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # noqa
                self.nsstatusitem.setHighlightMode_(True)
                # This does not seem to work, we'll display a menu item instead
                # self.nsstatusitem.setToolTip_('KeyCounter')

                self.setStatusBarTitle()
                self._init_menu()
Esempio n. 9
0
 def _setup_status_bar(self):
     """
     Set up the status bar in the Mac menu
     """
     self.status = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
     self.status.setMenu_(self.status_menu)
     self.status.setTitle_("Core")
     self.status.setHighlightMode_(objc.YES)
Esempio n. 10
0
            def initializeStatusBar(self):
                self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # noqa
                self.nsstatusitem.setHighlightMode_(True)
                # This does not seem to work, we'll display a menu item instead
                # self.nsstatusitem.setToolTip_('KeyCounter')

                self.setStatusBarTitle()
                self._init_menu()
Esempio n. 11
0
 def _setup_status_bar(self):
     """
     Set up the status bar in the Mac menu
     """
     self.status = NSStatusBar.systemStatusBar().statusItemWithLength_(
         NSVariableStatusItemLength)
     self.status.setMenu_(self.status_menu)
     self.status.setTitle_("Core")
     self.status.setHighlightMode_(objc.YES)
Esempio n. 12
0
    def applicationDidFinishLaunching_(self, notification):
        # load icon files
        self.active_image = NSImage.imageNamed_("active")
        self.inactive_image = NSImage.imageNamed_("inactive")

        # 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)

        proxyRef = SCNetworkServiceCopyProtocol(self.service,
                                                kSCNetworkProtocolTypeProxies)
        prefDict = SCNetworkProtocolGetConfiguration(proxyRef)

        hasProxies = False

        # For each of the proxies 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.proxies.values():
            enabled = CFDictionaryGetValue(prefDict, proxy['pref'])
            if enabled is not None:
                proxy[
                    'menuitem'] = self.menu.addItemWithTitle_action_keyEquivalent_(
                        proxy['title'], proxy['action'],
                        proxy['keyEquivalent'])
                hasProxies = True
            else:
                proxy['menuitem'] = None

        if hasProxies:
            self.menu.addItem_(NSMenuItem.separatorItem())
            self.enableallmi = self.menu.addItemWithTitle_action_keyEquivalent_(
                'Enable All', 'enableall', '')
            self.disableallmi = self.menu.addItemWithTitle_action_keyEquivalent_(
                'Disable All', 'disableall', '')
            self.menu.addItem_(NSMenuItem.separatorItem())

        # Need a way to quit
        self.menu.addItemWithTitle_action_keyEquivalent_(
            "Quit", "quitApp:", "")

        # Start working
        # self.loadNetworkServices()
        self.watchForProxyChanges()
        self.updateProxyStatus()
Esempio n. 13
0
    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)
Esempio n. 14
0
    def finishLaunching(self):
        # Make statusbar item
        statusbar = NSStatusBar.systemStatusBar()
        self.statusitem = statusbar.statusItemWithLength_(
            NSVariableStatusItemLength)
        self.icon = NSImage.alloc().initByReferencingFile_('icon.png')
        self.icon.setScalesWhenResized_(True)
        self.icon.setSize_((20, 20))
        self.statusitem.setImage_(self.icon)

        self.initialize_menu()
Esempio n. 15
0
    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()
Esempio n. 16
0
    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()
Esempio n. 17
0
    def initWithTrayIcon_usingXUI_(self, tray_icon, using_xui):
        self = super(TrayIconView, self).init()
        if self is None:
            return
        try:
            defaults = NSUserDefaults.standardUserDefaults()
            if defaults.boolForKey_('NSGrayBackground'):
                defaults.setBool_forKey_(0, 'NSGrayBackground')
                assert not defaults.boolForKey_('NSGrayBackground'), "User has NSGrayBackground set in their defaults, and changing it didn't work"
        except Exception:
            unhandled_exc_handler()

        try:
            self.canDisplayBadgeCount = using_xui
            self.badgeCount = 0
            self.shouldDrawAttentionRequest = False
            self.setupImages()
            self.setupLayers()
            self.tray_icon = tray_icon
            self.tray_icon_has_images = True
            self.menu_is_visible = False
            self.flashing_state = None
            self.flash_timer = None
            self.busy_timer = None
            self._menu = None
            self.updateIcon_(TrayController.CONNECTING)
            self.updateMenu_(())
            try:
                self.status_item = NSStatusBar.systemStatusBar().statusItemWithLength_(self.desiredWidth())
            except Exception:
                try:
                    defaults = NSUserDefaults.standardUserDefaults()
                except Exception:
                    unhandled_exc_handler()
                else:
                    if defaults.boolForKey_('NSGrayBackground'):
                        raise Exception("User has NSGrayBackground set in their defaults (and we couldn't fix it to not affect the NSStatusItem)")
                    else:
                        raise

                unhandled_exc_handler()
            else:
                self.status_item.setView_(self)
                NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, self.windowDidMove_, NSWindowDidMoveNotification, self.window())

        except Exception:
            self.tray_icon_has_images = False
            unhandled_exc_handler()

        return self
Esempio n. 18
0
    def applicationDidFinishLaunching_(self, notification):
        self._menu_items = {}

        self.statusbar = NSStatusBar.systemStatusBar()
        self._create_statusitem()
        self._create_menu()
        self._create_timer()

        self._syncing_icon_timer = None
        self._last_icon = None

        # sync on boot
        self.change_icon('inactive')
        app.get().sync(now=True)
Esempio n. 19
0
    def initializeStatusBar(self):
        self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)

        self.setStatusBarIcon()
        self.setStatusBarTitle()

        self._init_popover()
        return
    
        if self._app.get("_menu"):
            self._init_menu()
        else:
            self._init_popover()
Esempio n. 20
0
    def applicationDidFinishLaunching_(self, notification):
        self._menu_items = {}

        self.statusbar = NSStatusBar.systemStatusBar()
        self._create_statusitem()
        self._create_menu()
        self._create_timer()

        self._syncing_icon_timer = None
        self._last_icon = None

        # sync on boot
        self.change_icon('inactive')
        app.get().sync(now=True)
Esempio n. 21
0
    def finishLaunching(self):
        # Get current track info
        curr_track = get_current_track()

        self.lyrics = get_lyrics(curr_track['curr_artist'],
                                 curr_track['curr_song']).split('<br>')

        # Remove empty lines
        self.lyrics = [x for x in self.lyrics if x]

        # Cache current track to avoid unnecessary requests
        self.curr_track_hash = abs(hash(curr_track['curr_track_full'])) % (10**
                                                                           8)

        # Create the status & menu bar
        statusBar = NSStatusBar.systemStatusBar()
        self.statusItem = statusBar.statusItemWithLength_(-1)
        self.statusItem.setTitle_(curr_track['curr_track_full'])

        self.menuBar = NSMenu.alloc().init()

        # Lyrics block
        for i, row in enumerate(self.lyrics):
            row = re.sub('<[^<]+?>', '', row).strip()
            setattr(
                self, 'row_{}'.format(i),
                NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
                    row, 'doNothing:', ''))
            self.menuBar.addItem_(getattr(self, 'row_{}'.format(i)))

        self.SEPERATOR = NSMenuItem.separatorItem()
        self.menuBar.addItem_(self.SEPERATOR)

        # Quit option
        self.QUIT = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'terminate:', '')
        self.SEPERATOR = NSMenuItem.separatorItem()
        self.menuBar.addItem_(self.SEPERATOR)
        self.menuBar.addItem_(self.QUIT)

        # Add menu to status bar
        self.statusItem.setMenu_(self.menuBar)

        # Create our timer for song title updates
        self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
            1, self, 'update:', '', True)

        # Add our timer to the runloop
        NSRunLoop.currentRunLoop().addTimer_forMode_(
            self.timer, NSEventTrackingRunLoopMode)
Esempio n. 22
0
def start_taskbar():
    t = NSStatusBar.systemStatusBar()
    icon = t.statusItemWithLength_(NSVariableStatusItemLength)
    icon.setHighlightMode_(1)
    menuitems = []
    labels = ["Open", "Logout", "Quit"]
    if patch.current.current == "DEV" or patch.config.branch == "master":
        labels = ["Open", "Logout", "Restart", "Test", "Quit"]
    for label in labels:
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            localize._X(label),
            label.lower().replace(" ", "").split(" ")[0] + ":", "")

        iconpath = os.path.join(settings.menuiconfolder,
                                label.lower() + ".icns")
        if os.path.exists(iconpath):
            img = NSImage.alloc().initByReferencingFile_(iconpath)
            img.setSize_(NSSize(16, 16))
            item.setImage_(img)
        menuitems.append(item)

    menu = NSMenu.alloc().init()
    menu.setAutoenablesItems_(True)
    icon.setMenu_(menu)
    for m in menuitems:
        menu.addItem_(m)

    def set_image(path):
        taskbarimg = NSImage.alloc().initByReferencingFile_(path)
        taskbarimg.setSize_(NSSize(18, 18))
        icon.setImage_(taskbarimg)

    # taskbar icon switching
    @event.register("api:connected")
    def set_active(*_):
        set_image(settings.taskbaricon)

    @event.register("api:disconnected")
    @event.register("api:connection_error")
    def set_inactive(*_):
        set_image(settings.taskbaricon_inactive)

    set_image(settings.taskbaricon_inactive)
    icon.setEnabled_(True)

    @login.config.register('username')
    def _():
        item = menu.itemAtIndex_(0)
        item.setTitle_(login.config.username or "Open")
Esempio n. 23
0
    def initializeStatusBar(self):
        self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)

        if self._app['_icon'] is not None:
            self.setStatusBarIcon()
            _log('creating icon')
            if self._app['_title'] is not None:
                self.setStatusBarTitle()
        else:
            self.setStatusBarTitle()

        mainmenu = self._app['_menu']
        mainmenu.add('Quit')
        mainmenu['Quit']._menuitem.setAction_('terminate:')  # _menuitem attribute is NSMenuItem
        self.nsstatusitem.setMenu_(mainmenu._menu)  # mainmenu of our status bar spot (_menu attribute is NSMenu)
Esempio n. 24
0
    def finishLaunching(self):
        # Make statusbar item
        statusbar = NSStatusBar.systemStatusBar()
        self.statusitem = statusbar.statusItemWithLength_(NSVariableStatusItemLength)
        self.icon = NSImage.alloc().initByReferencingFile_('icon.png')
        self.icon.setScalesWhenResized_(True)
        self.icon.setSize_((20, 20))
        self.statusitem.setImage_(self.icon)
        self._schedules = []
        self._menu_items = []

        self._initialize_schedules()
        self._initialize_menu()

        self._timer = Timer(60, self.timer_callback)
        self._timer.start()
Esempio n. 25
0
    def initializeStatusBar(self):
        self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)

        if self._app["_icon"] is not None:
            self.setStatusBarIcon()
            _log("creating icon")
            if self._app["_title"] is not None:
                self.setStatusBarTitle()
        else:
            self.setStatusBarTitle()

        mainmenu = self._app["_menu"]
        mainmenu.add("Quit")
        mainmenu["Quit"]._menuitem.setAction_("terminate:")  # _menuitem attribute is NSMenuItem
        self.nsstatusitem.setMenu_(mainmenu._menu)  # mainmenu of our status bar spot (_menu attribute is NSMenu)
Esempio n. 26
0
    def initializeStatusBar(self):
        self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)

        self.setStatusBarIcon()
        self.setStatusBarTitle()

        mainmenu = self._app['_menu']
        quit_button = self._app['_quit_button']
        if quit_button is not None:
            quit_button.set_callback(quit_application)
            mainmenu.add(quit_button)
        else:
            _log('WARNING: the default quit button is disabled. To exit the application gracefully, another button '
                 'should have a callback of quit_application or call it indirectly.')
        self.nsstatusitem.setMenu_(mainmenu._menu)  # mainmenu of our status bar spot (_menu attribute is NSMenu)
Esempio n. 27
0
    def initializeStatusBar(self):
        self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)

        self.setStatusBarIcon()
        self.setStatusBarTitle()

        mainmenu = self._app['_menu']
        quit_button = self._app['_quit_button']
        if quit_button is not None:
            quit_button.set_callback(quit_application)
            mainmenu.add(quit_button)
        else:
            _log('WARNING: the default quit button is disabled. To exit the application gracefully, another button '
                 'should have a callback of quit_application or call it indirectly.')
        self.nsstatusitem.setMenu_(mainmenu._menu)  # mainmenu of our status bar spot (_menu attribute is NSMenu)
Esempio n. 28
0
    def initializeStatusBar(self):
        self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)

        if self._app['_icon'] is not None:
            self.setStatusBarIcon()
            _log('creating icon')
            if self._app['_title'] is not None:
                self.setStatusBarTitle()
        else:
            self.setStatusBarTitle()

        mainmenu = self._app['_menu']
        mainmenu.add('Quit')
        mainmenu['Quit']._menuitem.setAction_('terminate:')  # _menuitem attribute is NSMenuItem
        self.nsstatusitem.setMenu_(mainmenu._menu)  # mainmenu of our status bar spot (_menu attribute is NSMenu)
Esempio n. 29
0
def start_taskbar():
    t = NSStatusBar.systemStatusBar()
    icon = t.statusItemWithLength_(NSVariableStatusItemLength)
    icon.setHighlightMode_(1)
    menuitems = []
    labels = ["Open", "Logout", "Quit"]
    if patch.current.current == "DEV" or patch.config.branch == "master":
        labels = ["Open", "Logout", "Restart", "Test", "Quit"]
    for label in labels:
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            localize._X(label), label.lower().replace(" ", "").split(" ")[0]+":", "")
            
        iconpath = os.path.join(settings.menuiconfolder, label.lower() + ".icns")
        if os.path.exists(iconpath):
            img = NSImage.alloc().initByReferencingFile_(iconpath)
            img.setSize_(NSSize(16, 16))
            item.setImage_(img)
        menuitems.append(item)
    
    menu = NSMenu.alloc().init()
    menu.setAutoenablesItems_(True)
    icon.setMenu_(menu)
    for m in menuitems:
        menu.addItem_(m)
        
    def set_image(path):
        taskbarimg = NSImage.alloc().initByReferencingFile_(path)
        taskbarimg.setSize_(NSSize(18, 18))
        icon.setImage_(taskbarimg)
        
    # taskbar icon switching
    @event.register("api:connected")
    def set_active(*_):
        set_image(settings.taskbaricon)

    @event.register("api:disconnected")
    @event.register("api:connection_error")
    def set_inactive(*_):
        set_image(settings.taskbaricon_inactive)
    
    set_image(settings.taskbaricon_inactive)
    icon.setEnabled_(True)
    
    @login.config.register('username')
    def _():
        item = menu.itemAtIndex_(0)
        item.setTitle_(login.config.username or "Open")
Esempio n. 30
0
    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();
Esempio n. 31
0
    def _setup_menu_bar(self):
        """Setup the menu bar of the app."""
        self.main_menu = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)
        self.menuBar = NSMenu.alloc().init()

        # [f for f in dir(NSButton) if 'Title' in f]
        self.button = self.main_menu.button
        self.update_(None)

        # Menu items
        quit_menu = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Quit", "terminate:", "")

        # Add items to the menuBar
        self.menuBar.addItem_(quit_menu)

        # Add menu to status bar
        self.main_menu.setMenu_(self.menuBar)
Esempio n. 32
0
 def applicationDidFinishLaunching_(self, notification):
     global start_time
     statusbar = NSStatusBar.systemStatusBar()
     # Create the statusbar item
     self.statusitem = statusbar.statusItemWithLength_(70.0)
     # Set initial image
     self.statusitem.setTitle_(self.updateGeektime())
     # Let it highlight upon clicking
     self.statusitem.setHighlightMode_(1)
     
     self.menu = NSMenu.alloc().init()
     menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
     self.menu.addItem_(menuitem)
     self.statusitem.setMenu_(self.menu)
     
     self.timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(start_time, 0.65, self, 'tick:', None, True)
     NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
     self.timer.fire()
Esempio n. 33
0
def start_taskbar():
    t = NSStatusBar.systemStatusBar()
    icon = t.statusItemWithLength_(NSVariableStatusItemLength)
    icon.setHighlightMode_(1)

    def update_tooltip():
        text = common.generate_tooltip_text()
        icon.setToolTip_(text)
        gevent.spawn_later(5, update_tooltip)

    gevent.spawn_later(5, update_tooltip)

    def set_image(path):
        taskbarimg = NSImage.alloc().initByReferencingFile_(path)
        taskbarimg.setSize_(NSSize(18, 18))
        icon.setImage_(taskbarimg)

    # taskbar icon switching
    @event.register("api:connected")
    def set_active(*_):
        set_image(settings.taskbaricon)

    @event.register("api:disconnected")
    @event.register("api:connection_error")
    def set_inactive(*_):
        set_image(settings.taskbaricon_inactive)

    set_image(settings.taskbaricon_inactive)
    icon.setEnabled_(True)

    @event.register('login:changed')
    def login_changed(*_):
        opts = ["Open"]
        if login.is_guest() or not login.has_login():
            opts.append("Login")
            opts.append("Register")
        elif login.has_login():
            opts.append("Logout")
        else:
            opts.append("Register")
        opts.append("Quit")
        icon.setMenu_(build_menu(opts))

    login_changed()
Esempio n. 34
0
    def update_(self, timer):
        curr_track = get_current_track()
        self.statusItem.setTitle_(curr_track['curr_track_full'])
        self.next_track_hash = abs(hash(curr_track['curr_track_full'])) % (10**
                                                                           8)

        if self.curr_track_hash != self.next_track_hash:
            self.lyrics = get_lyrics(curr_track['curr_artist'],
                                     curr_track['curr_song']).split('<br>')

            # Remove empty lines
            self.lyrics = [x for x in self.lyrics if x]
            self.curr_track_hash = abs(hash(
                curr_track['curr_track_full'])) % (10**8)

            # Create the status & menu bar
            statusBar = NSStatusBar.systemStatusBar()
            self.statusItem = statusBar.statusItemWithLength_(-1)
            self.statusItem.setTitle_(curr_track['curr_track_full'])

            self.menuBar = NSMenu.alloc().init()

            # Lyrics block
            for i, row in enumerate(self.lyrics):
                row = re.sub('<[^<]+?>', '', row).strip()
                setattr(
                    self, 'row_{}'.format(i),
                    NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
                        row, 'doNothing:', ''))
                self.menuBar.addItem_(getattr(self, 'row_{}'.format(i)))

            self.SEPERATOR = NSMenuItem.separatorItem()
            self.menuBar.addItem_(self.SEPERATOR)

            # Quit option
            self.QUIT = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
                'Quit', 'terminate:', '')
            self.SEPERATOR = NSMenuItem.separatorItem()
            self.menuBar.addItem_(self.SEPERATOR)
            self.menuBar.addItem_(self.QUIT)

            # Add menu to status bar
            self.statusItem.setMenu_(self.menuBar)
Esempio n. 35
0
def start_taskbar():
    t = NSStatusBar.systemStatusBar()
    icon = t.statusItemWithLength_(NSVariableStatusItemLength)
    icon.setHighlightMode_(1)

    def update_tooltip():
        text = common.generate_tooltip_text()
        icon.setToolTip_(text)
        gevent.spawn_later(5, update_tooltip)
    gevent.spawn_later(5, update_tooltip)
        
    def set_image(path):
        taskbarimg = NSImage.alloc().initByReferencingFile_(path)
        taskbarimg.setSize_(NSSize(18, 18))
        icon.setImage_(taskbarimg)
        
    # taskbar icon switching
    @event.register("api:connected")
    def set_active(*_):
        set_image(settings.taskbaricon)

    @event.register("api:disconnected")
    @event.register("api:connection_error")
    def set_inactive(*_):
        set_image(settings.taskbaricon_inactive)
    
    set_image(settings.taskbaricon_inactive)
    icon.setEnabled_(True)
    
    @event.register('login:changed')
    def login_changed(*_):
        opts = ["Open"]
        if login.is_guest() or not login.has_login():
            opts.append("Login")
            opts.append("Register")
        elif login.has_login():
            opts.append("Logout")
        else:
            opts.append("Register")
        opts.append("Quit")
        icon.setMenu_(build_menu(opts))
    
    login_changed()
Esempio n. 36
0
    def applicationDidFinishLaunching_(self, notification):

        icon = NSImage.alloc().initByReferencingFile_("images/[email protected]")
        icon.setScalesWhenResized_(True)
        icon.setSize_((20, 20))

        self.status_item = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
        self.status_item.setImage_(icon)
        self.status_item.setHighlightMode_(True)

        menu = NSMenu.alloc().init()
        self.toggle_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Toggle lights", "toggle:", "")
        menu.addItem_(self.toggle_item)
        quit_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Quit", "terminate:", "")
        menu.addItem_(quit_item)
        self.status_item.setMenu_(menu)

        self.lights = lifx.get_lights()
        self.toggle_item.setState_(self.lights[0].power)
Esempio n. 37
0
    def create_ui(self):
        icon = NSImage.alloc().initByReferencingFile_('main.icns')
        icon.setScalesWhenResized_(True)
        icon.setSize_((20, 20))
        self.menu = NSMenu.alloc().init()

        configureMenuItem = NSMenuItem.alloc(
        ).initWithTitle_action_keyEquivalent_('Configure', 'clickedConfigure:',
                                              '')
        self.menu.addItem_(configureMenuItem)

        quit = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'terminate:', '')
        self.menu.addItem_(quit)

        self.nsstatusitem = NSStatusBar.systemStatusBar(
        ).statusItemWithLength_(NSVariableStatusItemLength)
        self.nsstatusitem.setImage_(icon)
        self.nsstatusitem.setHighlightMode_(True)
        self.nsstatusitem.setMenu_(self.menu)
Esempio n. 38
0
    def finishLaunching(self):
        # Make statusbar item
        statusbar = NSStatusBar.systemStatusBar()
        self.statusitem = statusbar.statusItemWithLength_(NSVariableStatusItemLength)
        self.icon = NSImage.alloc().initByReferencingFile_('icon.png')
        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_('Click Me', 'clicked:', '')
        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_('My App')
Esempio n. 39
0
    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)
Esempio n. 40
0
    def initializeStatusBar(self):
        _log(self)
        self.nsstatusitem = NSStatusBar.systemStatusBar().statusItemWithLength_(-1)  # variable dimensions
        self.nsstatusitem.setHighlightMode_(True)
        self.mainmenu = NSMenu.alloc().init()
        self.nsstatusitem.setMenu_(self.mainmenu)  # mainmenu of our status bar spot
        self.quit = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')

        _log(self.mainmenu)

        if self._app['_icon'] is not None:
            self.setStatusBarIcon()
            _log('creating icon')
            if self._app['_title'] is not None:
                self.setStatusBarTitle()
        else:
            self.setStatusBarTitle()

        if self._app['_menu'] is not None:
            for item in self._app['_menu'].itervalues():
                self.mainmenu.addItem_(item())  # calling works for separators and getting NSMenuItem from MenuItem objs
        self.mainmenu.addItem_(self.quit)
Esempio n. 41
0
    def finishLaunching(self):
        # Make statusbar item
        statusbar = NSStatusBar.systemStatusBar()
        self.statusitem = statusbar.statusItemWithLength_(NSVariableStatusItemLength)
        self.icon = NSImage.alloc().initByReferencingFile_("icon.png")
        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_("Test Notification", "clicked:", "")
        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_("My App")
        self._notify_obj = Notification.alloc().init()
Esempio n. 42
0
    def applicationDidFinishLaunching_(self, notification):
        self.native.activateIgnoringOtherApps(True)
        self.statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
        self.statusItem.setHighlightMode_(True)
        self.statusItem.setEnabled_(True)

        self.icon = NSImage.alloc().initByReferencingFile_("resources/app.icns")
        self.icon.setSize_((20,20))
        self.statusItem.setImage_(self.icon)

        self.menu = NSMenu.alloc().init()

        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Check For Updates", "update:", "")
        self.menu.addItem_(item)
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Open Website", "website:", "")
        self.menu.addItem_(item)
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("About", "about:", "")
        self.menu.addItem_(item)
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Quit", "quit:", "")
        self.menu.addItem_(item)

        self.statusItem.setMenu_(self.menu)
Esempio n. 43
0
    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)
Esempio n. 44
0
    def finishLaunching(self):

        # Note: variable names here are camelCased to stay consistent with
        # pyobjc (except menubar items).

        # Create the status & menu bar
        statusBar = NSStatusBar.systemStatusBar()
        self.statusItem = statusBar.statusItemWithLength_(-1)
        self.statusItem.setTitle_('Simon')
        self.menuBar = NSMenu.alloc().init()

        # System
        self.SYSTEM = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'System', 'doNothing:', '')
        self.CPU_USAGE = self._create_empty_menu_item()
        self.RAM_USAGE = self._create_empty_menu_item()
        self.RAM_AVAILABLE = self._create_empty_menu_item()

        self.menuBar.addItem_(self.SYSTEM)
        self.menuBar.addItem_(self.CPU_USAGE)
        self.menuBar.addItem_(self.RAM_USAGE)
        self.menuBar.addItem_(self.RAM_AVAILABLE)

        # Disk I/O
        self.DISKIO = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Disk I/O', 'doNothing:', '')
        self.DATA_READ = self._create_empty_menu_item()
        self.DATA_WRITTEN = self._create_empty_menu_item()

        self.menuBar.addItem_(self.DISKIO)
        self.menuBar.addItem_(self.DATA_READ)
        self.menuBar.addItem_(self.DATA_WRITTEN)

        # Network
        self.NETWORK = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Network', 'doNothing:', '')
        self.NETWORK_RECV = self._create_empty_menu_item()
        self.NETWORK_SENT = self._create_empty_menu_item()

        self.menuBar.addItem_(self.NETWORK)
        self.menuBar.addItem_(self.NETWORK_RECV)
        self.menuBar.addItem_(self.NETWORK_SENT)

        # Quit
        self.QUIT = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'terminate:', '')
        self.SEPERATOR = NSMenuItem.separatorItem()
        self.menuBar.addItem_(self.SEPERATOR)
        self.menuBar.addItem_(self.QUIT)

        # Add menu to status bar
        self.statusItem.setMenu_(self.menuBar)

        # Create our timer
        self.timer = \
            NSTimer \
            .scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                1, self, 'update:', '', True
            )

        # Add our timer to the runloop
        NSRunLoop.currentRunLoop().addTimer_forMode_(
            self.timer, NSEventTrackingRunLoopMode)

        print('Simon is now running.')
        print('CTRL+C does not work here.')
        print('You can quit through the menubar.')
Esempio n. 45
0
 def hide(self):
     TRACE('Hiding status item')
     NSStatusBar.systemStatusBar().removeStatusItem_(self.status_item)
Esempio n. 46
0
    def applicationDidFinishLaunching_(self, notification):

        icon = NSImage.alloc().initByReferencingFile_(
            'images/[email protected]')
        icon.setScalesWhenResized_(True)
        icon.setSize_((20, 20))

        self.status_item = NSStatusBar.systemStatusBar().statusItemWithLength_(
            NSVariableStatusItemLength)
        self.status_item.setImage_(icon)
        self.status_item.setHighlightMode_(True)

        menu = NSMenu.alloc().init()
        self.toggle_item = NSMenuItem.alloc(
        ).initWithTitle_action_keyEquivalent_('Toggle All Lights', 'toggle:',
                                              '')
        menu.addItem_(self.toggle_item)
        self.status_item.setMenu_(menu)

        self.lights = lifx.get_lights()
        self.toggle_item.setState_(self.lights[0].power)

        submenu = NSMenu.alloc().init()
        item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Colours', '', '')
        item.setSubmenu_(submenu)
        menu.addItem_(item)
        subitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'White', 'setColour:', '')
        subitem.setRepresentedObject_('White')
        submenu.addItem_(subitem)
        subitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Red', 'setColour:', '')
        subitem.setRepresentedObject_('Red')
        submenu.addItem_(subitem)
        subitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Green', 'setColour:', '')
        subitem.setRepresentedObject_('Green')
        submenu.addItem_(subitem)
        subitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Blue', 'setColour:', '')
        subitem.setRepresentedObject_('Blue')
        submenu.addItem_(subitem)

        menu.addItem_(NSMenuItem.separatorItem())

        for bulb in self.lights:
            submenu = NSMenu.alloc().init()
            name = bulb.bulb_label or bulb.get_addr()
            item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
                name, '', '')
            item.setSubmenu_(submenu)
            menu.addItem_(item)
            subitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
                'Toggle Light', 'toggleBulb:', '')
            subitem.setRepresentedObject_(bulb)
            subitem.setState_(bulb.power)
            submenu.addItem_(subitem)

        menu.addItem_(NSMenuItem.separatorItem())

        quit_item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'terminate:', '')
        menu.addItem_(quit_item)
Esempio n. 47
0
    def _setup_menuBar(self):
        statusBar = NSStatusBar.systemStatusBar()
        self.statusItem = statusBar.statusItemWithLength_(-1)
        self.menuBar = NSMenu.alloc().init()

        self.statusItem.setTitle_('Simon')

        # Labels/buttons
        self.SYSTEM = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'System', 'doNothing:', '')
        self.DISKIO = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Disk I/O', 'doNothing:', '')
        self.NETWORK = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Network', 'doNothing:', '')
        self.QUIT = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
            'Quit', 'terminate:', '')

        # System
        self.CPU_USAGE = self._create_empty_menu_item()
        self.RAM_USAGE = self._create_empty_menu_item()
        self.RAM_AVAILABLE = self._create_empty_menu_item()

        # Disk I/O
        self.DATA_READ = self._create_empty_menu_item()
        self.DATA_WRITTEN = self._create_empty_menu_item()

        # Network
        self.NETWORK_RECV = self._create_empty_menu_item()
        self.NETWORK_SENT = self._create_empty_menu_item()
        '''
        Add our items to the menuBar - yields the following output:

        Simon
            System
                CPU Usage
                RAM Usage
                Available Memory
            Disk I/O
                Read
                Written
            Network
                Received
                Sent
            -----------------------
            Quit
        '''
        self.menuBar.addItem_(self.SYSTEM)  # system label
        self.menuBar.addItem_(self.CPU_USAGE)
        self.menuBar.addItem_(self.RAM_USAGE)
        self.menuBar.addItem_(self.RAM_AVAILABLE)

        self.menuBar.addItem_(self.DISKIO)  # disk I/O label
        self.menuBar.addItem_(self.DATA_READ)
        self.menuBar.addItem_(self.DATA_WRITTEN)

        self.menuBar.addItem_(self.NETWORK)  # network label
        self.menuBar.addItem_(self.NETWORK_RECV)
        self.menuBar.addItem_(self.NETWORK_SENT)

        self.menuBar.addItem_(NSMenuItem.separatorItem())  # seperator
        self.menuBar.addItem_(self.QUIT)  # quit button

        # Add menu to status bar
        self.statusItem.setMenu_(self.menuBar)
Esempio n. 48
0
    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)