Пример #1
0
def input_handler2():
    """Run the wx event loop by processing pending events only.

    This is like inputhook_wx1, but it keeps processing pending events
    until stdin is ready.  After processing all pending events, a call to
    time.sleep is inserted.  This is needed, otherwise, CPU usage is at 100%.
    This sleep time should be tuned though for best performance.
    """
    app = wx.GetApp()
    global POLLTIME, ON_INTERRUPT
    if app is not None:
        if not wx.Thread_IsMain():
            raise Exception('wx thread is not the main thread')
        evtloop = wx.EventLoop()
        activator = wx.EventLoopActivator(evtloop)
        while not stdin_ready():
            while evtloop.Pending():
                evtloop.Dispatch()
            app.ProcessIdle()
            try:
                sleep(POLLTIME)
            except KeyboardInterrupt:
                if hasattr(ON_INTERRUPT, '__call__'):
                    ON_INTERRUPT()
        activator = None
        # del activator
    return 0
Пример #2
0
def input_handler2():
    """Run the wx event loop by processing pending events only.

    This is like inputhook_wx1, but it keeps processing pending events
    until stdin is ready.  After processing all pending events, a call to
    time.sleep is inserted.  This is needed, otherwise, CPU usage is at 100%.
    This sleep time should be tuned though for best performance.
    """
    app = wx.GetApp()
    global POLLTIME, ON_INTERRUPT
    if app is not None:
        assert wx.Thread_IsMain()
        evtloop = wx.EventLoop()
        activator = wx.EventLoopActivator(evtloop)
        t0 = time.time()

        while update_requested() or not stdin_ready():
            while evtloop.Pending():
                evtloop.Dispatch()
            app.ProcessIdle()
            try:
                sleep(0.001*POLLTIME)
            except KeyboardInterrupt:
                # print 'INTERRUPT', ON_INTERRUPT, hasattr(ON_INTERRUPT, '__call__')
                if hasattr(ON_INTERRUPT, '__call__'):
                    ON_INTERRUPT()
            clear_update_request()

        activator = None
        # del activator
    return 0
Пример #3
0
 def check_stdin(self, event=None):
     # print 'Get In ', clock()-self.t0, stdin_ready()
     try:
         if (stdin_ready() or update_requested() or
             (clock() - self.t0) > 5):
             self.timer.Stop()
             self.evtloop.Exit()
             del self.timer, self.evtloop
             clear_update_request()
     except KeyboardInterrupt:
         print('Captured Ctrl-C!')
Пример #4
0
 def check_stdin(self, event=None):
     # print 'Get In ', clock()-self.t0, stdin_ready()
     try:
         if (stdin_ready() or update_requested()
                 or (clock() - self.t0) > 5):
             self.timer.Stop()
             self.evtloop.Exit()
             del self.timer, self.evtloop
             clear_update_request()
     except KeyboardInterrupt:
         print('Captured Ctrl-C!')
Пример #5
0
    def check_stdin(self, event=None):
        try:
            if (not IN_MODAL_DIALOG and (stdin_ready() or update_requested() or
                                         (clock() - self.t0) > 5)):
                self.timer.Stop()
                self.evtloop.Exit()
                del self.timer, self.evtloop
                clear_update_request()

        except KeyboardInterrupt:
            print('Captured Ctrl-C!')
        except:
            print(sys.exc_info())
Пример #6
0
def inputhook_wx():
    """Run the wx event loop by processing pending events only.

    This keeps processing pending events until stdin is ready.
    After processing all pending events, a call to time.sleep is inserted.
    This is needed, otherwise, CPU usage is at 100%.
    This sleep time should be tuned though for best performance.
    """
    # We need to protect against a user pressing Control-C when IPython is
    # idle and this is running. We trap KeyboardInterrupt and pass.
    try:
        app = wx.GetApp()
        if app is not None:
            assert is_wxMain()

            if not callable(signal.getsignal(signal.SIGINT)):
                signal.signal(signal.SIGINT, signal.default_int_handler)
            evtloop = wx_EvtLoop()
            ea = wx.EventLoopActivator(evtloop)
            t = clock()
            while not stdin_ready() and not update_requested():
                while evtloop.Pending():
                    t = clock()
                    evtloop.Dispatch()

                if callable(getattr(app, 'ProcessIdle', None)):
                    app.ProcessIdle()
                if callable(getattr(evtloop, 'ProcessIdle', None)):
                    evtloop.ProcessIdle()

                # We need to sleep at this point to keep the idle CPU load
                # low.  However, if sleep to long, GUI response is poor.
                used_time = clock() - t
                ptime = 0.001
                if used_time >  0.10: ptime = 0.05
                if used_time >  3.00: ptime = 0.25
                if used_time > 30.00: ptime = 1.00
                sleep(ptime)
            del ea
            clear_update_request()
    except KeyboardInterrupt:
        if callable(ON_INTERRUPT):
            ON_INTERRUPT()
    return 0
Пример #7
0
def inputhook_wx():
    """Run the wx event loop by processing pending events only.

    This keeps processing pending events until stdin is ready.
    After processing all pending events, a call to time.sleep is inserted.
    This is needed, otherwise, CPU usage is at 100%.
    This sleep time should be tuned though for best performance.
    """
    # We need to protect against a user pressing Control-C when IPython is
    # idle and this is running. We trap KeyboardInterrupt and pass.
    try:
        app = wx.GetApp()
        if app is not None:
            assert is_wxMain()

            if not callable(signal.getsignal(signal.SIGINT)):
                signal.signal(signal.SIGINT, signal.default_int_handler)
            evtloop = wx_EvtLoop()
            ea = wx.EventLoopActivator(evtloop)
            t = clock()
            while not stdin_ready() and not update_requested():
                while evtloop.Pending():
                    t = clock()
                    evtloop.Dispatch()

                if callable(getattr(app, 'ProcessIdle', None)):
                    app.ProcessIdle()
                if callable(getattr(evtloop, 'ProcessIdle', None)):
                    evtloop.ProcessIdle()

                # We need to sleep at this point to keep the idle CPU load
                # low.  However, if sleep to long, GUI response is poor.
                used_time = clock() - t
                ptime = 0.001
                if used_time > 0.10: ptime = 0.05
                if used_time > 3.00: ptime = 0.25
                if used_time > 30.00: ptime = 1.00
                sleep(ptime)
            del ea
            clear_update_request()
    except KeyboardInterrupt:
        if callable(ON_INTERRUPT):
            ON_INTERRUPT()
    return 0
Пример #8
0
 def check_stdin(self, event=None):
     if stdin_ready() or update_requested():
         self.timer.Stop()
         self.evtloop.Exit()
         del self.timer, self.evtloop
         clear_update_request()
Пример #9
0
 def check_stdin(self):
     if stdin_ready():
         self.timer.Stop()
         self.evtloop.Exit()
Пример #10
0
 def check_stdin(self):
     if stdin_ready():
         self.timer.Stop()
         self.evtloop.Exit()