def start(self, tasks): """This can be called to start timer and to define unfinished tasks """ self.tasks_all = tasks self.start_time = time.time() try: self.timer.Start(1000) except AttributeError: self.timer = Timer(1000, self._timer_task)
def _configure_timer(self, event): """ Creates, replaces, or destroys the autosave timer. """ if self._timer: self._timer.Stop() if self.autosave and self.saveObject: self._timer = Timer(self.autosaveInterval * 1000, self._autosave) else: self._timer = None
def start_readout(self, interval=1.): """Starts readout process. GUI must be running for this to work... """ super(DSCUSBUILog, self).start_readout(interval) try: self.log_timer.Start(1000) except AttributeError: #self._timer_function() self.log_timer = Timer(1000, self._log_timer_function)
def __init__(self, **traits): super(Demo, self).__init__(**traits) self._create_plot_component() self.queue = Queue() self.finish_event = threading.Event() self.thread = threading.Thread(target=self.get_audio_data) self.thread.start() self.timer = Timer(10, self.on_timer) self.win_func = np.hanning(NUM_SAMPLES + 1)[:NUM_SAMPLES]
def _reset(self): if hasattr(self,'_timer'): self._timer.Stop() self._create_plot() self._counter = Counter(self.tagger, self.channels, int(self.seconds_per_point*1e12), self.number_of_points) self.time = self._counter.getIndex() * 1e-12 self.count_rate = self._counter.getData() / self.seconds_per_point self._timer = Timer(100, self._refresh_data) self._timer.Start()
def start_timer(self, interval=TIMER_INTERVAL): """Starts timer process. It updates status of the instrument with the interval specified, collects data, etc, depending on the defined update method """ self.logger.info('Starting readout.') try: self.timer.Start(interval * 1000) except AttributeError: self.timer = Timer(interval * 1000, self._update)
def main(): fname = 'output.vtk' data = setup_data(fname) view_data() p = Pollster(fname, data) timer = Timer(1000, p.poll_file) mayavi2.savedtimerbug = timer
def run(self): MayaviDaemon._viewers.append(self) mlab.clf() bounds = zeros((0, 6), 'l') self.cellsource = self.setup_source(self.cellfname) if self.cellsource is not None: tmp = [out.cell_data.scalars for out in self.cellsource.outputs \ if out.cell_data.scalars is not None] self.has_cell_scalars = (len(tmp) > 0) tmp = [out.cell_data.vectors for out in self.cellsource.outputs \ if out.cell_data.vectors is not None] self.has_cell_vectors = (len(tmp) > 0) tmp = [out.cell_data.tensors for out in self.cellsource.outputs \ if out.cell_data.tensors is not None] self.has_cell_tensors = (len(tmp) > 0) bounds = concatenate((bounds, [out.bounds for out in self.cellsource.outputs]), axis=0) self.facesource = self.setup_source(self.facefname) if self.facesource is not None: tmp = [out.point_data.scalars for out in self.facesource.outputs \ if out.point_data.scalars is not None] self.has_face_scalars = (len(tmp) > 0) tmp = [out.point_data.vectors for out in self.facesource.outputs \ if out.point_data.vectors is not None] self.has_face_vectors = (len(tmp) > 0) tmp = [out.point_data.tensors for out in self.facesource.outputs \ if out.point_data.tensors is not None] self.has_face_tensors = (len(tmp) > 0) bounds = concatenate((bounds, [out.bounds for out in self.facesource.outputs]), axis=0) boundsmin = bounds.min(axis=0) boundsmax = bounds.max(axis=0) bounds = (boundsmin[0], boundsmax[1], boundsmin[2], boundsmax[3], boundsmin[4], boundsmax[5]) self.bounds = where(self.bounds == array((None,)), bounds, self.bounds).astype(float) self.view_data() # Poll the lock file. self.timer = Timer(1000 / self.fps, self.poll_file)
def timed_update(): from pyface.timer.api import Timer def update_loop(line_plot): line_plot.update_data() # shouldn't need this # line_plot.autoscale_axis() def log_memory(): # log memory usage usage = float(psutil.Process(os.getpid()).memory_info().rss) * 1e-6 info = '#[{}] MB:{:f}'.format(-1, usage) logger.warning(info) plot = LinePlot() millisecs = int(1000.0 / 30.0) # ~30Hz update_timer = Timer(millisecs, update_loop, plot) log_timer = Timer(int(1000.0 * 10.0), log_memory) update_timer.Start() log_timer.Start() plot.configure_traits()
def _start_timer(self, project): """ Resets the timer to work on auto-saving the current project. """ if self.timer is None: if self.autosave_interval > 0: # Timer needs the interval in millisecs self.timer = Timer(self.autosave_interval * 60000, self._auto_save, project) return
def _watchFolderModeChanged(self): eagle = self.view eagle.oldFiles = [] if eagle.watchFolderBool: if eagle.watchFolder == '' and os.path.isfile(eagle.selectedFile): eagle.watchFolder = os.path.dirname(eagle.selectedFile) eagle.oldFiles = self.getPNGFiles() self.watchFolderTimer = Timer(2000., self.checkForNewFiles) else: if self.watchFolderTimer is not None: self.watchFolderTimer.stop() self.watchFolderTimer = None
def main(): # Change this to suit your needs. Edit the file after running this # script and the pipeline should be updated automatically. fname = join(mayavi2.get_data_dir(abspath(dirname(__file__))), 'heart.vtk') data = setup_data(fname) view_data() # Poll the file. p = Pollster(fname, data) timer = Timer(1000, p.poll_file) # Keep a reference on the timer mayavi2.savedtimerbug = timer
def create_mayavi(pipe): def send_key_callback(widget, event): "Send the key-presses to the process which created this mayavi viewer." pipe.send(cPickle.dumps(("KEY_DOWN", widget.GetKeyCode()))) fig = mlab.figure() fig.scene.interactor.add_observer("KeyPressEvent", send_key_callback) time.sleep(1) mayavi_app = Plotter(pipe) from pyface.timer.api import Timer from mayavi.scripts import mayavi2 timer = Timer(50, mayavi_app.check_and_process) mayavi2.savedtimerbug = timer
def __init__(self, Xmean, tris, components): HasTraits.__init__(self) self._components = components self._max_component_index = len(components) self._Xmean = Xmean self.pd = tvtk.PolyData(points=Xmean, polys=tris) self.pd.point_data.normals = compute_normals( self.pd) # compute normals once for rest-shape (faster) self.actor = tvtk.Actor(mapper=tvtk.PolyDataMapper( input=self.pd, immediate_mode_rendering=True)) self.actor.mapper.lookup_table = tvtk.LookupTable( hue_range=(0.45, 0.6), saturation_range=(0., 0.8), value_range=(.6, 1.), ) self.scene.add_actor(self.actor) self.timer = Timer(40, self.animate().next)
def __init__(self, num_frames, callable, millisec=40, figure=None, play=True, *args, **kwargs): HasTraits.__init__(self) self.delay = millisec self._last_frame = num_frames - 1 self._callable = callable if figure is None: figure = mlab.gcf() self._figure = figure self._camera_interpolator = tvtk.CameraInterpolator(interpolation_type='spline') self._t_keyframes = {} self.render_to_frame = self._last_frame self.timer = Timer(millisec, self._on_timer, *args, **kwargs) if not play: self.stop = True self._internal_generator = None self.current_frame = 0 self.on_trait_change(self._render, "render, current_frame", dispatch="ui")
def _anim_frame_fired(self): if hasattr(self, '_atimer'): if pyf_new_api and self._atimer.active: self._atimer.stop() return elif not pyf_new_api and self._atimer.IsRunning(): self._atimer.Stop() return x, self.__y = self.curve_manager.interactive_curve.current_data( full_xdata=False) self.__f_skip = 1 self.__x = x dt = self.__x[1] - self.__x[0] self.__n_frames = self.__y.shape[1] self.__n = 0 self._atimer = Timer(self.anim_time_scale * dt * 1000, self.__step_frame)
def __init__(self, Xmean, tris, components): HasTraits.__init__(self) self._components = components self._max_component_index = len(components) self._Xmean = Xmean self.pd = tvtk.PolyData(points=Xmean, polys=tris) self.normals = tvtk.PolyDataNormals(splitting=False) configure_input_data(self.normals, self.pd) mapper = tvtk.PolyDataMapper(immediate_mode_rendering=True) self.actor = tvtk.Actor(mapper=mapper) configure_input(self.actor.mapper, self.normals) self.actor.mapper.lookup_table = tvtk.LookupTable( hue_range=(0.45, 0.6), saturation_range=(0., 0.8), value_range=(.6, 1.), ) self.scene.add_actor(self.actor) self.timer = Timer(40, self.animate().next)
def __init__(self, millisec, callable, *args, **kwargs): """Constructor. **Parameters** :millisec: int specifying the delay in milliseconds between calls to the callable. :callable: callable function to call after the specified delay. :\*args: optional arguments to be passed to the callable. :\*\*kwargs: optional keyword arguments to be passed to the callable. """ HasTraits.__init__(self) self.delay = millisec self.timer = Timer(millisec, callable, *args, **kwargs)
def _create_window(self): numpoints = 50 low = -5 high = 15.0 x = arange(low, high, (high - low) / numpoints) container = OverlayPlotContainer(bgcolor="lightgray") common_index = None index_range = None value_range = None self.animated_plots = [] for i, color in enumerate(COLOR_PALETTE): if not common_index: animated_plot = AnimatedPlot(x, jn(i, x), color) plot = animated_plot.plot common_index = plot.index index_range = plot.index_mapper.range value_range = plot.value_mapper.range else: if i % 2 == 1: orientation = "v" else: orientation = "h" animated_plot = AnimatedPlot(common_index, jn(i, x), color, orientation=orientation) plot = animated_plot.plot plot.index_mapper.range = index_range plot.value_mapper.range = value_range container.add(plot) self.animated_plots.append(animated_plot) for i, a_plot in enumerate(self.animated_plots): a_plot.plot.position = [ 50 + (i % 3) * (PLOT_SIZE + 50), 50 + (i // 3) * (PLOT_SIZE + 50) ] self.timer = Timer(100.0, self.onTimer) self.container = container return Window(self, -1, component=container)
def _create_window(self): self._create_data() x = self.x_values[:self.current_index] y = self.y_values[:self.current_index] plot = create_line_plot((x, y), color="red", width=2.0) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot) hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 2.0 vgrid.grid_interval = 2.0 self.plot = plot plot.tools.append(PanTool(component=plot)) plot.overlays.append( ZoomTool(component=plot, tool_mode="box", always_on=False)) self.timer = Timer(50.0, self.onTimer) return Window(self, -1, component=plot)
def __init__(self, ax, img=None, mask_shape=None, canmove=True, size=None): self.canmove = canmove self.ax = ax if size is None: size = 10 self.bbox = mtrans.Bbox(np.array([[0, 0], [10, 10]])) bbox = mtrans.TransformedBbox(self.bbox, ax.transData) self.mask_img = mimage.BboxImage(bbox, animated=True, alpha=0.6, zorder=1000) self.ax.add_artist(self.mask_img) self.create_mask(img, mask_shape) self.canvas = ax.figure.canvas self.event_ids = [ self.canvas.mpl_connect('motion_notify_event', self.on_move), self.canvas.mpl_connect('draw_event', self.on_draw), self.canvas.mpl_connect('button_press_event', self.on_press), self.canvas.mpl_connect('button_release_event', self.on_release), self.canvas.mpl_connect('scroll_event', self.on_scroll), ] self.circle = mpatches.Circle((0, 0), size, facecolor="red", alpha=0.5, animated=True) self.ax.add_patch(self.circle) self.mask_circle = mpatches.Circle((0, 0), 10, facecolor="white", lw=0) self.mask_line = plt.Line2D((0, 0), (0, 0), lw=18, solid_capstyle="round", color="white") self.background = None self.last_pos = None self.timer = Timer(40, self.check_dirty)
def _create_window(self): numpoints = 50 low = -5 high = 15.0 x = arange(low, high, (high - low) / numpoints) container = OverlayPlotContainer(bgcolor="lightgray") self.animated_plots = [] for i, color in enumerate(COLOR_PALETTE): animated_plot = AnimatedPlot(x, jn(i, x), color) container.add(animated_plot.plot) self.animated_plots.append(animated_plot) for i, a_plot in enumerate(self.animated_plots): a_plot.plot.position = [ 50 + (i % 3) * (PLOT_SIZE + 50), 50 + (i // 3) * (PLOT_SIZE + 50) ] self.timer = Timer(100.0, self.onTimer) self.container = container return Window(self, -1, component=container)
def _autoRefresh_dialog(self): """when user clicks autorefresh in the menu this function calls the dialog after user hits ok, it makes the choices of how to setup or stop the timer""" logger.info("auto refresh dialog called") if self.autoRefreshDialog is None: self.autoRefreshDialog = plotObjects.autoRefreshDialog.AutoRefreshDialog( ) self.autoRefreshDialog.configure_traits() logger.info("dialog edit traits finished") if self.autoRefreshDialog.autoRefreshBool: if self.autoRefreshTimer is not None: self.autoRefreshTimer.stop() self.selectedLFP.autoRefreshObject = self.autoRefreshDialog #this gives it all the info it needs self.autoRefreshTimer = Timer( self.autoRefreshDialog.minutes * 60.0 * 1000.0, self.selectedLFP.autoRefresh) logger.info("started auto refresh timer to autorefresh") else: self.selectedLFP.autoRefreshObject = None logger.info("stopping auto refresh") if self.autoRefreshTimer is not None: self.autoRefreshTimer.stop()
def init(self, info): super(AnimationHandler, self).init(info) info.object.timer = Timer(80, info.object.on_timer)
def configure_traits(self, *args, **kws): # Start up the timer! We should do this only when the demo actually # starts and not when the demo object is created. self.timer=Timer(100, self.controller.timer_tick) return super(Demo, self).configure_traits(*args, **kws)
def configure_traits(self, *args, **kws): self.timer = Timer(10, self.plotter.update_graph) # lance un timer en # tache de fond: toutes les 10 ms, ma methode est executee. ca correspond # a la frequence de rafraichissement de la fenetre (sauf si le queue.get # est bloquant) return super(Viewer, self).configure_traits(*args, **kws)
def start_timer(self): """Called in init if user selected live update mode, otherwise called from menu action. Every self.wizard.updateRateSeconds, self._refresh_data_action will be called""" print "Timer Object Started. Will update ADC Information every %s seconds" % self.refreshTime self.timer = Timer( float(self.refreshTime) * 1000, self._refresh_Visible_channels)
def edit_traits(self, *args, **kws): # Start up the timer! We should do this only when the demo actually # starts and not when the demo object is created. self.timer = Timer(20, self.controller.onTimer) return super(Demo, self).edit_traits(*args, **kws)
def configure_traits(self, *args, **kws): self.timer = Timer(10, self.error_window.timer_tick) return super(main, self).configure_traits(*args, **kws)
def edit_traits(self, *args, **kws): # Start up the timer! We should do this only when the main actually # starts and not when the main object is created. self.timer = Timer(10, self.error_window.timer_tick) return super(main, self).edit_traits(*args, **kws)