예제 #1
0
파일: tray.py 프로젝트: jone/unison-tray
 def _create_timer(self):
     timer = NSTimer.alloc() \
         .initWithFireDate_interval_target_selector_userInfo_repeats_(
         start_time, 1, self, 'tick:', None, True)
     NSRunLoop.currentRunLoop().addTimer_forMode_(
         timer, NSDefaultRunLoopMode)
     timer.fire()
예제 #2
0
 def _create_timer(self):
     timer = NSTimer.alloc() \
         .initWithFireDate_interval_target_selector_userInfo_repeats_(
         start_time, 1, self, 'tick:', None, True)
     NSRunLoop.currentRunLoop().addTimer_forMode_(timer,
                                                  NSDefaultRunLoopMode)
     timer.fire()
예제 #3
0
def gevent_timer(deleg):
    timer = NSTimer.alloc(
    ).initWithFireDate_interval_target_selector_userInfo_repeats_(
        NSDate.date(), 0.1, deleg, 'gevent:', None, True)
    NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode)
    timer.fire()
    print "started gevent timer"
예제 #4
0
 def progress(self, err):
     self.w.errorBox.set("Error: %.7f" % err)
     self.w.errorBox._nsObject.setNeedsDisplay_(True)
     pairs = len(self.prespaced["caps"]) + len(
         self.prespaced["caplower"]) + len(self.prespaced["lower"])
     self.w.bar.increment(1.0 / (3 * pairs))
     NSRunLoop.mainRunLoop().runUntilDate_(
         NSDate.dateWithTimeIntervalSinceNow_(0.0001))
예제 #5
0
    def set(self, value):
        """
        Set the value of the progress bar to **value**.

        *Only available in determinate progress bars.*
        """
        self._nsObject.setDoubleValue_(value)
        self._nsObject.display()
        if osVersionCurrent >= osVersion10_11:
            NSRunLoop.mainRunLoop().runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(0.0001))
예제 #6
0
    def increment(self, value=1):
        """
        Increment the progress bar by **value**.

        *Only available in determinate progress bars.*
        """
        self._nsObject.incrementBy_(value)
        self._nsObject.display()
        if osVersionCurrent >= osVersion10_11:
            NSRunLoop.mainRunLoop().runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(0.0001))
예제 #7
0
    def increment(self, value=1):
        """
        Increment the progress bar by **value**.

        *Only available in determinate progress bars.*
        """
        self._nsObject.incrementBy_(value)
        self._nsObject.display()
        if osVersionCurrent >= osVersion10_11:
            NSRunLoop.mainRunLoop().runUntilDate_(
                NSDate.dateWithTimeIntervalSinceNow_(0.0001))
예제 #8
0
    def set(self, value):
        """
        Set the value of the progress bar to **value**.

        *Only available in determinate progress bars.*
        """
        self._nsObject.setDoubleValue_(value)
        self._nsObject.display()
        if osVersionCurrent >= osVersion10_11:
            NSRunLoop.mainRunLoop().runUntilDate_(
                NSDate.dateWithTimeIntervalSinceNow_(0.0001))
예제 #9
0
 def setFlash_(self, on):
     if on and self.flash_timer is None:
         self.flashing_state = True
         self.flash_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(0.5, self, self.updateStatusImage_, ('flash',), True)
         self.flash_timer.fire()
         NSRunLoop.currentRunLoop().addTimer_forMode_(self.flash_timer, NSDefaultRunLoopMode)
     elif not on and self.flashing_state is not None:
         if self.flash_timer is not None:
             self.flash_timer.invalidate()
             self.flash_timer = None
             self.flashing_state = None
             self.setNeedsDisplay_(1)
예제 #10
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)
예제 #11
0
 def updateIcon_(self, icon_state):
     target_image = self.ICON_MAP.get(icon_state)
     assert target_image is not None, 'invalid icon state'
     if target_image in ('busy', 'cam'):
         self.busy_timer_image = target_image
         if self.busy_timer is None:
             self.busy_timer_state = 5
             self.busy_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(0.4, self, self.updateStatusImage_, ('busy',), True)
             self.busy_timer.fire()
             NSRunLoop.currentRunLoop().addTimer_forMode_(self.busy_timer, NSDefaultRunLoopMode)
     else:
         if self.busy_timer is not None:
             self.busy_timer.invalidate()
             self.busy_timer = None
         self.updateStatusImage_((target_image,))
예제 #12
0
    def watchForProxyChanges(self):
        """ install a watcher for proxy changes """
        SCDynamicStoreSetNotificationKeys(self.store, None,
                                          ['State:/Network/Global/Proxies'])

        source = SCDynamicStoreCreateRunLoopSource(None, self.store, 0)
        loop = NSRunLoop.currentRunLoop().getCFRunLoop()
        CFRunLoopAddSource(loop, source, kCFRunLoopCommonModes)
예제 #13
0
파일: tray.py 프로젝트: jone/unison-tray
    def change_icon(self, name):
        if name == 'syncing':
            if self._last_icon is not None and \
                    self._last_icon.startswith('syncing'):
                return

            self.change_icon('syncing1')

            self._syncing_icon_timer = NSTimer.alloc() \
                .initWithFireDate_interval_target_selector_userInfo_repeats_(
                start_time, 1.0, self, 'animateSyncingIcon:', None, True)
            NSRunLoop.currentRunLoop().addTimer_forMode_(
                self._syncing_icon_timer, NSDefaultRunLoopMode)
            self._syncing_icon_timer.fire()
            return

        self._last_icon = name
        self.trayicon.setImage_(ICONS[name])
