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)
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"
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()
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()
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 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)
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())
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?
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()
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?
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)
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)
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)
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)
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,))
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()
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])
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"
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)
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)
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)
def run(self): NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 0.1, self, 'runAndStop:', '', False) NSApplication.sharedApplication() NSApp.run()
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)