Exemple #1
0
    def __init__(self, pilot, x_width=50, parent=None):
        """
        Args:
            pilot (str): The name of our pilot
            x_width (int): How many trials in the past should we plot?
        """
        #super(Plot, self).__init__(QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers), parent)
        super(Plot, self).__init__()

        self.logger = init_logger(self)

        self.parent = parent
        self.layout = None
        self.infobox = None
        self.n_trials = None
        self.session_trials = 0
        self.info = {}
        self.plot = None
        self.xrange = None
        self.plot_params = {}
        self.data = {
        }  # Keep a dict of the data we are keeping track of, will be instantiated on start
        self.plots = {}
        self.state = "IDLE"
        self.continuous = False
        self.last_time = 0
        self.video = None
        self.videos = []

        self.invoker = get_invoker()

        # The name of our pilot, used to listen for events
        self.pilot = pilot

        # Set initial x-value, will update when data starts coming in
        self.x_width = x_width
        self.last_trial = self.x_width

        # Inits the basic widget settings
        self.init_plots()

        ## Station
        # Start the listener, subscribes to terminal_networking that will broadcast data
        self.listens = {
            'START': self.l_start,  # Receiving a new task
            'DATA': self.l_data,  # Receiving a new datapoint
            'CONTINUOUS': self.l_data,
            'STOP': self.l_stop,
            'PARAM': self.l_param,  # changing some param
            'STATE': self.l_state
        }

        self.node = Net_Node(id='P_{}'.format(self.pilot),
                             upstream="T",
                             port=prefs.get('MSGPORT'),
                             listens=self.listens,
                             instance=True)
Exemple #2
0
    def wrapper_gui_event(*args, **kwargs):
        # type: (object, object) -> None
        """

        Args:
            *args (): 
            **kwargs (): 
        """
        QtCore.QCoreApplication.postEvent(get_invoker(),
                                          InvokeEvent(fn, *args, **kwargs))
    def __init__(self):
        # type: () -> None
        super(Terminal, self).__init__()

        # store instance
        globals()['_TERMINAL'] = self

        # networking
        self.node = None
        self.networking = None
        self.heartbeat_dur = 10  # check every n seconds whether our pis are around still

        # data
        self.subjects = {}  # Dict of our open subject objects

        # gui
        self.layout = None
        self.widget = None
        self.file_menu = None
        self.tool_menu = None
        self.control_panel = None
        self.data_panel = None
        self.logo = None

        # property private attributes
        self._pilots = None

        # logging
        self.logger = init_logger(self)

        # Listen dictionary - which methods to call for different messages
        # Methods are spawned in new threads using handle_message
        self.listens = {
            'STATE': self.l_state,  # A Pi has changed state
            'PING': self.l_ping,  # Someone wants to know if we're alive
            'DATA': self.l_data,
            'CONTINUOUS':
            self.l_data,  # handle continuous data same way as other data
            'STREAM': self.l_data,
            'HANDSHAKE':
            self.l_handshake  # a pi is making first contact, telling us its IP
        }

        # Make invoker object to send GUI events back to the main thread
        # self.invoker = Invoker()
        self.invoker = get_invoker()
        # prefs.add('INVOKER', self.invoker)

        self.initUI()

        # Start Networking
        # Networking is in two parts,
        # "internal" networking for messages sent to and from the Terminal object itself
        # "external" networking for messages to and from all the other components,
        # The split is so the external networking can run in another process, do potentially time-consuming tasks
        # like resending & confirming message delivery without blocking or missing messages

        self.node = Net_Node(id="_T",
                             upstream='T',
                             port=prefs.get('MSGPORT'),
                             listens=self.listens)
        self.logger.info("Net Node Initialized")

        # Start external communications in own process
        # Has to be after init_network so it makes a new context
        self.networking = Terminal_Station(self.pilots)
        self.networking.start()
        self.logger.info("Station object Initialized")

        # send an initial ping looking for our pilots
        self.node.send('T', 'INIT')

        # start beating ur heart
        # self.heartbeat_timer = threading.Timer(self.heartbeat_dur, self.heartbeat)
        # self.heartbeat_timer.daemon = True
        # self.heartbeat_timer.start()
        #self.heartbeat(once=True)
        self.logger.info('Terminal Initialized')