Esempio n. 1
0
    def setup(self):

        ''' 
            process custom settings that might have been set after initializing
            the object.  
        '''
        # check if these parameters / properties / attributes were actually set!
        self.USE_MMAP = getattr(self, 'receive_data_from_matlab', self.USE_MMAP)
        self.SETTINGS.COLOR_TO_USE = getattr(self, 'COLOR_TO_USE', self.SETTINGS.COLOR_TO_USE)

        # add 'abs_plugin_ID' to plugin name.
        self.PLUGIN_NAME = self.PLUGIN_NAME + '-' + str(self.abs_plugin_ID)


        ''' set variables based on init() values. '''
        self.Y_LIMS = [0, self.SETTINGS.WINDOW_HEIGHT_DEFAULT]
        self.SETTINGS.WINDOW_WIDTH_CURRENT = self.SETTINGS.WINDOW_WIDTH_DEFAULT
        self.SETTINGS.WINDOW_HEIGHT_CURRENT = self.SETTINGS.WINDOW_HEIGHT_DEFAULT

        ''' setup mmap or random data interface '''
        status, self.MMAP, self.RANDOM_DATA = setup_incoming_data_interface(self.USE_MMAP, self.PLUGIN_NAME, self.NBR_CHANNELS, self.nPointsToUpdate, self.nPoints, self.SETTINGS.WINDOW_WIDTH_CURRENT, self.SETTINGS.WINDOW_HEIGHT_CURRENT)
        if not status:
             sys.exit(1)


        ''' setup plot queue '''
        self.plot_queue = setup_plotting_queue()


        ''' generate initial positions & colors, and setup VOBs '''
        self.vbo_data, self.vbo_colors, self.x_coords, self.SETTINGS.COLOR_USED = \
            gl_setup_initial_data_and_color_and_vbos(self.nPoints, n_COORDINATES_PER_COLOR, self.NBR_CHANNELS, self.SETTINGS)


        ''' horizontal and vertical lines - setup even if user doesn't want 
            to see them, because we setup key press functions to en-/disable them. '''
        # horizontal line showing the threshold 
        self.line_hor = line_default_horizontal(self)

        # vertical line showing which data point is going to be update next 
        self.line_ver = line_default_vertical(self)

        ''' axes - setup even it user doesn't want to see it, because of kpf. '''
        self.coord_axes, self.y_axis_tics = axes_default_with_y_ticks(self)


        ''' other stuff '''
        # is Tkinter installed and running?
        self.SETTINGS = tkinter_register_with_settings(self.SETTINGS)

        # set the window caption. Can't do it in 'setup_window' because some parameters
        # are not processed there yet.
        self.setup_window_caption()
    def on_key_press(self, symbol, modifiers):

        # offset that needs to be added to 'key.MOD_*' in order to match the
        # 'modifiers' value
        mod_offset = 16
        ''' key press function for y limits '''
        key_matched = self.kpf_change_y_lims(symbol, modifiers, mod_offset)
        # skip remainder of key press function in case 'kpf_change_y_lims' had a hit.
        if key_matched:
            return
        ''' key press function for horizontal line '''
        key_matched = self.kpf_change_horizontal_line(symbol, modifiers,
                                                      mod_offset)
        # skip remainder of key press function in case 'kpf_change_horizontal_line' had a hit.
        if key_matched:
            return
        ''' remaining keys '''
        if symbol == key.A:
            if modifiers == key.MOD_CTRL + mod_offset:
                if self.SHOW_AXES:
                    self.coord_axes, self.y_axis_tics, self.SHOW_AXES = False, False, False
                else:
                    self.SHOW_AXES = True
                    self.coord_axes, self.y_axis_tics = axes_default_with_y_ticks(
                        self.SETTINGS, self.Y_LIMS)

        elif symbol == key.C:
            self.plot_queue = setup_plotting_queue()
            print "Cleared Plot-Queue"

        elif symbol == key.F:  # show / hide FPS display
            self.SHOW_FPS = not self.SHOW_FPS

        elif symbol == key.H:  # show help menu
            print " "
            print "      *** HELP ***"
            print " "
            print "\t 0: \t\t\trestore original y-lims"
            print "\t 1: \t\t\tdecrease upper y-lim"
            print "\t 2: \t\t\tincrease upper y-lim"
            print "\t 3: \t\t\tdecrease lower y-lim"
            print "\t 4: \t\t\tincrease lower y-lim"
            print "\t a + ctrl: \t\tshow / hide axes"
            print "\t f: \t\t\tshow / hide FPS display"
            print "\t q: \t\t\tshow number of elements in plot queue"
            print "\t t: \t\t\tset position of horizontal line"
            print "\t t + shift: \t\tprint out current position of horizontal line"
            print "\t t + ctrl: \t\tshow / hide horizontal line"
            print "\t v + ctrl: \t\tshow / hide vertical line"
            print "\t y: \t\t\tset upper y-lim to value from command line"
            print "\t y + shift: \t\tset lower y-lim to value from command line"
            print "\t y + ctrl: \t\tset upper and lower y limits through GUI"
            print "\t arrow up: \t\tmove horizontal line up by one"
            print "\t arrow down: \t\tmove horizontal line down by one"
            print "\t arrow up + shift: \tmove horizontal line up by five"
            print "\t arrow down + shift: \tmove horizontal line down by five"
            print "\t space bar: \t\tpause / resume screen update"
            print " "

        elif symbol == key.Q:  # show number of elements in plot queue
            print "Plot-Queue size: %d" % (len(self.plot_queue))

        elif symbol == key.V:  # show / hide vertical line (toggle display of vertical line)
            if modifiers == key.MOD_CTRL + mod_offset:
                if not self.SHOW_VERTICAL_LINE:
                    self.line_ver = line_default_vertical(
                        self.SETTINGS.WINDOW_HEIGHT_CURRENT, self.x_coords)
                self.SHOW_VERTICAL_LINE = not self.SHOW_VERTICAL_LINE

        elif symbol == key.ESCAPE:  # quit program
            sys.exit()

        elif symbol == key.SPACE:  # freeze / resume plotting
            self.DO_DRAW = not self.DO_DRAW
    def on_key_press(self, symbol, modifiers):

        # offset that needs to be added to 'key.MOD_*' in order to match the
        # 'modifiers' value
        mod_offset = 16

        """ key press function for y limits """
        key_matched = self.kpf_change_y_lims(symbol, modifiers, mod_offset)
        # skip remainder of key press function in case 'kpf_change_y_lims' had a hit.
        if key_matched:
            return

        """ key press function for horizontal line """
        key_matched = self.kpf_change_horizontal_line(symbol, modifiers, mod_offset)
        # skip remainder of key press function in case 'kpf_change_horizontal_line' had a hit.
        if key_matched:
            return

        """ remaining keys """
        if symbol == key.A:
            if modifiers == key.MOD_CTRL + mod_offset:
                if self.SHOW_AXES:
                    self.coord_axes, self.y_axis_tics, self.SHOW_AXES = False, False, False
                else:
                    self.SHOW_AXES = True
                    self.coord_axes, self.y_axis_tics = axes_default_with_y_ticks(self.SETTINGS, self.Y_LIMS)

        elif symbol == key.C:
            self.plot_queue = setup_plotting_queue()
            print "Cleared Plot-Queue"

        elif symbol == key.F:  # show / hide FPS display
            self.SHOW_FPS = not self.SHOW_FPS

        elif symbol == key.H:  # show help menu
            print " "
            print "      *** HELP ***"
            print " "
            print "\t 0: \t\t\trestore original y-lims"
            print "\t 1: \t\t\tdecrease upper y-lim"
            print "\t 2: \t\t\tincrease upper y-lim"
            print "\t 3: \t\t\tdecrease lower y-lim"
            print "\t 4: \t\t\tincrease lower y-lim"
            print "\t a + ctrl: \t\tshow / hide axes"
            print "\t f: \t\t\tshow / hide FPS display"
            print "\t q: \t\t\tshow number of elements in plot queue"
            print "\t t: \t\t\tset position of horizontal line"
            print "\t t + shift: \t\tprint out current position of horizontal line"
            print "\t t + ctrl: \t\tshow / hide horizontal line"
            print "\t v + ctrl: \t\tshow / hide vertical line"
            print "\t y: \t\t\tset upper y-lim to value from command line"
            print "\t y + shift: \t\tset lower y-lim to value from command line"
            print "\t y + ctrl: \t\tset upper and lower y limits through GUI"
            print "\t arrow up: \t\tmove horizontal line up by one"
            print "\t arrow down: \t\tmove horizontal line down by one"
            print "\t arrow up + shift: \tmove horizontal line up by five"
            print "\t arrow down + shift: \tmove horizontal line down by five"
            print "\t space bar: \t\tpause / resume screen update"
            print " "

        elif symbol == key.Q:  # show number of elements in plot queue
            print "Plot-Queue size: %d" % (len(self.plot_queue))

        elif symbol == key.V:  # show / hide vertical line (toggle display of vertical line)
            if modifiers == key.MOD_CTRL + mod_offset:
                if not self.SHOW_VERTICAL_LINE:
                    self.line_ver = line_default_vertical(self.SETTINGS.WINDOW_HEIGHT_CURRENT, self.x_coords)
                self.SHOW_VERTICAL_LINE = not self.SHOW_VERTICAL_LINE

        elif symbol == key.ESCAPE:  # quit program
            sys.exit()

        elif symbol == key.SPACE:  # freeze / resume plotting
            self.DO_DRAW = not self.DO_DRAW
    def setup(self):
        ''' set variables based on init() values. '''
        self.Y_LIMS = [0, self.SETTINGS.WINDOW_HEIGHT_DEFAULT]
        self.SETTINGS.WINDOW_WIDTH_CURRENT = self.SETTINGS.WINDOW_WIDTH_DEFAULT
        self.SETTINGS.WINDOW_HEIGHT_CURRENT = self.SETTINGS.WINDOW_HEIGHT_DEFAULT

        # add 'abs_plugin_ID' to plugin name.
        self.PLUGIN_NAME = self.PLUGIN_NAME + '-' + str(self.abs_plugin_ID)
        ''' setup mmap or random data interface '''
        status, self.MMAP, self.DATA = setup_incoming_data_interface(
            self.USE_MMAP, self.PLUGIN_NAME, self.NBR_CHANNELS,
            self.nPointsToUpdate, self.nPoints,
            self.SETTINGS.WINDOW_WIDTH_CURRENT,
            self.SETTINGS.WINDOW_HEIGHT_CURRENT)
        if not status:
            sys.exit(1)
        ''' setup plot queue '''
        self.plot_queue = setup_plotting_queue()
        ''' generate initial positions & colors, and setup VOBs '''
        self.vbo_data, self.vbo_colors, self.x_coords = \
         gl_setup_initial_data_and_color_and_vbos(self.nPoints, n_COORDINATES_PER_COLOR, self.NBR_CHANNELS, self.SETTINGS.WINDOW_WIDTH_DEFAULT, self.SETTINGS.WINDOW_HEIGHT_DEFAULT)
        ''' horizontal and vertical lines '''
        # horizontal line showing the threshold
        if self.SHOW_HORIZONTAL_LINE:
            self.line_hor = line_default_horizontal(self)

        # vertical line showing which data point is going to be update next
        if self.SHOW_VERTICAL_LINE:
            self.line_ver = line_default_vertical(self)
        ''' axes '''
        if self.SHOW_AXES:
            self.coord_axes, self.y_axis_tics = axes_default_with_y_ticks(self)
        ''' other stuff '''
        # is Tkinter installed and running?
        self.SETTINGS = tkinter_register_with_settings(self.SETTINGS)

        # set default gl modes
        set_gl_defaults(self.POINT_SIZE)

        # try to render a smooth line (if supported by driver)
        gl_enable_line_smoothing()

        # set window title
        win_title = 'generating random data'
        if self.USE_MMAP:
            win_title = 'receiving data from matlab'
        nbr_points_shown = ' -- showing %s points per panel.' % self.nPoints
        self.set_caption(self.PLUGIN_NAME + ' -- ' + win_title +
                         nbr_points_shown)

        # hide mouse - disabled.
        # self.set_mouse_visible(False)

        # schedule the 'update()' method to be called each 'update_interval'
        pyglet.clock.schedule_interval(self.update, self.update_interval)

        # Create a font for our FPS clock
        ft = pyglet.font.load('Arial', 28)
        self.fps_display = pyglet.clock.ClockDisplay(font=ft,
                                                     interval=0.125,
                                                     format='FPS %(fps).2f')
    def setup(self):

        """ set variables based on init() values. """
        self.Y_LIMS = [0, self.SETTINGS.WINDOW_HEIGHT_DEFAULT]
        self.SETTINGS.WINDOW_WIDTH_CURRENT = self.SETTINGS.WINDOW_WIDTH_DEFAULT
        self.SETTINGS.WINDOW_HEIGHT_CURRENT = self.SETTINGS.WINDOW_HEIGHT_DEFAULT

        # add 'abs_plugin_ID' to plugin name.
        self.PLUGIN_NAME = self.PLUGIN_NAME + "-" + str(self.abs_plugin_ID)

        """ setup mmap or random data interface """
        status, self.MMAP, self.DATA = setup_incoming_data_interface(
            self.USE_MMAP,
            self.PLUGIN_NAME,
            self.NBR_CHANNELS,
            self.nPointsToUpdate,
            self.nPoints,
            self.SETTINGS.WINDOW_WIDTH_CURRENT,
            self.SETTINGS.WINDOW_HEIGHT_CURRENT,
        )
        if not status:
            sys.exit(1)

        """ setup plot queue """
        self.plot_queue = setup_plotting_queue()

        """ generate initial positions & colors, and setup VOBs """
        self.vbo_data, self.vbo_colors, self.x_coords = gl_setup_initial_data_and_color_and_vbos(
            self.nPoints,
            n_COORDINATES_PER_COLOR,
            self.NBR_CHANNELS,
            self.SETTINGS.WINDOW_WIDTH_DEFAULT,
            self.SETTINGS.WINDOW_HEIGHT_DEFAULT,
        )

        """ horizontal and vertical lines """
        # horizontal line showing the threshold
        if self.SHOW_HORIZONTAL_LINE:
            self.line_hor = line_default_horizontal(self)

            # vertical line showing which data point is going to be update next
        if self.SHOW_VERTICAL_LINE:
            self.line_ver = line_default_vertical(self)

        """ axes """
        if self.SHOW_AXES:
            self.coord_axes, self.y_axis_tics = axes_default_with_y_ticks(self)

        """ other stuff """
        # is Tkinter installed and running?
        self.SETTINGS = tkinter_register_with_settings(self.SETTINGS)

        # set default gl modes
        set_gl_defaults(self.POINT_SIZE)

        # try to render a smooth line (if supported by driver)
        gl_enable_line_smoothing()

        # set window title
        win_title = "generating random data"
        if self.USE_MMAP:
            win_title = "receiving data from matlab"
        nbr_points_shown = " -- showing %s points per panel." % self.nPoints
        self.set_caption(self.PLUGIN_NAME + " -- " + win_title + nbr_points_shown)

        # hide mouse - disabled.
        # self.set_mouse_visible(False)

        # schedule the 'update()' method to be called each 'update_interval'
        pyglet.clock.schedule_interval(self.update, self.update_interval)

        # Create a font for our FPS clock
        ft = pyglet.font.load("Arial", 28)
        self.fps_display = pyglet.clock.ClockDisplay(font=ft, interval=0.125, format="FPS %(fps).2f")