# Qt widgets for data sets

This module provides a set of widgets to edit and show data sets, using ready-to-use dialog boxes, layouts and group boxes.

## Dialog boxes

class guidata.dataset.qtwidgets.DataSetEditDialog(instance: DataSet | DataSetGroup, icon: str | QIcon = '', parent: QWidget | None = None, apply: Callable | None = None, wordwrap: bool = True, size: QSize | tuple[int, int] | None = None)

  Bases: `QDialog`

  Dialog box for DataSet editing

  Parameters:

    - instance – DataSet instance to edit

    - icon – icon name (default: “guidata.svg”)

    - parent – parent widget

    - apply – function called when Apply button is clicked

    - wordwrap – if True, comment text is wordwrapped

    - size – dialog size (default: None)

  button_clicked(button: QAbstractButton) → None

    Handle button click

    Parameters:

      button – button that was clicked

  setup_instance(instance: Any) → None

    Construct main layout

    Parameters:

      instance – DataSet instance to edit

  layout_factory(instance: DataSet, grid: QGridLayout) → DataSetEditLayout

    A factory method that produces instances of DataSetEditLayout or derived classes (see DataSetShowDialog)

    Parameters:

      - instance – DataSet instance to edit

      - grid – grid layout

    Returns:

      DataSetEditLayout instance

  child_title(item: DataItemVariable) → str

    Return data item title combined with QApplication title

    Parameters:

      item – data item

    Returns:

      title

  check() → bool

    Check input of all widgets

    Returns:

      True if all widgets are valid

  accept() → None

    Validate inputs

class guidata.dataset.qtwidgets.DataSetShowDialog(instance: DataSet | DataSetGroup, icon: str | QIcon = '', parent: QWidget | None = None, apply: Callable | None = None, wordwrap: bool = True, size: QSize | tuple[int, int] | None = None)

  Bases: `DataSetEditDialog`

  Read-only dialog box

  Parameters:

    - instance – DataSet instance to edit

    - icon – icon name (default: “guidata.svg”)

    - parent – parent widget

    - apply – function called when Apply button is clicked

    - wordwrap – if True, comment text is wordwrapped

    - size – dialog size (default: None)

  layout_factory(instance: DataSet, grid: QGridLayout) → DataSetShowLayout

    A factory method that produces instances of DataSetEditLayout or derived classes (see DataSetShowDialog)

    Parameters:

      - instance – DataSet instance to edit

      - grid – grid layout

    Returns:

      DataSetEditLayout instance

class guidata.dataset.qtwidgets.DataSetGroupEditDialog(instance: DataSet | DataSetGroup, icon: str | QIcon = '', parent: QWidget | None = None, apply: Callable | None = None, wordwrap: bool = True, size: QSize | tuple[int, int] | None = None)

  Bases: `DataSetEditDialog`

  Tabbed dialog box for DataSet editing

  Parameters:

    - instance – DataSetGroup instance to edit

    - icon – icon name (default: “guidata.svg”)

    - parent – parent widget

    - apply – function called when Apply button is clicked

    - wordwrap – if True, comment text is wordwrapped

    - size – dialog size (default: None)

  setup_instance(instance: DataSetGroup) → None

    Construct main layout

    Parameters:

      instance – DataSetGroup instance to edit

## Layouts

