Ejemplo n.º 1
0
	def fadeOut(self):
		global dismissing
		if dismissing: return
		dismissing = True
		NSAnimationContext.beginGrouping()
		NSAnimationContext.currentContext().setTimingFunction_(CAMediaTimingFunction.functionWithName_(kCAMediaTimingFunctionEaseInEaseOut))
		NSAnimationContext.currentContext().setDuration_(0.2)
		self.animator().setAlphaValue_(0.0)
		NSAnimationContext.endGrouping()
		NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.21, app, "terminate:", None, False)
Ejemplo n.º 2
0
	def fadeOut(self):
		global dismissing
		if dismissing: return
		dismissing = True
		NSAnimationContext.beginGrouping()
		NSAnimationContext.currentContext().setTimingFunction_(CAMediaTimingFunction.functionWithName_(kCAMediaTimingFunctionEaseInEaseOut))
		NSAnimationContext.currentContext().setDuration_(0.2)
		self.animator().setAlphaValue_(0.0)
		NSAnimationContext.endGrouping()
		NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.21, app, "terminate:", None, False)
Ejemplo n.º 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"
Ejemplo n.º 4
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()
Ejemplo n.º 5
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()
Ejemplo 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?")
Ejemplo n.º 7
0
 def setTimeToGiveUp_(self, time):
     """Configure alert to give up after time seconds."""
     # Cocoa objects must use class func alloc().init(), so pylint
     # doesn't see our init().
     # pylint: disable=attribute-defined-outside-init
     self.timer = \
         NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(
             time, self, "_killWindow", None, False)
Ejemplo n.º 8
0
 def setTimeToGiveUp_(self, time):
     """Configure alert to give up after time seconds."""
     # Cocoa objects must use class func alloc().init(), so pylint
     # doesn't see our init().
     # pylint: disable=attribute-defined-outside-init
     self.timer = \
         NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(
             time, self, "_killWindow", None, False)
Ejemplo n.º 9
0
    def play_(self, sender):
        try:
            if not bool(
                    Glyphs.
                    defaults["com.mekkablue.OTVarGlyphAnimator.backAndForth"]):
                self.direction = 1

            # finer steps when played slowly:
            smoothnessFactor = 1
            if float(Glyphs.defaults["com.mekkablue.OTVarGlyphAnimator.delay"]
                     ) > 0.07:
                smoothnessFactor = 3
            elif float(
                    Glyphs.defaults["com.mekkablue.OTVarGlyphAnimator.delay"]
            ) > 0.05:
                smoothnessFactor = 2

            # execute an animation step:
            if self.isPlaying:
                # Move Slider:
                sliderPos = self.w.slider.get()
                if sliderPos >= 100:
                    if not bool(Glyphs.defaults[
                            "com.mekkablue.OTVarGlyphAnimator.backAndForth"]):
                        sliderPos = 0
                    else:
                        sliderPos = 99.9999
                        self.direction = -1
                elif sliderPos <= 0:
                    sliderPos = 0.0001
                    if self.direction == -1:
                        self.direction = 1

                else:
                    sliderPos += self.direction * 2.0 / smoothnessFactor
                self.w.slider.set(sliderPos)

                # Trigger Redraw:
                self.redrawPreview(None)
                self.font.currentTab.updatePreview()

                # Call this method again after a delay:
                playSignature = objc.selector(self.play_, signature=b'v@:')
                self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                    float(Glyphs.
                          defaults["com.mekkablue.OTVarGlyphAnimator.delay"]) /
                    smoothnessFactor,  # interval
                    self,  # target
                    playSignature,  # selector
                    None,  # userInfo
                    False  # repeat
                )
        except Exception as e:
            # brings macro window to front and reports error:
            Glyphs.showMacroWindow()
            print("OTVar Glyph Animator Error: %s" % e)
            import traceback
            print(traceback.format_exc())
Ejemplo n.º 10
0
 def __init__(self, listener, seconds_to_run=5.0):
     self._listener = listener
     callback = objc.selector(self.alarm, signature='v@:')
     self._timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
         seconds_to_run,  # Interval
         self,  # Target
         callback,  # Selector
         None,  # User info
         False)  # Repeats?