예제 #14
0
    def change_icon(self, name):
        if name == 'syncing':
            if self._last_icon is not None and \
                    self._last_icon.startswith('syncing'):
                return

            self.change_icon('syncing1')

            self._syncing_icon_timer = NSTimer.alloc() \
                .initWithFireDate_interval_target_selector_userInfo_repeats_(
                start_time, 1.0, self, 'animateSyncingIcon:', None, True)
            NSRunLoop.currentRunLoop().addTimer_forMode_(
                self._syncing_icon_timer, NSDefaultRunLoopMode)
            self._syncing_icon_timer.fire()
            return

        self._last_icon = name
        self.trayicon.setImage_(ICONS[name])
예제 #15
0
    def present(self):
        """Present the Alert, giving up after configured time..

        Returns: Int result code, based on PyObjC enums. See NSAlert
            Class reference, but result should be one of:
                User clicked the cancel button:
                    NSAlertFirstButtonReturn = 1000
                Alert timed out:
                    NSRunAbortedResponse = -1001
        """
        if self.timer:
            NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode)
        # Start a Cocoa application by getting the shared app object.
        # Make the python app the active app so alert is noticed.
        app = NSApplication.sharedApplication()
        app.activateIgnoringOtherApps_(True)
        if self.alert_sound:
            sound = NSSound.soundNamed_(self.alert_sound).play()
        result = self.runModal()  # pylint: disable=no-member
        print result
        return result
예제 #16
0
    def present(self):
        """Present the Alert, giving up after configured time..

        Returns: Int result code, based on PyObjC enums. See NSAlert
            Class reference, but result should be one of:
                User clicked the cancel button:
                    NSAlertFirstButtonReturn = 1000
                Alert timed out:
                    NSRunAbortedResponse = -1001
        """
        if self.timer:
            NSRunLoop.currentRunLoop().addTimer_forMode_(
                self.timer, NSModalPanelRunLoopMode)
        # Start a Cocoa application by getting the shared app object.
        # Make the python app the active app so alert is noticed.
        app = NSApplication.sharedApplication()
        app.activateIgnoringOtherApps_(True)
        if self.alert_sound:
            sound = NSSound.soundNamed_(self.alert_sound).play()
        result = self.runModal()  # pylint: disable=no-member
        print result
        return result
예제 #17
0
파일: app.py 프로젝트: Werniman/client
def gevent_timer(deleg):
    timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(
        NSDate.date(), 0.1, deleg, 'gevent:', None, True)
    NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode)
    timer.fire()
    print "started gevent timer"
예제 #18
0
    def instances_(self, _n):
        self.loop_func = sys._getframe(0).f_code.co_name
        try:
            x = subprocess.check_output(["/usr/local/bin/docker", "ps", "--format", "{{.Names}}"])
        except subprocess.CalledProcessError as e:
            #print(e)
            self.statusitem.setImage_(self.image)
            # Keep looping, but don't do anything
            NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
            return

        containers = x.splitlines()

        self.statusitem.setTitle_(str(len(containers)))

        new_menu = NSMenu.alloc().init()
        shellmenu = NSMenu.alloc().init()
        logmenu = NSMenu.alloc().init()

        i = NSMenuItem.alloc().init()
        i.setTitle_("Shell")
        i.setSubmenu_(shellmenu)
        new_menu.addItem_(i)

        i = NSMenuItem.alloc().init()
        i.setTitle_("Logs")
        i.setSubmenu_(logmenu)
        new_menu.addItem_(i)

        new_menu.addItem_(NSMenuItem.separatorItem())

        for container in containers:
            shellmenuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(container, 'shellinto:', '')
            shellmenu.addItem_(shellmenuitem)
            logmenuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(container, 'loginto:', '')
            logmenu.addItem_(logmenuitem)
            menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(container, 'killinstance:', '')
            menuitem.setImage_(self.toggle_images['kill' if self.kill else 'refresh'])
            # pprint(dir(menuitem))
            new_menu.addItem_(menuitem)

        new_menu.addItem_(NSMenuItem.separatorItem())

        i = NSMenuItem.alloc().init()
        configmenu = NSMenu.alloc().init()
        i.setTitle_("Settings")
        i.setSubmenu_(configmenu)
        new_menu.addItem_(i)


        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Kill', 'killornot:', '')
        menuitem.setState_(NSOnState if self.kill else NSOffState)
        configmenu.addItem_(menuitem)
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Restart', 'killornot:', '')
        menuitem.setState_(NSOnState if not self.kill else NSOffState)
        configmenu.addItem_(menuitem)
        configmenu.addItem_(NSMenuItem.separatorItem())
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('iTerm', 'itermtoggle:', '')
        menuitem.setState_(NSOnState if self.which_terminal == 'iTerm' else NSOffState)
        configmenu.addItem_(menuitem)
        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Terminal', 'itermtoggle:', '')
        menuitem.setState_(NSOnState if not self.which_terminal == 'iTerm' else NSOffState)
        configmenu.addItem_(menuitem)

        menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
        new_menu.addItem_(menuitem)

        self.menu = new_menu
        self.statusitem.setMenu_(self.menu)

        if self.state == 'setup':
            self.state = 'running'
        if self.state == 'running':
            NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
예제 #19
0
 def watchForProxyOrIpChanges(self):
     """ install a watcher for proxy and Ip changes """
     SCDynamicStoreSetNotificationKeys(self.store, None, ['State:/Network/Global/Proxies', 'State:/Network/Global/IPv4'])
     source = SCDynamicStoreCreateRunLoopSource(None, self.store, 0)
     loop = NSRunLoop.currentRunLoop().getCFRunLoop()
     CFRunLoopAddSource(loop, source, kCFRunLoopCommonModes)