spacr.qt.widgets.gate_console¶
A console and a chat box beside the gating surface.
Two panes with one job between them: let the user ask a question about the table they are gating without leaving the screen to do it.
ConsoleRuns an expression against the CURRENT frame and prints the answer. Not a Python shell – a Python shell in a GUI is a way to hang the GUI, and the questions that come up while gating are all of one shape: “how many objects satisfy this”, “what is the median of that”. So it evaluates pandas expressions with the frame in scope and nothing else.
ChatThe same box, addressed in English. It is wired to whatever assistant the host provides and is EMPTY when none is configured – it says so rather than pretending to think, because a chat box that silently ignores you is worse than one that is honestly unavailable.
Both write into one transcript, so the record of what was asked and what came back reads in order regardless of which pane asked.
Classes¶
The console and the chat box, sharing one transcript. |
Functions¶
|
Answer one question about |
Module Contents¶
- class spacr.qt.widgets.gate_console.GateConsole(parent=None)[source]¶
Bases:
PySide6.QtWidgets.QWidgetThe console and the chat box, sharing one transcript.
- Parameters:
parent – parent widget.
Build the console that answers questions about the gated table.
- Parameters:
parent – parent widget, or
None.
- ask(question: str) str[source]¶
Put a question to the assistant, or say there is not one.
- Parameters:
question – the question text, stripped; empty does nothing and returns
"". It is written to the console, emitted onaskedand passed to the responder, if one is set.
- reply(answer: str) None[source]¶
Record an answer that arrived later, from an async host.
- Parameters:
answer – the answer text, written to the console as given (converted with
str).
- run(expression: str) str[source]¶
Evaluate
expressionand record both halves.- Parameters:
expression – a Python expression over the loaded table, as
evaluate()takes it; stripped, and empty does nothing and returns"".
- run_input() None[source]¶
Run whatever is typed, clearing the box only if it was accepted.
CLEARED ONLY ON SUCCESS, so a refused expression stays where the user can fix it rather than having to be retyped from memory.
- set_frame(frame: pandas.DataFrame | None) None[source]¶
Point the console at a table to gate.
- Parameters:
frame – the rows, or None to clear.
- set_responder(responder: Callable[[str], str] | None) None[source]¶
Give the chat box something to answer with.
Without one it says it is not configured rather than staying silent: a chat box that ignores you is worse than one that is honestly unavailable.
- Parameters:
responder – a callable taking the question text and returning the answer, or
Noneto remove it. An exception it raises is shown as the answer.
- spacr.qt.widgets.gate_console.evaluate(expression: str, frame: pandas.DataFrame | None) str[source]¶
Answer one question about
frame.The frame is in scope as
df, and every column as itself, soarea.mean()anddf['area'].mean()both work – the first is what people type.Errors come back as text rather than exceptions: this is a question box, and a typo is a normal thing to do in one.
- Parameters:
expression – a Python expression, stripped; empty returns
"". It is evaluated withdf,pd,npand every column whose name is an identifier in scope, and a restricted set of builtins.frame – the table to question;
Noneor an empty frame returns"no table loaded".