neurocarto.views.base

neurocarto.views.base.Figure

alias of figure

class neurocarto.views.base.ViewBase

View component base class.

__init__(config, *, logger=None)
Parameters:
logger: Logger
abstract property name: str

view name

property description: str | None

view description. show in help button.

view_title: Div
view_status: Div
view_content: UIElement
setup(f, **kwargs)

Setup controls and plotting.

Parameters:
  • f (figure) – figure in middle panel

  • kwargs – control or plotting related parameters.

Returns:

row list.

Return type:

list[UIElement]

start()

Invoked when figure is ready.

set_status(text, *, decay=None)

Set status message, which is shown right beside the help button in the title row.

Parameters:
  • text (str | None) – message

  • decay (float | None) – after give seconds, clear the message. If None, show forever until replaced.

final log_message(*message, reset=False)

log messages in CartoApp.

Warning

do not overwrite this function, because this method will be replaced by CartoApp.

Parameters:
  • message (str) – message in lines.

  • reset – reset message area.

class neurocarto.views.base.ControllerView

This view component is a controller view that it purpose to control {CartoApp} or other {ViewBase}.

final get_app()

Get CartoApp instance.

Warning

do not overwrite this function, because this method will be replaced by CartoApp.

Returns:

Return type:

CartoApp

final get_view(view_type)

Get corresponding ViewBase instance if activated.

Warning

do not overwrite this function, because this method will be replaced by CartoApp.

Parameters:

view_type (str | type[V]) – view type or its type name.

Returns:

Return type:

V | None

new_blueprint_function(probe, chmap=None)

Create a BlueprintFunctions with controller supports.

Parameters:
  • probe (str | ProbeDesp) – ProbeDesp or a module path

  • chmap (int | str | M | None) – channelmap instance.

Returns:

an empty BlueprintFunctions

Return type:

BlueprintFunctions

class neurocarto.views.base.StateView

This view component can save a state with a channelmap into a project config. It also can read the config and restore the state.

The state will be stored (invoke save_state()) when a corresponding channelmap has saved. The state will be restored (invoke restore_state()) when a corresponding channelmap has loaded.

Parameters:

S – stored information. It should be json-serializable. We usually use a TypedDict.

abstract save_state()

Save current state into S.

Returns:

json-serializable instance.

Return type:

S | None

abstract restore_state(state)

Restore state from state.

Parameters:

state (S) – json-deserializable instance.

class neurocarto.views.base.GlobalStateView

This view component can save a global state into a user config, which is shared across projects (channelmaps). It also can read the config and restore the state.

Due to it also inherit from StateView, it is able to save a local state into a project config. The state S can be either shared (user and project config) or separate.

For a local state, storing and restoring are following a channelmap file (as same as StateView). However, for a global state, storing and restoring will not be triggered by CartoApp automatically. The view needs to explicitly use save_global_state() or restore_global_state() to make it happen.

Parameters:

S – stored information. It should be json-serializable. We usually use a TypedDict.

disable_save_global_state = False

