def start_test_timer(self): NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 1, self.delegate, 'timerCallback:', None, True)
def run(self): NSApplication.sharedApplication() self.delegate = AppDelegate.alloc().init() self.delegate.event_sniffer = self NSApp().setDelegate_(self.delegate) self.workspace = NSWorkspace.sharedWorkspace() nc = self.workspace.notificationCenter() # This notification needs OS X v10.6 or later nc.addObserver_selector_name_object_( self.delegate, 'applicationActivated:', 'NSWorkspaceDidActivateApplicationNotification', None) nc.addObserver_selector_name_object_( self.delegate, 'screenSleep:', 'NSWorkspaceScreensDidSleepNotification', None) # I don't think we need to track when the screen comes awake, but in case # we do we can listen for NSWorkspaceScreensDidWakeNotification NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( self.options.active_window_time, self.delegate, 'writeActiveApp:', None, True) # Start the application. This doesn't return. AppHelper.runEventLoop()
def run(self) -> None: NSApplication.sharedApplication() self.delegate = AppDelegate.alloc().init() self.delegate.handler = Handler() NSApp().setDelegate_(self.delegate) self.workspace = NSWorkspace.sharedWorkspace() nc = self.workspace.notificationCenter() nc.addObserver_selector_name_object_( self.delegate, 'applicationActivated:', 'NSWorkspaceDidActivateApplicationNotification', None, ) nc.addObserver_selector_name_object_( self.delegate, 'screenSleep:', 'NSWorkspaceScreensDidSleepNotification', None, ) NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( self.polling_time, self.delegate, 'writeActiveApp:', None, True) AppHelper.runConsoleEventLoop(maxTimeout=1)
def isScrolling_(self, scrollTop): if not self.handle_scrolling: return if self.editorVisible: return if scrollTop < 0: if self.scrollingTimer is None: self.scrollingTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 1, self, "scrollTimerDelay:", None, False) self.scrolling_back = True else: self.scrolling_back = False if self.scrollingTimer is not None: self.scrollingTimer.invalidate() self.scrollingTimer = None if scrollTop == 0 and self.handle_scrolling: current_label = self.lastMessagesLabel.stringValue() new_label = NSLocalizedString( "Keep scrolling up for more than one second to load older messages", "Label") if current_label != new_label and NSLocalizedString( "Loading", "Label") not in current_label: self.lastMessagesLabel.setStringValue_(new_label) NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 4, self, "showLastScrollLabel:", None, False)
def main(self): # Callback that quits after a frame is captured NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.1, self, "quitMainLoop:", None, True) # Turn on the camera and start the capture self.startImageCapture(None) # Start Cocoa's main event loop AppHelper.runConsoleEventLoop(installInterrupt=True) print "Frame capture completed."
def main(self): # Callback that quits after a frame is captured NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 0.1, self, 'quitMainLoop:', None, True) # Turn on the camera and start the capture self.startImageCapture(None) # Start Cocoa's main event loop AppHelper.runConsoleEventLoop(installInterrupt=True) print "Frame capture completed."
def stopEventLoop(): """ Stop the current event loop if possible returns True if it expects that it was successful, False otherwise """ stopper = PyObjCAppHelperRunLoopStopper.currentRunLoopStopper() if stopper is None: if NSApp() is not None: NSApp().terminate_(None) return True return False NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 0.0, stopper, "performStop:", None, False) return True
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()
def windowShouldClose_(self, sender): self.visible = False self.closed_by_user = False if self.close_timer is None: self.close_timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 0.05, self, "fade:", None, True) return False
def __init__(self, image): NSBundle.loadNibNamed_owner_("ScreensharingPreviewPanel", self) self.view.setImage_(image) self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(5.0, self, "closeTimer:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode) self.window.orderFront_(None)
def gotIsComposing(self, window, state, refresh, last_active): self.enableIsComposing = True flag = state == "active" if flag: if refresh is None: refresh = 120 if last_active is not None and ( last_active - ISOTimestamp.now() > datetime.timedelta(seconds=refresh)): # message is old, discard it return if self.remoteTypingTimer: # if we don't get any indications in the request refresh, then we assume remote to be idle self.remoteTypingTimer.setFireDate_( NSDate.dateWithTimeIntervalSinceNow_(refresh)) else: self.remoteTypingTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( refresh, self, "remoteBecameIdle:", window, False) else: if self.remoteTypingTimer: self.remoteTypingTimer.invalidate() self.remoteTypingTimer = None window.noteView_isComposing_(self, flag)
def end(self): if self.ended: return self.sessionController.log_debug(u"End %s" % self) self.ended = True NSApp.delegate().contactsWindowController.hideLocalVideoWindow() status = self.status if status in [STREAM_IDLE, STREAM_FAILED]: self.changeStatus(STREAM_IDLE) elif status == STREAM_PROPOSING: self.sessionController.cancelProposal(self.stream) self.changeStatus(STREAM_CANCELLING) else: self.sessionController.endStream(self) self.changeStatus(STREAM_IDLE) self.removeFromSession() self.videoWindowController.close() self.notification_center.discard_observer(self, sender=self.sessionController) dealloc_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(5.0, self, "deallocTimer:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(dealloc_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(dealloc_timer, NSEventTrackingRunLoopMode)
def __init__(self, callback, interval): self.set_callback(callback) self._nsdate = NSDate.date() self._nstimer = NSTimer.alloc( ).initWithFireDate_interval_target_selector_userInfo_repeats_( self._nsdate, interval, self, 'callback:', None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self._nstimer, NSDefaultRunLoopMode)
def start(self): if not self._status: self._nsdate = NSDate.date() self._nstimer = NSTimer.alloc().initWithFireDate_interval_target_selector_userInfo_repeats_( self._nsdate, self._interval, self, 'callback:', None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self._nstimer, NSDefaultRunLoopMode) _TIMERS.add(self) self._status = True
def startDeallocTimer(self): # workaround to keep the object alive as cocoa still sends delegate tableview messages after close self.dealloc_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 2.0, self, "deallocTimer:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(self.dealloc_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( self.dealloc_timer, NSEventTrackingRunLoopMode)
def awakeFromNib(self): NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, "contactSelectionChanged:", NSTableViewSelectionDidChangeNotification, self.contactTable) timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1, self, "refreshContactsTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode) self.contactTable.setDoubleAction_("doubleClick:")
def awakeFromNib(self): NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, "contactSelectionChanged:", NSTableViewSelectionDidChangeNotification, self.contactTable) timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(0.3, self, "refreshContactsTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSDefaultRunLoopMode) self.contactTable.setDoubleAction_("doubleClick:")
def start(self): delay = 2.0 if self._burst_count <= 0 else 0.5 self._timestamp_timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( delay, self, self.timestampTimerCallback_, None, True, )
def stopEventLoop(): """ Stop the current event loop if possible returns True if it expects that it was successful, False otherwise """ stopper = PyObjCAppHelperRunLoopStopper.currentRunLoopStopper() if stopper is None: if NSApp() is not None: NSApp().terminate_(None) return True return False NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 0.0, stopper, 'performStop:', None, False) return True
def applicationDidFinishLaunching_(self, _): NSLog("applicationDidFinishLaunching_") self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 1.0 / self.FRAMERATE, self.view, self.view.animate_, None, True )
def start_auto_close_timer(self): if not self.close_timer: # auto-close everything in 5s self.close_timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( 5, self, "closeWindows:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_( self.close_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( self.close_timer, NSEventTrackingRunLoopMode)
def __init__(self, image): NSBundle.loadNibNamed_owner_("ScreensharingPreviewPanel", self) self.view.setImage_(image) self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 5.0, self, "closeTimer:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode) self.window.orderFront_(None)
def enableAutoAnswer(self, view, session, delay=30): if session not in self.autoAnswerTimers: label = view.viewWithTag_(15) info = dict(delay = delay, session = session, label = label, time = time.time()) timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "timerTickAutoAnswer:", info, True) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSEventTrackingRunLoopMode) self.autoAnswerTimers[session] = timer self.timerTickAutoAnswer_(timer) label.setHidden_(False)
def _finish(self): self.smp_running = False self.finished = True self.secretText.setEnabled_(False) self.questionText.setEnabled_(False) self.progressBar.setDoubleValue_(9) self.continueButton.setEnabled_(True) self.continueButton.setTitle_('Finish') self.cancelButton.setHidden_(True) self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(5, self, "verificationFinished:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSRunLoopCommonModes)
def _NH_SIPApplicationDidStart(self, notification): settings = SIPSimpleSettings() if settings.presence_state.timestamp is None: settings.presence_state.timestamp = ISOTimestamp.now() settings.save() self.get_location([account for account in AccountManager().iter_accounts() if account is not BonjourAccount()]) self.publish() idle_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "updateIdleTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(idle_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(idle_timer, NSEventTrackingRunLoopMode)
def textDidChange_(self, notification): self.lastTypedTime = datetime.datetime.now() if self.inputText.textStorage().length() == 0: self.becameIdle_(None) else: if not self.lastTypeNotifyTime or time.time() - self.lastTypeNotifyTime > TYPING_NOTIFY_INTERVAL: self.lastTypeNotifyTime = time.time() self.delegate.chatView_becameActive_(self, self.lastTypedTime) if self.typingTimer: # delay the timeout a bit more self.typingTimer.setFireDate_(NSDate.dateWithTimeIntervalSinceNow_(TYPING_IDLE_TIMEOUT)) else: self.typingTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(TYPING_IDLE_TIMEOUT, self, "becameIdle:", None, False)
def start(self): notification_center = NotificationCenter() notification_center.add_observer(self, name="BlinkFileTransferDidEnd") notification_center.add_observer(self, name="AudioStreamDidChangeHoldState") notification_center.add_observer(self, name="CFGSettingsObjectDidChange") notification_center.add_observer(self, name="ChatViewControllerDidDisplayMessage") notification_center.add_observer(self, name="ConferenceHasAddedAudio") notification_center.add_observer(self, name="BlinkWillCancelProposal") self.cleanupTimer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(3, self, "cleanupTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.cleanupTimer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(self.cleanupTimer, NSEventTrackingRunLoopMode) self.started = True
def _finish(self, result=False): self.finished = True self.smp_running = False self.requested_by_remote = False self.secretText.setEnabled_(False) self.questionText.setEnabled_(False) self.progressBar.setDoubleValue_(9) self.continueButton.setEnabled_(False) self.continueButton.setTitle_(NSLocalizedString("Finish", "Button Title")) self.cancelButton.setHidden_(True) self.continueButton.setEnabled_(True) wait_interval = 5 if result else 10 self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(wait_interval, self, "verificationFinished:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSRunLoopCommonModes)
def start(self): self.stop() #ns_timer = \ # NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( # self._interval, self._target, '_ns_fire', None, self._repeat) ns_timer = \ NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( self._interval, trigger, 'fire:', None, self._repeat) self._ns_timer = ns_timer ns_timer_to_task[ns_timer] = self ns_run_loop = NSRunLoop.currentRunLoop() ns_run_loop.addTimer_forMode_(ns_timer, NSDefaultRunLoopMode) ns_run_loop.addTimer_forMode_(ns_timer, NSEventTrackingRunLoopMode) ns_run_loop.addTimer_forMode_(ns_timer, NSModalPanelRunLoopMode)
def isScrolling_(self, scrollTop): if not self.handle_scrolling: return if self.editorVisible: return if scrollTop < 0: if self.scrollingTimer is None: self.scrollingTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1, self, "scrollTimerDelay:", None, False) self.scrolling_back = True else: self.scrolling_back = False if self.scrollingTimer is not None: self.scrollingTimer.invalidate() self.scrollingTimer = None if scrollTop == 0 and self.handle_scrolling: current_label = self.lastMessagesLabel.stringValue() new_label = NSLocalizedString("Keep scrolling up for more than one second to load older messages", "Label") if current_label != new_label and NSLocalizedString("Loading", "Label") not in current_label: self.lastMessagesLabel.setStringValue_(new_label) NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(4, self, "showLastScrollLabel:", None, False)
def finishLaunching(self): """Setup the menu and run the app loop.""" self._setup_menu_bar() # Create a timer which fires the update_ method every 1second, # and add it to the runloop NSRunLoop.currentRunLoop().addTimer_forMode_( NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1, self, "update:", "", True), NSEventTrackingRunLoopMode, ) print("Sentinel is now running.") print("CTRL+C does not work here.") print("You can quit through the menu bar (Sentinel -> Quit).")
def close(self): self.log_debug('Close local %s' % self) if self.finished: return self.finished = True if self.tracking_area is not None: self.window().contentView().removeTrackingArea_(self.tracking_area) self.tracking_area = None timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(3, self, "fade:", None, False) self.notification_center.remove_observer(self, name="VideoDeviceDidChangeCamera") self.notification_center = None
def _NH_MediaStreamDidStart(self, sender, data): super(VideoController, self)._NH_MediaStreamDidStart(sender, data) self.started = True sample_rate = self.stream.clock_rate/1000 codec = beautify_video_codec(self.stream.codec) self.sessionController.log_info("Video stream established to %s:%s using %s %0.fkHz codec" % (self.stream.remote_rtp_address, self.stream.remote_rtp_port, codec, sample_rate)) self.videoWindowController.show() self.changeStatus(STREAM_CONNECTED) if self.sessionController.hasStreamOfType("chat") and self.videoWindowController.always_on_top: self.videoWindowController.toogleAlwaysOnTop() self.statistics_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(STATISTICS_INTERVAL, self, "updateStatisticsTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.statistics_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(self.statistics_timer, NSEventTrackingRunLoopMode)
def textDidChange_(self, notification): self.lastTypedTime = datetime.datetime.now() if self.inputText.textStorage().length() == 0: self.becameIdle_(None) else: if not self.lastTypeNotifyTime or time.time( ) - self.lastTypeNotifyTime > TYPING_NOTIFY_INTERVAL: self.lastTypeNotifyTime = time.time() self.delegate.chatView_becameActive_(self, self.lastTypedTime) if self.typingTimer: # delay the timeout a bit more self.typingTimer.setFireDate_( NSDate.dateWithTimeIntervalSinceNow_(TYPING_IDLE_TIMEOUT)) else: self.typingTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( TYPING_IDLE_TIMEOUT, self, "becameIdle:", None, False)
def start(self): self.stop() #ns_timer = \ # NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( # self._interval, self._target, '_ns_fire', None, self._repeat) ns_timer = \ NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( self._interval, trigger, 'fire:', None, self._repeat) self._ns_timer = ns_timer ns_timer_to_task[ns_timer] = self ns_run_loop = NSRunLoop.currentRunLoop() ns_run_loop.addTimer_forMode_( ns_timer, NSDefaultRunLoopMode) ns_run_loop.addTimer_forMode_( ns_timer, NSEventTrackingRunLoopMode) ns_run_loop.addTimer_forMode_( ns_timer, NSModalPanelRunLoopMode)
def enableAnsweringMachine(self, view, session, run_now=False): try: timer = self.answeringMachineTimers[session] except KeyError: settings = SIPSimpleSettings() amLabel = view.viewWithTag_(15) delay = 0 if run_now else settings.answering_machine.answer_delay info = dict(delay = delay, session = session, label = amLabel, time = time.time()) timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "timerTickAnsweringMachine:", info, True) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(timer, NSEventTrackingRunLoopMode) self.answeringMachineTimers[session] = timer self.timerTickAnsweringMachine_(timer) amLabel.setHidden_(False) else: if run_now: self.acceptAudioStreamAnsweringMachine(session)
def end(self): if self.ended: return self.sessionController.log_debug("End %s" % self) self.ended = True if self.sessionController.waitingForLocalVideo: self.stop_wait_for_camera_timer() self.sessionController.cancelBeforeDNSLookup() if self.sessionController.video_consumer == "audio": NSApp.delegate().contactsWindowController.detachVideo( self.sessionController) elif self.sessionController.video_consumer == "chat": NSApp.delegate().chatWindowController.detachVideo( self.sessionController) status = self.status if status in [STREAM_IDLE, STREAM_FAILED]: self.changeStatus(STREAM_IDLE) elif status == STREAM_PROPOSING: self.sessionController.cancelProposal(self) self.changeStatus(STREAM_CANCELLING) else: self.sessionController.endStream(self) self.changeStatus(STREAM_IDLE) self.removeFromSession() self.videoRecorder.stop() self.videoWindowController.close() self.notification_center.remove_observer( self, sender=self.sessionController, name='VideoRemovedByRemoteParty') dealloc_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 5.0, self, "deallocTimer:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(dealloc_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( dealloc_timer, NSEventTrackingRunLoopMode)
def captureButtonClicked_(self, sender): if self.countdownCheckbox.state() == NSOnState: self.countdown_counter = 10 self.previewButton.setHidden_(True) self.captureButton.setHidden_(True) self.countdownCheckbox.setHidden_(True) self.countdownProgress.setHidden_(False) self.countdownProgress.startAnimation_(None) self.countdownProgress.setIndeterminate_(False) self.countdownProgress.setDoubleValue_(self.countdown_counter) self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1, self, "executeTimerCapture:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode) else: self.countdownCheckbox.setHidden_(True) self.countdownProgress.setHidden_(True) self.executeCapture()
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()
def _NH_MediaStreamDidStart(self, sender, data): self.started = True sample_rate = self.stream.sample_rate / 1000 codec = beautify_video_codec(self.stream.codec) self.sessionController.log_info( "Video stream established to %s:%s using %s codec" % (self.stream.remote_rtp_address, self.stream.remote_rtp_port, codec)) self.changeStatus(STREAM_CONNECTED) self.sessionController.setVideoConsumer( self.sessionController.video_consumer) self.statistics_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( STATISTICS_INTERVAL, self, "updateStatisticsTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.statistics_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( self.statistics_timer, NSEventTrackingRunLoopMode)
def __init__(self, owner): BlinkLogger().log_debug('Starting Ringtone Manager') self.owner = owner notification_center = NotificationCenter() notification_center.add_observer(self, name="BlinkFileTransferDidEnd") notification_center.add_observer(self, name="RTPStreamDidChangeHoldState") notification_center.add_observer(self, name="CFGSettingsObjectDidChange") notification_center.add_observer( self, name="ChatViewControllerDidDisplayMessage") notification_center.add_observer(self, name="ConferenceHasAddedAudio") notification_center.add_observer(self, name="BlinkWillCancelProposal") self.cleanupTimer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 3, self, "cleanupTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.cleanupTimer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( self.cleanupTimer, NSEventTrackingRunLoopMode) self.update_ringtones()
def __init__(self, sessionController): self.notification_center = NotificationCenter() self.sessionController = None self.audio_stream = None self.chat_stream = None self.add_session(sessionController) self.add_audio_stream() self.add_chat_stream() self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "updateTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode) NSBundle.loadNibNamed_owner_("SessionInfoPanel", self) sessionBoxTitle = NSAttributedString.alloc().initWithString_attributes_("SIP Session", NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName)) self.sessionBox.setTitle_(sessionBoxTitle) audioBoxTitle = NSAttributedString.alloc().initWithString_attributes_("Audio Stream", NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName)) self.audioBox.setTitle_(audioBoxTitle) chatBoxTitle = NSAttributedString.alloc().initWithString_attributes_("Chat Stream", NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName)) self.chatBox.setTitle_(chatBoxTitle) self.audio_rtt_graph.setLineWidth_(1.0) self.audio_rtt_graph.setLineSpacing_(1.0) self.audio_rtt_graph.setAboveLimit_(200) # if higher than 200 ms show red color self.audio_rtt_graph.setMinimumHeigth_(200) self.audio_packet_loss_graph.setLineWidth_(1.0) self.audio_packet_loss_graph.setLineSpacing_(1.0) self.audio_packet_loss_graph.setAboveLimit_(3) # if higher than 3% show red color self.audio_packet_loss_graph.setLineColor_(NSColor.greenColor()) self.audio_packet_loss_graph.setMinimumHeigth_(5) self.resetSession() self.updatePanelValues()
def startOutgoing(self, is_update): if self.videoWindowController: self.videoWindowController.initLocalVideoWindow() self.ended = False self.notification_center.add_observer(self, sender=self.stream) self.notification_center.add_observer(self, sender=self.sessionController) self.notification_center.add_observer(self, sender=self.sessionController, name='VideoRemovedByRemoteParty') if is_update and self.sessionController.canProposeMediaStreamChanges(): self.changeStatus(STREAM_PROPOSING) else: self.changeStatus(STREAM_WAITING_DNS_LOOKUP) self.wait_for_camera_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 5.0, self, "localVideoReadyTimer:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_( self.wait_for_camera_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( self.wait_for_camera_timer, NSEventTrackingRunLoopMode)
def gotIsComposing(self, window, state, refresh, last_active): self.enableIsComposing = True flag = state == "active" if flag: if refresh is None: refresh = 120 if last_active is not None and (last_active - ISOTimestamp.now() > datetime.timedelta(seconds=refresh)): # message is old, discard it return if self.remoteTypingTimer: # if we don't get any indications in the request refresh, then we assume remote to be idle self.remoteTypingTimer.setFireDate_(NSDate.dateWithTimeIntervalSinceNow_(refresh)) else: self.remoteTypingTimer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(refresh, self, "remoteBecameIdle:", window, False) else: if self.remoteTypingTimer: self.remoteTypingTimer.invalidate() self.remoteTypingTimer = None window.noteView_isComposing_(self, flag)
def captureButtonClicked_(self, sender): if self.countdownCheckbox.state() == NSOnState: self.countdown_counter = 5 self.previewButton.setHidden_(True) self.captureButton.setHidden_(True) self.countdownCheckbox.setHidden_(True) self.mirrorButton.setHidden_(True) self.countdownProgress.setHidden_(False) self.countdownProgress.startAnimation_(None) self.countdownProgress.setIndeterminate_(False) self.countdownProgress.setDoubleValue_(self.countdown_counter) self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 1, self, "executeTimerCapture:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_( self.timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_( self.timer, NSDefaultRunLoopMode) else: self.countdownCheckbox.setHidden_(True) self.mirrorButton.setHidden_(True) self.countdownProgress.setHidden_(True) self.executeCapture()
def importButtonClicked_(self, sender): BlinkLogger().log_info("Import private key") pincode = str(self.pincode.stringValue()).strip() data = self.encryptedKeyPair.decode() keyPair = self.decrypt(data, pincode) try: keyPair = keyPair.decode() except UnicodeDecodeError as e: self.status.setTextColor_(NSColor.redColor()) BlinkLogger().log_error("Import private key failed: %s" % str(e)) self.status.setStringValue_( NSLocalizedString("Key import failed", "status label")) else: public_key_checksum_match = re.findall( r"--PUBLIC KEY SHA1 CHECKSUM--(\w+)--", keyPair) private_key_checksum_match = re.findall( r"--PRIVATE KEY SHA1 CHECKSUM--(\w+)--", keyPair) if (public_key_checksum_match): public_key_checksum = public_key_checksum_match[0] else: public_key_checksum = None if (private_key_checksum_match): private_key_checksum = private_key_checksum_match[0] else: private_key_checksum = None public_key = '' private_key = '' start_public = False start_private = False for l in keyPair.split("\n"): if l == "-----BEGIN RSA PUBLIC KEY-----": start_public = True start_private = False if l == "-----END RSA PUBLIC KEY-----": public_key = public_key + l start_public = False start_private = False if l == "-----BEGIN RSA PRIVATE KEY-----": start_public = False start_private = True if l == "-----END RSA PRIVATE KEY-----": private_key = private_key + l start_public = False start_private = False if start_public: public_key = public_key + l + '\n' if start_private: private_key = private_key + l + '\n' if (public_key and private_key and public_key_checksum): self.importButton.setEnabled_(False) BlinkLogger().log_info("Key imported sucessfully") self.status.setTextColor_(NSColor.greenColor()) self.status.setStringValue_( NSLocalizedString("Key imported sucessfully", "status label")) self.checksum.setStringValue_(public_key_checksum) self.account.sms.private_key = private_key self.account.sms.public_key = public_key self.account.sms.public_key_checksum = public_key_checksum self.account.save() if self.dealloc_timer is None: self.dealloc_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 6.0, self, "deallocTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_( self.dealloc_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( self.dealloc_timer, NSEventTrackingRunLoopMode) else: BlinkLogger().log_error("Key import failed") self.status.setStringValue_( NSLocalizedString("Key import failed", "status label")) self.status.setTextColor_(NSColor.redColor())
def sleep(self, timeout): NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( timeout, self, "timedOut:", None, False) self.timedout = False waituntil(lambda: self.timedout)
def wrap(): NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( delay, NSApp.delegate(), "callTimerObject:", lambda: func(*args, **kw), False)
def startSpeechSynthesizerTimer(self): self.speech_synthesizer_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(2, self, "startSpeaking:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(self.speech_synthesizer_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(self.speech_synthesizer_timer, NSEventTrackingRunLoopMode)
def __init__(self, sessionController): self.notification_center = NotificationCenter() self.notification_center.add_observer( self, name='CFGSettingsObjectDidChange') self.sessionController = None self.audio_stream = None self.video_stream = None self.chat_stream = None self.add_session(sessionController) self.add_audio_stream() self.add_video_stream() self.add_chat_stream() self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 1.0, self, "updateTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode) NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode) NSBundle.loadNibNamed_owner_("SessionInfoPanel", self) sessionBoxTitle = NSAttributedString.alloc( ).initWithString_attributes_( NSLocalizedString("SIP Session", "Label"), NSDictionary.dictionaryWithObject_forKey_( NSColor.orangeColor(), NSForegroundColorAttributeName)) self.sessionBox.setTitle_(sessionBoxTitle) audioBoxTitle = NSAttributedString.alloc().initWithString_attributes_( NSLocalizedString("Audio Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_( NSColor.orangeColor(), NSForegroundColorAttributeName)) self.audioBox.setTitle_(audioBoxTitle) videoBoxTitle = NSAttributedString.alloc().initWithString_attributes_( NSLocalizedString("Video Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_( NSColor.orangeColor(), NSForegroundColorAttributeName)) self.videoBox.setTitle_(videoBoxTitle) chatBoxTitle = NSAttributedString.alloc().initWithString_attributes_( NSLocalizedString("Chat Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_( NSColor.orangeColor(), NSForegroundColorAttributeName)) self.chatBox.setTitle_(chatBoxTitle) settings = SIPSimpleSettings() self.audio_rtt_graph.setLineWidth_(1.0) self.audio_rtt_graph.setLineSpacing_(1.0) self.audio_rtt_graph.setAboveLimit_( settings.gui.rtt_threshold) # if higher show red color self.audio_rtt_graph.setMinimumHeigth_(settings.gui.rtt_threshold) self.audio_packet_loss_rx_graph.setLineWidth_(1.0) self.audio_packet_loss_rx_graph.setLineSpacing_(1.0) self.audio_packet_loss_rx_graph.setAboveLimit_( 3) # if higher than 3% show red color self.audio_packet_loss_rx_graph.setLineColor_(NSColor.greenColor()) self.audio_packet_loss_rx_graph.setMinimumHeigth_(5) self.audio_packet_loss_tx_graph.setLineWidth_(1.0) self.audio_packet_loss_tx_graph.setLineSpacing_(1.0) self.audio_packet_loss_tx_graph.setAboveLimit_( 3) # if higher than 3% show red color self.audio_packet_loss_tx_graph.setLineColor_(NSColor.greenColor()) self.audio_packet_loss_tx_graph.setMinimumHeigth_(5) self.rx_speed_graph.setLineWidth_(1.0) self.rx_speed_graph.setLineSpacing_(0.0) self.rx_speed_graph.setLineColor_(NSColor.greenColor()) self.rx_speed_graph.setMinimumHeigth_(100000) self.rx_speed_graph.setAboveLimit_(120000) self.tx_speed_graph.setLineWidth_(1.0) self.tx_speed_graph.setLineSpacing_(0.0) self.tx_speed_graph.setLineColor_(NSColor.blueColor()) self.tx_speed_graph.setMinimumHeigth_(100000) self.tx_speed_graph.setAboveLimit_(120000) self.video_rx_speed_graph.setLineWidth_(1.0) self.video_rx_speed_graph.setLineSpacing_(0.0) self.video_rx_speed_graph.setLineColor_(NSColor.greenColor()) self.video_rx_speed_graph.setMinimumHeigth_(100000) self.video_rx_speed_graph.setAboveLimit_(99999999) self.video_tx_speed_graph.setLineWidth_(1.0) self.video_tx_speed_graph.setLineSpacing_(0.0) self.video_tx_speed_graph.setLineColor_(NSColor.blueColor()) self.video_tx_speed_graph.setMinimumHeigth_(100000) self.video_tx_speed_graph.setAboveLimit_(99999999) self.resetSession() self.updatePanelValues()
def __init__(self): NSBundle.loadNibNamed_owner_("VideoDisconnectWindow", self) self.window.setAlphaValue_(0.7) timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.05, self, "fade:", None, True)
def startFadeTimer(self): self.visible = False if self.fade_timer is None: self.fade_timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.05, self, "fade:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(self.fade_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(self.fade_timer, NSEventTrackingRunLoopMode)
def startDeallocTimer(self): # workaround to keep the object alive as cocoa still sends delegate tableview messages after close self.dealloc_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(2.0, self, "deallocTimer:", None, False) NSRunLoop.currentRunLoop().addTimer_forMode_(self.dealloc_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(self.dealloc_timer, NSEventTrackingRunLoopMode)
def set_timeout(target, sel, delay, info=None, repeat=False): return NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(delay, target, sel, info, repeat)