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)
Example #2
0
 def start_test_timer(self):
   NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
       1,
       self.delegate,
       'timerCallback:',
       None,
       True)
Example #3
0
  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()
Example #4
0
 def start_test_timer(self):
   NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
       1,
       self.delegate,
       'timerCallback:',
       None,
       True)
Example #5
0
    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)
Example #6
0
    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()
Example #7
0
    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."
Example #8
0
    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."
Example #9
0
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
Example #10
0
    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)
Example #11
0
 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 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(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,
     )
Example #14
0
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
Example #15
0
 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 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)
Example #17
0
    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 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 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 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 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 startMouseOutTimer(self):
     if self.mouse_timer is None:
         self.mouse_timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(3, self, "mouseOutTimer:", None, False)
         NSRunLoop.currentRunLoop().addTimer_forMode_(self.mouse_timer, NSRunLoopCommonModes)
         NSRunLoop.currentRunLoop().addTimer_forMode_(self.mouse_timer, NSEventTrackingRunLoopMode)
Example #23
0
 def sleep(self, timeout):
     NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
         timeout, self, "timedOut:", None, False)
     self.timedout = False
     waituntil(lambda: self.timedout)
Example #24
0
 def runTimer(target, selector, interval):
     return NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(interval,target,selector,None,True)
Example #25
0
 def sleep(self, timeout):
     NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
             timeout, self, "timedOut:", None, False)
     self.timedout = False
     waituntil(lambda: self.timedout)
Example #26
0
#!/usr/bin/env python
"""
This script shows how to use PyObjCTools.Debugging to show a dump of all
(Cocoa) exceptions (handled and unhandled).
"""
from Foundation import NSArray, NSObject, NSTimer
from PyObjCTools import AppHelper, Debugging


class FooTester(NSObject):
    def doCBad_(self, aTimer):
        NSArray([1])[5]

    def doBadThingsNow_(self, aTimer):
        AppHelper.stopEventLoop()
        raise ValueError("doing bad things")


foo = FooTester.alloc().init()
NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
    0.5, foo, "doBadThingsNow:", None, False)
NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
    0.0, foo, "doCBad:", None, False)
# we need to catch everything, because NSTimer handles this one
Debugging.installVerboseExceptionHandler()
AppHelper.runConsoleEventLoop()
 def windowShouldClose_(self, sender):
     self.visible = 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):
     NSBundle.loadNibNamed_owner_("VideoDisconnectWindow", self)
     self.window.setAlphaValue_(0.7)
     timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(0.05, self, "fade:", None, True)
Example #29
0
def set_timeout(target, sel, delay, info=None, repeat=False):
    return NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
        delay, target, sel, info, repeat)
Example #30
0
def set_timeout(target, sel, delay, info=None, repeat=False):
    return NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(delay, target, sel, info, repeat)
 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)
Example #32
0
 def wrap():
     NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
         delay, NSApp.delegate(), "callTimerObject:",
         lambda: func(*args, **kw), False)
 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 registerAlarm(subject, interval=0.5):
    '''Returns a correctly configured timer (already added to RunLoop, if Cocoa)'''
    return NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
            interval, subject, 'alarm', objc.nil, objc.YES)