disable {#restore_global_state()} for debugging purposes to prevent testing content from polluting config.

save_state(local=True)

Save current state into S.

Default returning None, which indicate this view only read config and never write config.

Parameters:

local – Is this state going to be saved into a project config?

Returns:

json-serializable instance.

Return type:

S | None

final save_global_state(state=None, *, sync=False, force=False)

save state into user config.

Although CartoApp will invoke save_state() when the session is closed, the timing is not guarantied. It is better to call this method when any global option is modified.

Warning

do not overwrite this function, because this method will be replaced by CartoApp.

Parameters:
final restore_global_state(*, reload=False, force=False)

read user config and invoke StateView. restore_state().

Remember to invoke this method when ViewBase. start() to restore the global state.

Warning

do not overwrite this function, because this method will be replaced by CartoApp.

Parameters:
  • reload – reload config from disk

  • force – force invoke StateView. restore_state() (give an empty dict), even when the config is not existed.

class neurocarto.views.base.DynamicView

This view component needs to be aware on modification of channelmap and electrodes.

on_probe_update(probe, chmap, electrodes)

Invoked when channelmap is changed or electrode’s category is changed.

Parameters:
  • probe (ProbeDesp[M, E]) – probe interface.

  • chmap (M | None) – channelmap instance.

  • electrodes (list[E] | None) – all electrodes.

class neurocarto.views.base.EditorView

This view provider the editing function on channelmap or blueprint.

final update_probe()

notify GUI probe has updated.

Warning

do not call this method in DynamicView. on_probe_update(). It may cause recursive call.

do not overwrite this function, because this method will be replaced by CartoApp.

class neurocarto.views.base.ExtensionView

This view component require some probe specific operations, and it is only enabled/activated when the probe fit the requirements.

In general, it requires a ProbeDesp implement some functions or a Protocol class. init_view() use is_supported() to determine whether it needs to initialize this view or not.

classmethod is_supported(probe)

Check whether a probe fit the requirements.

Parameters:

probe (ProbeDesp)

Return type:

bool

class neurocarto.views.base.InvisibleView

This view component’s visible state is controlled by CartoApp.

visible_btn: Switch
property visible: bool
setup_visible_switch()

Setup visible switch control.

Return type:

Switch

on_visible(visible)

visible state changed callback.

Parameters:

visible (bool) – new visible state

class neurocarto.views.base.RecordView

This view can record each manipulating steps and also can replay them.

Warning

It is an experimental feature.

Parameters:

R – RecordedAction. It should be json-serializable. We usually use a TypedDict.

final add_record(record, category, description)

add a record into history.

Warning

do not overwrite this function, because this method will be replaced by RecordManager.

Parameters:
  • record (R) – stored step. type should be json-serializable.

  • category (str) – step category

  • description (str) – step description

filter_records(records, *, reset=False)

Filter records which source came from itself.

It is also used to modify the records and return the equivalence steps.

Parameters:
  • records (list[RecordStep])

  • reset – reset view to the initial state? If so, you can add extra action in return.

Returns:

filtered records

Return type:

list[RecordStep]

abstract replay_record(record)

Replay the record step.

Warning

Do not call this method directly, because it might cause add_record() be invoked during the replay. Use RecordManager. replay() instead.

Parameters:

record (RecordStep)

class neurocarto.views.base.RecordStep

Recorded action for saving.

Warning

It is an experimental feature.

source: str

(class) name of the source RecordView

time_stamp: float

action time stamp in unix time

category: str

action category

description: str

action description

record: R

json-serializable

with_record(record)
Parameters:

record (R)

Return type:

Self

as_dict()
Return type:

dict

classmethod from_dict(record)
Parameters:

record (dict)

Return type:

Self

static __new__(_cls, source, time_stamp, category, description, record)

Create new instance of RecordStep(source, time_stamp, category, description, record)

Parameters:
  • source (str)

  • time_stamp (float)

  • category (str)

  • description (str)

  • record (R)

class neurocarto.views.base.BoundaryState

Boundary parameters

dx: float

x moving (um)

dy: float

y moving (um)

sx: float

x scaling

sy: float

y scaling

rt: float

rotating (degree)

class neurocarto.views.base.BoundView

This view component has draw a rectangle-like (shorten as image) on the plotting, and supporting moving, scaling and rotating. This class provide a framework for supporting image transforming.

This class handle a rectangle as boundary. The image should follow the boundary updating.

Event Call chain

(UI component)
    -/-> (event callback)
        -> update_boundary_transform()
            -> on_boundary_transform()
tool_boundary: BoxEditTool
render_boundary: GlyphRenderer
__init__(config, *, logger=None)
Parameters:
data_boundary: ColumnDataSource
abstract property width: float

Width of image

abstract property height: float

Height of image

setup_boundary(f, *, boundary_color='black', boundary_desp=None)

Setup boundary plotting in figure.

Parameters:
  • f (figure)

  • boundary_color (str) – boundary border color

  • boundary_desp (str | None) – figure tool hint description.

boundary_rotate_slider: Slider
boundary_scale_slider: Slider
setup_rotate_slider(*, new_btn=None, new_slider=None)

Setup image rotating controls.

Parameters:
Returns:

row list.

Return type:

list[UIElement]

setup_scale_slider(*, new_btn=None, new_slider=None)

Setup image scaling controls.

Parameters:
Returns:

row list.

Return type:

list[UIElement]

get_boundary_state()

Get current boundary parameters.

Return type:

BoundaryState

reset_boundary()
set_anchor_to(p, a=(0, 0))

Update boundary transform to move a onto p.

Parameters:
  • p (tuple[float, float]) – target point on figure. figure (probe) origin as origin.

  • a (tuple[float, float]) – anchor point on image, center point as origin.

update_boundary_transform(*, p=None, s=None, rt=None)

Image transforming updating handle.

Parameters:
  • p (tuple[float, float]) – center position (x, y)

  • s (float | tuple[float, float]) – scaling (sx, sy)

  • rt (float) – rotating degree

on_boundary_transform(state)

Image transforming updating callback.

Parameters:

state (BoundaryState) – updated boundary parameters.

transform_image_data(image, boundary=None)

A helper method for transforming an image data.

Parameters:
  • image (ndarray[tuple[int, ...], dtype[uint64]]) – image data

  • boundary (BoundaryState | None) – boundary parameters

Returns:

a dict which is ready for updating ColumnDataSource.

Return type:

dict[str, Any]