Ejemplo n.º 11
0
def main():
    """Main magic."""
    parser = argparse.ArgumentParser(
        description='Setup and configuration tool.')
    parser.add_argument('-a',
                        '--auto',
                        help='Automatically run all configuration.',
                        action='store_true')
    args = parser.parse_args()

    if args.auto:
        # We want to do stuff automatically
        global on_run_trigger
        on_run_trigger = True
        # If `on_run_trigger` is true, then the on_run() function will be called
        # when the window loads for the first time.

    # Attach all the buttons to functions
    n.attach(button_outlook, 'button.outlook')
    n.attach(button_chef, 'button.chef')
    n.attach(button_msc, 'button.msc')
    n.attach(button_mscbootstrap, 'button.mscbootstrap')
    n.attach(button_filetask, 'button.filetask')
    n.attach(button_password, 'button.validate')
    n.attach(button_quit, 'button.quit')
    # Set up our window controller and delegate
    n.hidden = True
    closer = genericWindowCloseController.alloc().init()
    closer.setClose_(close_window)
    closer.setMain_(became_main)
    n.win.setDelegate_(closer)
    # Trigger an automatic timer that will kick off code
    # that we want to run automatically on launch
    NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
        5,  # seconds before timer fires
        closer,  # controller to be used
        'automaticTimerResponder:',  # function to be called on controller
        None,  # always None
        False  # repeat the timer
    )
    # Launch the window
    n.run()
Ejemplo n.º 12
0
 def start(self):
     """ Start the timer """
     if self._timer:
         self._timer.fire()
     else:
         s = objc.selector(self.tick, signature='v@:')
         self._timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
             1.0,  # Interval. 1 second
             self,  # Target
             s,  # Selector
             None,  # User info
             True)  # Repeats?
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def __init__(self, start_val, end_val, k, damp, duration, update_period, value_cb, done_cb):
     self.last_time = self.start_time = time.time()
     self.start_val = self.cur_val = start_val
     self.end_val = end_val
     self.cur_velocity = 0
     self.damp = damp
     self.k = k
     self.duration = duration
     self.value_cb = value_cb
     self.done_cb = done_cb
     self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(update_period, self, selector(self.period, signature='v@:'), None, True)
     NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSEventTrackingRunLoopMode)
Ejemplo n.º 15
0
 def initWithStartVal_endVal_duration_interval_valueCb_doneCb_(self, start_val, end_val, duration, update_period, value_callback, done_callback):
     self = super(LinearAnimator, self).init()
     if not self:
         return
     self.start_time = time.time()
     self.duration = duration
     self.end_val = end_val
     self.start_val = start_val
     self.value_callback = value_callback
     self.done_callback = done_callback
     self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(update_period, self, 'period:', None, True)
     NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSEventTrackingRunLoopMode)
     NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
Ejemplo n.º 16
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)
Ejemplo n.º 17
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,))
Ejemplo n.º 18
0
def openSocketIO(cookies):
    print 'opening SocketIO'
    global sio
    sio = SocketIO('localhost', 8778, Namespace=Namespace, cookies=cookies)
    # horrible hack to get around a pesky 3 second stutter
    # as websocket.py times out on receiving some combination of bytes
    # this doesn't hurt us now, but it might in the future if it is causing
    # messages to be dropped
    sio._transport._connection.settimeout(0.00001)
    sioeventstimer = SocketIOEventTimer.alloc().init()
    start_time = NSDate.date()
    interval = 0.05
    timer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_(
        start_time, interval, sioeventstimer, 'tick:', None, True)
    NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode)
    timer.fire()
Ejemplo n.º 19
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])
Ejemplo n.º 20
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])
Ejemplo n.º 21
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"
Ejemplo n.º 22
0
 def run(self):
     # You could adjust the 1.0 here to how ever many seconds you wanted to wait between checks to terminate
     self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, self.checkProcess_, None, True)
     NSApp.run()
 def setTimer(self):
     NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
         5, self, self.handleTimer, None, False)
Ejemplo n.º 24
0
 def run(self):
     # You could adjust the 1.0 here to how ever many seconds you wanted to wait between checks to terminate
     self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
         1.0, self, self.checkProcess_, None, True)
     NSApp.run()
 def setTimer(self):
     self.count = TOTAL_COUNT
     self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
         TOTAL_TIME / TOTAL_COUNT, self, self.handleTimer, None, True)
Ejemplo n.º 26
0
def startWatchdog():
    watchdog = WatchdogTimer.alloc().init()
    interval = 0.5
    timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(
        interval, watchdog, 'tick:', None, True)
    NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode)
Ejemplo n.º 27
0
 def run(self):
     NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
         0.1, self, 'runAndStop:', '', False)
     NSApplication.sharedApplication()
     NSApp.run()
Ejemplo n.º 28
0
 def start(self):
     assert_message_queue()
     self.t = 0
     self.orderFront_(None)
     self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(self.TICK_RATE, self, self.tick_, None, True)