terminal
Methods for running the Terminal GUI
Classes:
|
Central host to a swarm of |
- class Terminal(self, parent: PySide6.QtWidgets.QWidget | None = None, flags: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags))
Bases:
QMainWindowCentral host to a swarm of
Pilots and user-facingguiobjects.Called as a module with the -f flag to give the location of a prefs file, eg:
python terminal.py -f prefs_file.json
if the -f flag is not passed, looks in the default location for prefs (ie. /usr/autopilot/prefs.json)
**Listens used by the internal
Net_Node**Key
Method
Description
‘STATE’
A Pi has changed state
‘PING’
Someone wants to know if we’re alive
‘DATA’
Receiving data to store
‘HANDSHAKE’
Pilot first contact, telling us it’s alive and its IP
Note
See
autopilot.prefsfor full list of prefs needed by terminal!Note
The Terminal class is currently a subclass of
PySide6.QtWidgets.QMainWindow– it will be refactored to inherit fromAgentas the agent system is formalized.- Variables:
node (
Net_Node) – Our Net_Node we use to communicate with our main networking objectnetworking (
Terminal_Station) – Our networking object to communicate with the outside worldsubjects (dict) – A dictionary mapping subject ID to
Subjectobject.layout (
QtWidgets.QGridLayout) – Layout used to organize widgetscontrol_panel (
Control_Panel) – Control Panel to manage pilots and subjectsdata_panel (
Plot_Widget) – Plots for each pilot and subject.logo (
QtWidgets.QLabel) – Label holding our beautiful logo ;Xlogger (
logging.Logger) – Used to log messages and network events.settings (
PySide2.QtCore.QSettings) – QSettings used to store pyside configuration like window size, stored inprefs.get("TERMINAL_SETTINGS_FN")
Initialize self. See help(type(self)) for accurate signature.
Methods:
Calibrate
hardware.gpio.Solenoidobjects.closeEvent(event)When Closing the Terminal Window, close any running subject objects, 'KILL' our networking object.
heartbeat([once])Perioducally send an
INITmessage that checks the status of connected pilotsinitUI()Initializes graphical elements of Terminal.
l_data(value)A Pilot has sent us data.
l_handshake(value)Pilot is sending its IP and state on startup.
l_ping(value)Todo
Reminder to implement heartbeating.
l_state(value)A Pilot has changed state, keep track of it.
new_pilot([name, ip, pilot_prefs])Make a new entry in
Terminal.pilotsand make appropriate GUI elements.Open a
gui.Protocol_Wizardto create a new protocol.ping_pilot(pilot)Select subject, step, and variables to plot a psychometric curve
Batch reassign protocols and steps.
reset_ui()Clear Layout and call
initUI()againOpen a window to stream videos from a connected pilot.
Gets recent weights from all
subjectsand open agui.Weightswindow to view or set weights.Test bandwidth of Pilot connection with variable sized arrays as paylods
toggle_start(starting, pilot[, subject])Start or Stop running the currently selected subject's task.
If we change the protocol file, update the stored version in subject files
Attributes:
A dictionary mapping pilot ID to its attributes, including a list of its subjects assigned to it, its IP, etc.
List of protocol names available in
PROTOCOLDIRGet a list of all subject IDs
Returns: subject_protocols (dict): a dictionary of subjects: [protocol, step]
- calibrate_ports()
Calibrate
hardware.gpio.Solenoidobjects.See
gui.Calibrate_Water.After calibration routine, send results to pilot for storage.
- closeEvent(event)
When Closing the Terminal Window, close any running subject objects, ‘KILL’ our networking object.
- heartbeat(once=False)
Perioducally send an
INITmessage that checks the status of connected pilotssent with frequency according to
Terminal.heartbeat_dur- Parameters:
once (bool) – if True, do a single heartbeat but don’t start a thread to do more.
- initUI()
Initializes graphical elements of Terminal.
Including…
Toolbar
gui.Control_Panelplots.Plot_Widget
- l_data(value)
A Pilot has sent us data.
value field of message should have subject and pilot added to dictionary for identification.
Any key in value that matches a column in the subject’s trial data table will be saved.
If the subject graduates after receiving this piece of data, stop the current task running on the Pilot and send the new one.
- Parameters:
value (dict) – A dict of field-value pairs to save
- l_handshake(value)
Pilot is sending its IP and state on startup.
If we haven’t heard of this pilot before, make a new entry in
pilotsandgui.Control_Panel.update_db().- Parameters:
value (dict) – dict containing ip and state
- l_ping(value)
Todo
Reminder to implement heartbeating.
Note
Currently unused, as Terminal Net_Node stability hasn’t been a problem and no universal system of heartbeating has been established (global stability has not been an issue).
- Parameters:
value – (unused)
- l_state(value)
A Pilot has changed state, keep track of it.
- Parameters:
value (dict) – dict containing state .
- manage_plugins()
- new_pilot(name: str | None = None, ip: str = '', pilot_prefs: dict | None = None)
Make a new entry in
Terminal.pilotsand make appropriate GUI elements.- Parameters:
ip (str) – Optional. if given, stored in db.
name (str) – If None, prompted for a name, otherwise used for entry in pilot DB.
- new_protocol()
Open a
gui.Protocol_Wizardto create a new protocol.Prompts for name of protocol, then saves in prefs.get(‘PROTOCOLDIR’)
- new_subject()
- property pilots: OrderedDict
A dictionary mapping pilot ID to its attributes, including a list of its subjects assigned to it, its IP, etc.
- Returns:
like
self.pilots['pilot_id'] = {'subjects': ['subject_0', 'subject_1'], 'ip': '192.168.0.101'}- Return type:
- ping_pilot(pilot)
- plot_psychometric()
Select subject, step, and variables to plot a psychometric curve
- property protocols: list
List of protocol names available in
PROTOCOLDIR- Returns:
list of protocol names in
prefs.get('PROTOCOLDIR')- Return type:
- reassign_protocols()
Batch reassign protocols and steps.
Opens a
gui.Reassignwindow after getting protocol data, and applies any changes made in the window.
- staticMetaObject = PySide6.QtCore.QMetaObject("Terminal" inherits "QMainWindow": )
- stream_video()
Open a window to stream videos from a connected pilot.
Choose from connected pilots and configured
Cameraobjects (prefs.jsonsent by Pilots inPilot.handshake()). Stream video, save to file.Todo
Configure camera parameters!!!
- property subject_list: list
Get a list of all subject IDs
- Returns:
list of all subject IDs present in
Terminal.pilots- Return type:
- property subject_protocols: dict
Returns: subject_protocols (dict): a dictionary of subjects: [protocol, step]
- subject_weights()
Gets recent weights from all
subjectsand open agui.Weightswindow to view or set weights.
- test_bandwidth()
Test bandwidth of Pilot connection with variable sized arrays as paylods
See
gui.Bandwidth_Test
- toggle_start(starting, pilot, subject=None)
Start or Stop running the currently selected subject’s task. Sends a message containing the task information to the concerned pilot.
Each
Pilot_Panelis given a lambda function that calls this one with the arguments specified SeePilot_Button, as it is what calls this function.- Parameters:
starting (bool) – Does this button press mean we are starting (True) or stopping (False) the task?
pilot – Which Pilot is starting or stopping?
subject – Which Subject is currently selected?
- update_protocols()
If we change the protocol file, update the stored version in subject files