예제 #1
0
파일: timer.py 프로젝트: sjl421/code-2
    def _start_timer(self):
        """Called when the user selects "Start Timer" from the menu."""

        if self.my_timer is None:
            # First call, so create a Timer.  It starts automatically.
            self.my_timer = Timer(500, self._timer_task)
        else:
            self.my_timer.Start()
    def __init__(self):       
        self.data = ArrayPlotData()
        self.set_empty_data()
        self.plot = Plot(self.data, padding=10)
        scatter = self.plot.plot(("x","y", "c"), type="cmap_scatter", 
            marker_size=1, color_mapper=make_color_map(), line_width=0)[0]
        self.plot.x_grid.visible = False
        self.plot.y_grid.visible = False
        self.plot.x_axis.visible = False
        self.plot.y_axis.visible = False
        self.tool = TrianglesTool(self.plot)
        self.plot.overlays.append(self.tool)

        try:
            with file("ifs_chaco.data","rb") as f:
                tmp = pickle.load(f)
                self.ifs_names = [x[0] for x in tmp]                
                self.ifs_points = [np.array(x[1]) for x in tmp]

            if len(self.ifs_names) > 0:
                self.current_name = self.ifs_names[-1]
        except:
            pass 
        
        self.tool.on_trait_change(self.triangle_changed, 'changed')
        self.timer = Timer(10, self.ifs_calculate)       
예제 #3
0
    def __init__(self, **traits):
        super(HistDemo, self).__init__(**traits)
        img = cv.imread("lena.jpg")
        gray_img = cv.Mat()
        cv.cvtColor(img, gray_img, cv.CV_BGR2GRAY)
        self.img = gray_img
        self.img2 = self.img.clone()
        result = cv.MatND()

        r = cv.vector_float32([0, 256])
        ranges = cv.vector_vector_float32([r, r])

        cv.calcHist(cv.vector_Mat([self.img]),
                    channels=cv.vector_int([0, 1]),
                    mask=cv.Mat(),
                    hist=result,
                    histSize=cv.vector_int([256]),
                    ranges=ranges)

        data = ArrayPlotData(x=np.arange(0, len(result[:])), y=result[:])
        self.plot = Plot(data, padding=10)
        line = self.plot.plot(("x", "y"))[0]
        self.select_tool = RangeSelection(line, left_button_selects=True)
        line.tools.append(self.select_tool)
        self.select_tool.on_trait_change(self._selection_changed, "selection")
        line.overlays.append(RangeSelectionOverlay(component=line))

        cv.imshow("Hist Demo", self.img)

        self.timer = Timer(50, self.on_timer)
예제 #4
0
    def __call__(self, step=0):
        """Get the file source."""
        if self.source is None:
            self.source = self.create_source()
            if self.watch:
                self.timer = Timer(1000, self.poll_file)

        return self.source
예제 #5
0
파일: timer.py 프로젝트: sjl421/code-2
class MainWindow(ApplicationWindow):
    """ The main application window. """

    # The pyface Timer.
    my_timer = Any()

    # Count each time the timer task executes.
    counter = Int

    def __init__(self, **traits):
        """ Creates a new application window. """

        # Base class constructor.
        super(MainWindow, self).__init__(**traits)

        # Add a menu bar.
        self.menu_bar_manager = MenuBarManager(
            MenuManager(
                Action(name='Start Timer', on_perform=self._start_timer),
                Action(name='Stop Timer', on_perform=self._stop_timer),
                Action(name='E&xit', on_perform=self.close),
                name='&File',
            ))

        return

    def _start_timer(self):
        """Called when the user selects "Start Timer" from the menu."""

        if self.my_timer is None:
            # First call, so create a Timer.  It starts automatically.
            self.my_timer = Timer(500, self._timer_task)
        else:
            self.my_timer.Start()

    def _stop_timer(self):
        """Called when the user selecte "Stop Timer" from the menu."""

        if self.my_timer is not None:
            self.my_timer.Stop()

    def _timer_task(self):
        """The method run periodically by the timer."""

        self.counter += 1
        print "counter = %d" % self.counter
예제 #6
0
 def __init__(self, **traits):
     super(Demo, self).__init__(**traits)
     self.plot = 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)
예제 #7
0
    def __init__(self, options, **kwtraits):
        super(FiberView, self).__init__(**kwtraits)
        self.model = FiberModel(options)

        # debugging
        self.debug = options.debug
        self.model.debug = options.debug

        # timing parameters
        self.max_packets = options.max_packets
        self.hertz = options.hertz

        # extend options to model
        self.model.max_packets = options.max_packets
        self.model.preallocate_arrays()
        self.model.num_analog_channels = options.num_analog_channels

        # generate traits plot
        self.plot_data = ArrayPlotData(x=self.model._tdata,
                                       y=self.model._ydata)
        self.plot = Plot(self.plot_data)
        renderer = self.plot.plot(("x", "y"),
                                  type="line",
                                  name='old',
                                  color="green")[0]
        #        self.plot.delplot('old')

        # recording flags
        self.model.recording = False
        self.model.trialEnded = True

        print 'Viewer initialized.'

        # should we wait for a ttl input to start?
        if options.ttl_start:
            self.model.ttl_start = True
            self.ttl_received = False

            # initialize FIO0 for TTL input
            self.FIO0_DIR_REGISTER = 6100
            self.FIO0_STATE_REGISTER = 6000
            self.model.labjack.writeRegister(self.FIO0_DIR_REGISTER,
                                             0)  # Set FIO0 low

        # initialize output array
        self.out_arr = None

        # keep track of number of runs
        self.run_number = 0

        self.timer = Timer(self.model.dt,
                           self.time_update)  # update every 1 ms
