Skip to content

QtMultiDictTagEditor#

Edit multiple named dictionaries together with an aggregate summary view.

Screenshot#

qt multi dict tag editor

Example#

Source: examples/qt_multi_dict_tag_editor.py

"""QtMultiDictTagEditor."""

from qtpy.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget

from qtextra.config import THEMES
from qtextra.widgets.qt_multi_dict_summary import QtMultiDictSummaryWidget
from qtextra.widgets.qt_multi_dict_tag_editor import QtMultiDictTagEditor

app = QApplication([])

widget = QWidget()
THEMES.apply(widget)

layout = QVBoxLayout(widget)

layout.addWidget(QLabel("QtMultiDictTagEditor + standalone summary"))
editor = QtMultiDictTagEditor()
summary = QtMultiDictSummaryWidget()
editor.evt_items_changed.connect(summary.set_items)
editor.set_items(
    {
        "sample_a": {
            "group": "control",
            "replicate": 1,
            "score": 0.91,
        },
        "sample_b": {
            "group": "treated",
            "replicate": 2,
            "score": 0.84,
            "note": None,
        },
        "sample_c": {
            "group": "treated",
            "replicate": 3,
        },
        "sample_d": {
            "group": "treated",
            "replicate": 3,
        },
        "sample_e": {
            "group": "treated",
            "replicate": 3,
        },
        "sample_f": {
            "group": "treated",
            "replicate": 3,
        },
        "sample_h": {
            "group": "treated",
            "replicate": 3,
        },
    },
)
body = QVBoxLayout()
body.addWidget(editor, stretch=1)
body.addWidget(summary, stretch=3)
layout.addLayout(body)

layout.addWidget(QLabel("Target one sample or all samples"))
editor.set_target_samples(["sample_b", "sample_c"])
editor.table.selectRow(0)

widget.resize(900, 700)
widget.show()

app.exec_()

Notes#

  • Useful when multiple samples or records share similar metadata fields.

API#

Qt Class#

QWidget

Signals#

evt_key_added#

evt_key_removed#

evt_search_changed#

evt_items_changed#

evt_value_changed#

evt_target_changed#

Methods#

Editor for managing multiple dictionaries side by side.

addCurrentKey = add_current_key class-attribute instance-attribute #

addKey = add_key class-attribute instance-attribute #

applyCurrentValue = apply_current_value class-attribute instance-attribute #

clearItems = clear_items class-attribute instance-attribute #

confirmClearItems = confirm_clear_items class-attribute instance-attribute #

exportDicts = export_dicts class-attribute instance-attribute #

getItems = items class-attribute instance-attribute #

getSampleNames = sample_names class-attribute instance-attribute #

getTargetSamples = current_target_samples class-attribute instance-attribute #

getValue = get_value class-attribute instance-attribute #

removeKey = remove_key class-attribute instance-attribute #

removeSelectedKey = remove_selected_key class-attribute instance-attribute #

setCurrentValueType = set_current_value_type class-attribute instance-attribute #

setItems = set_items class-attribute instance-attribute #

setSamples = set_samples class-attribute instance-attribute #

setTargetSamples = set_target_samples class-attribute instance-attribute #

setValue = set_value class-attribute instance-attribute #

add_current_key() -> bool #

Add the current key to the selected target.

add_key(key: str, value: DictTagValue = None, *, target_sample: str | None = None, target_samples: list[str] | None = None, value_type: str | None = None) -> bool #

Add a key to one sample or all samples.

apply_current_value() -> bool #

Apply the current value to the selected target for the current key.

clear_items(emit_signal: bool = True) -> None #

Remove all keys from all samples.

confirm_clear_items() -> bool #

Ask for confirmation before clearing all keys.

current_target_sample() -> str | None #

Return the current target sample when exactly one sample is selected.

current_target_samples() -> list[str] #

Return the currently selected target samples.

current_value_type() -> str #

Return the currently selected value type.

export_dicts() -> dict[str, dict[str, DictTagValue]] #

Export the current nested dictionaries.

get_value(key: str, sample: str) -> DictTagValue #

Return the typed value for a key in a sample.

items() -> dict[str, dict[str, DictTagValue]] #

Return the current sample dictionaries.

remove_key(key: str) -> bool #

Remove a key from all samples.

remove_selected_key() -> bool #

Remove the selected key row.

sample_names() -> list[str] #

Return the configured sample names.

select_all_samples() -> None #

Select every configured sample in the target picker.

set_current_value_type(value_type: str) -> None #

Set the current value type and refresh validation.

set_items(items: Mapping[str, Mapping[str, DictTagValue]]) -> None #

Replace all sample dictionaries.

set_samples(samples: list[str]) -> None #

Set the active sample names.

set_target_samples(samples: list[str]) -> None #

Set the selected target samples.

set_value(key: str, value: DictTagValue, *, target_sample: str | None = None, target_samples: list[str] | None = None, value_type: str | None = None) -> bool #

Set a value for a key in one sample or all samples.

Qt Class#

QWidget

Methods#

Summary panel for nested dictionary data.

clearItems = clear_items class-attribute instance-attribute #

setItems = set_items class-attribute instance-attribute #

summaryData = summary_data class-attribute instance-attribute #

build_summary(items: Mapping[str, Mapping[str, DictTagValue]]) -> dict classmethod #

Build structured summary data for nested dictionaries.

clear_items() -> None #

Clear all summaries.

set_items(items: Mapping[str, Mapping[str, DictTagValue]]) -> None #

Compute summaries from nested dictionaries.

summary_data() -> dict #

Return the computed summary structure.