class guidata.dataset.qtwidgets.DataSetEditLayout(parent: QWidget | None, instance: AnyDataSet, layout: QGridLayout, items: list[DataItem] | None = None, first_line: int = 0, change_callback: Callable | None = None, group_widget: GroupWidget | None = None)

  Bases: `Generic`[`AnyDataSet`]

  Layout in which data item widgets are placed

  Parameters:

    - parent – parent widget

    - instance – DataSet instance to edit

    - layout – grid layout

    - items – list of data items

    - first_line – first line of grid layout

    - change_callback – function called when any widget’s value has changed

    - group_widget – group widget associated with this layout, if any

  classmethod register(item_type: type, factory: Any) → None

    Register a factory for a new item_type

    Parameters:

      - item_type – item type

      - factory – factory function

  transform_items(items: list[DataItem]) → list[DataItem]

    Handle group of items: transform items into a GroupItem instance if they are located between BeginGroup and EndGroup

    Parameters:

      items – list of data items

    Returns:

      list of data items

  check_all_values() → bool

    Check input of all widgets

    Returns:

      True if all widgets are valid

  accept_changes() → None

    Accept changes made to widget inputs

  setup_layout(items: list[DataItem]) → None

    Place items on layout

    Parameters:

      items – list of data items

  build_widget(item: DataItem) → DataSetShowWidget

    Build widget for item

    Parameters:

      item – data item

    Returns:

      widget

  add_row(widget: DataSetShowWidget) → None

    Add widget to row

    Parameters:

      widget – widget to add

  refresh_widgets() → None

    Refresh the status of all widgets

  update_dataitems() → None

    Refresh the content of all data items

  update_widgets(except_this_one: QWidget | AbstractDataSetWidget | None = None) → None

    Refresh the content of all widgets

    Parameters:

      except_this_one – widget to skip

  widget_value_changed() → None

    Method called when any widget’s value has changed

  get_terminal_widgets() → list[AbstractDataSetWidget]

    Get all terminal widgets (i.e. not GroupWidget or TabGroupWidget).

    Returns:

      List of terminal widgets

class guidata.dataset.qtwidgets.DataSetShowLayout(parent: QWidget | None, instance: AnyDataSet, layout: QGridLayout, items: list[DataItem] | None = None, first_line: int = 0, change_callback: Callable | None = None, group_widget: GroupWidget | None = None)

  Bases: `DataSetEditLayout`

  Read-only layout

  Parameters:

    - parent – parent widget

    - instance – DataSet instance to edit

    - layout – grid layout

    - items – list of data items

    - first_line – first line of grid layout

    - change_callback – function called when any widget’s value has changed

## Group boxes

class guidata.dataset.qtwidgets.DataSetShowGroupBox(label: QLabel | str, klass: type[AnyDataSet], wordwrap: bool = False, **kwargs)

  Bases: `Generic`[`AnyDataSet`], `QGroupBox`

  Group box widget showing a read-only DataSet

  Parameters:

    - label – group box label (string)

    - klass – guidata.DataSet class

    - wordwrap – if True, comment text is wordwrapped

    - kwargs – keyword arguments passed to DataSet constructor

  get_edit_layout() → DataSetEditLayout[AnyDataSet]

    Return edit layout

    Returns:

      edit layout

  get() → None

    Update group box contents from data item values

class guidata.dataset.qtwidgets.DataSetEditGroupBox(label: QLabel | str, klass: type[AnyDataSet], button_text: str | None = None, button_icon: QIcon | str | None = None, show_button: bool = True, wordwrap: bool = False, **kwargs)

  Bases: `DataSetShowGroupBox`[`AnyDataSet`]

  Group box widget including a DataSet

  Parameters:

    - label – group box label (string)

    - klass – guidata.DataSet class

    - button_text – text of apply button (default: “Apply”)

    - button_icon – icon of apply button (default: “apply.png”)

    - show_button – if True, show apply button (default: True)

    - wordwrap – if True, comment text is wordwrapped

    - kwargs – keyword arguments passed to DataSet constructor

  When the “Apply” button is clicked, the `SIG_APPLY_BUTTON_CLICKED` signal is emitted.

  SIG_APPLY_BUTTON_CLICKED

    Signal emitted when Apply button is clicked

  get_edit_layout() → DataSetEditLayout[AnyDataSet]

    Return edit layout

    Returns:

      edit layout

  change_callback() → None

    Method called when any widget’s value has changed

  set(check: bool = True) → None

    Update data item values from layout contents

    Parameters:

      check – if True, check input of all widgets

  set_apply_button_state(state: bool) → None

    Set apply button enable/disable state

    Parameters:

      state – if True, enable apply button

  child_title(item: DataItemVariable) → str

    Return data item title combined with QApplication title

    Parameters:

      item – data item

    Returns:

      title