예제 #8
0
    def init_gui_component(self):
        self.ifs_triangle = IFSTriangles(self.ax)
        self.figure.canvas.draw()  
        try:
            with file("ifs_matplotlib.data","rb") as f:
                tmp = pickle.load(f)
                self.ifs_names = [x[0] for x in tmp]                
                self.ifs_points = [np.array(x[1]) for x in tmp]

            if len(self.ifs_names) > 0:
                self.current_name = self.ifs_names[-1]
        except:
            pass        
        self.timer = Timer(10, self.ifs_calculate)     
    def __init__(self):
        #读入图像
        img = cv.imread("lena_full.jpg")
        img2 = cv.Mat()
        cv.cvtColor(img, img2, cv.CV_BGR2GRAY)
        img = cv.Mat()
        cv.resize(img2, img, cv.Size(N, N))
        self.fimg = fft.fft2(img[:])  # 图像的频域信号
        mag_img = np.log10(np.abs(self.fimg))

        # 创建计算用图像
        filtered_img = np.zeros((N, N), dtype=np.float)
        self.mask = np.zeros((N, N), dtype=np.float)
        self.mask_img = cv.asMat(self.mask)  # 在self.mask上绘制多边形用的图像

        # 创建数据源
        self.data = ArrayPlotData(mag_img=fft.fftshift(mag_img),
                                  filtered_img=filtered_img,
                                  mask_img=self.mask)

        # 创建三个图像绘制框以及容器
        meg_plot, img = self.make_image_plot("mag_img")
        mask_plot, _ = self.make_image_plot("mask_img")
        filtered_plot, _ = self.make_image_plot("filtered_img")
        self.plot = HPlotContainer(meg_plot, mask_plot, filtered_plot)

        # 创建套索工具
        lasso_selection = LassoSelection(component=img)
        lasso_overlay = LassoOverlay(lasso_selection=lasso_selection,
                                     component=img,
                                     selection_alpha=0.3)
        img.tools.append(lasso_selection)
        img.overlays.append(lasso_overlay)
        self.lasso_selection = lasso_selection

        # 监听套索工具的事件、开启时钟事件
        lasso_selection.on_trait_change(self.lasso_updated,
                                        "disjoint_selections")
        self.timer = Timer(50, self.on_timer)
예제 #10
0
def main():
		def sys_var(name):
			return os.popen("echo $"+name).readline()[:-1]
		# Change this to suit your needs.	Edit the file after running this
		# script and the pipeline should be updated automatically.
		tmpdir="seatree." + sys_var("USER") + "." #+ sys_var("$")
		fulltmpdir = fnmatch.filter(os.listdir('/tmp/.'),tmpdir+"*")
		tmpdirpath = os.sep+"tmp"+os.sep + fulltmpdir[0] + os.sep
		model = tmpdirpath + 'model.vtk'
		
		vtkpath = os.path.abspath(".." + os.sep + ".." + os.sep + "plotter" + os.sep + "vtk_objects")
		coast = vtkpath + os.sep + "coastline.vtk"
		plate = vtkpath + os.sep + "nuvel.vtk"
		
		#Move the earth to a more interesting viewing angle
		sc = mayavi.new_scene()
		#sc = mayavi.scenes[0]
		sc.scene.camera.position = [-2.7052003426618358, -5.734319456638211, 2.1247131906105454]
		sc.scene.camera.focal_point = [0.0, 0.0, 0.0]
		sc.scene.camera.view_angle = 30.0
		sc.scene.camera.view_up = [-0.2466025971449512, 0.43686490479728257, 0.86506428318236928]
		sc.scene.camera.clipping_range = [3.4791144146559461, 10.741021597415996]
		sc.scene.camera.compute_view_plane_normal()
		
		coastdata = setup_data(coast)
		view_data("black")
		
		platedata = setup_data(plate)
		view_data("white")
		
		modeldata = setup_data(model)
		view_model()

		# Poll the file.
		p = Pollster(model, modeldata)
		timer = Timer(3000, p.poll_file)
		# Keep a reference on the timer
		mayavi2.savedtimerbug = timer
 def __init__(self):
     self.pendulum = DoublePendulum(self.m1, self.m2, self.l1, self.l2)
     self.pendulum.init_status[:] = 1.0, 2.0, 0, 0
     self.graph = DoublePendulumComponent()
     self.graph.gui = self
     self.timer = Timer(10, self.on_timer)
예제 #12
0
 def init(self, info):
     super(AnimationHandler, self).init(info)
     info.object.timer = Timer(10, info.object.on_timer)
예제 #13
0
 def _timer_default(self):
     return Timer(int(self.interval * 1000), self._timer_event)