Exemplo n.º 1
0
    def run_mainloop(self, delay, wait=True, exact=False):
        '''
        Run mainloop for a maximum of <delay> seconds.
        If wait is True (default), sleep until <delay> seconds have passed.
        '''
        start = exact_time()
        dt = 0
        # TODO possibly this implementation of event handling using threads
        # can be done in a better way using ipython-0.11 inputhook support?
        gtk.gdk.threads_enter()
        while gtk.events_pending() and (not exact or (dt + 0.001) < delay):
            gtk.main_iteration_do(False)
            dt = exact_time() - start
        gtk.gdk.threads_leave()

        if delay > dt and wait:
            time.sleep(delay - dt)
Exemplo n.º 2
0
    def run_mainloop(self, delay, wait=True, exact=False):
        '''
        Run mainloop for a maximum of <delay> seconds.
        If wait is True (default), sleep until <delay> seconds have passed.
        '''
        start = exact_time()
        dt = 0
	# TODO possibly this implementation of event handling using threads
	# can be done in a better way using ipython-0.11 inputhook support?
        gtk.gdk.threads_enter()
        while gtk.events_pending() and (not exact or (dt + 0.001) < delay):
            gtk.main_iteration_do(False)
            dt = exact_time() - start
        gtk.gdk.threads_leave()

        if delay > dt and wait:
            time.sleep(delay - dt)
Exemplo n.º 3
0
    def measurement_idle(self, delay=0.0, exact=False, emit_interval=1):
        '''
        Indicate that the measurement is idle and handle events.

        This function will check whether an abort has been requested and
        handle queued events for a time up to 'delay' (in seconds).

        It starts by emitting the 'measurement-idle' signal to allow callbacks
        to be executed by the time this function handles the event queue.
        After that it handles events and sleeps for periods of 10msec. Every
        <emit_interval> seconds it will emit another measurement-idle signal.

        If exact=True, timing should be a bit more precise, but in this case
        a delay <= 1msec will result in NO gui interaction.
        '''

        start = exact_time()

        self.emit('measurement-idle')
        lastemit = exact_time()

        while self._pause:
            self.check_abort()
            self.run_mainloop(0.01)

        while True:
            self.check_abort()

            curtime = exact_time()
            if curtime - lastemit > emit_interval:
                self.emit('measurement-idle')
                lastemit = curtime

            dt = exact_time() - start
            self.run_mainloop(delay - dt, wait=False, exact=exact)

            dt = exact_time() - start
            if dt + 0.01 < delay:
                time.sleep(0.01)
            else:
                time.sleep(max(0, delay - dt))
                return
Exemplo n.º 4
0
    def measurement_idle(self, delay=0.0, exact=False, emit_interval=1):
        '''
        Indicate that the measurement is idle and handle events.

        This function will check whether an abort has been requested and
        handle queued events for a time up to 'delay' (in seconds).

        It starts by emitting the 'measurement-idle' signal to allow callbacks
        to be executed by the time this function handles the event queue.
        After that it handles events and sleeps for periods of 10msec. Every
        <emit_interval> seconds it will emit another measurement-idle signal.

        If exact=True, timing should be a bit more precise, but in this case
        a delay <= 1msec will result in NO gui interaction.
        '''

        start = exact_time()

        self.emit('measurement-idle')
        lastemit = exact_time()

        while self._pause:
            self.check_abort()
            self.run_mainloop(0.01)

        while True:
            self.check_abort()

            curtime = exact_time()
            if curtime - lastemit > emit_interval:
                self.emit('measurement-idle')
                lastemit = curtime

            dt = exact_time() - start
            self.run_mainloop(delay-dt, wait=False, exact=exact)

            dt = exact_time() - start
            if dt + 0.01 < delay:
                time.sleep(0.01)
            else:
                time.sleep(max(0, delay - dt))
                return
Exemplo n.º 5
0
 def _measurement_idle_cb(self, widget):
     now = exact_time()
     if (now - self._idle_lasttime) > self._idle_mintime:
         self._idle_lasttime = now
         self._function()
Exemplo n.º 6
0
 def _measurement_idle_cb(self, widget):
     now = exact_time()
     if (now - self._idle_lasttime) > self._idle_mintime:
         self._idle_lasttime = now
         self._function()