Skip to content

TranslatableHeaderMixin

Sub classes

Name Children Inherits
CategoryModel
cutepandas.pandasmodels.categorymodel
One row per category of a column, with its code and number of rows, read-only.
SchemaModel
cutepandas.pandasmodels.schemamodel
One row per column of a frame (any backend), read-only.
PandasIndexListModel
cutepandas.pandasmodels.pandascolumnlistmodel
Index levels of a pandas frame: name, index type, monotonic (editable).
    TopValuesModel
    cutepandas.pandaswidgets.columnprofilewidget
    Most frequent values of a column: value, count and share of all rows.

      Base classes

      Name Children Inherits
      TranslateMixin
      cutepandas.utils.i18n
      Keeps an optional `translate` callable; `_tr(text)` applies it.

      ⋔ Inheritance diagram

      graph TD
        1559661765["i18n.TranslatableHeaderMixin"]
        3771062457["i18n.TranslateMixin"]
        2751680898["builtins.object"]
        3771062457 --> 1559661765
        2751680898 --> 3771062457

      🛈 DocStrings

      Bases: TranslateMixin

      Item model mixin: horizontal header labels from HEADER, translated.

      Put it before the Qt model base class. retranslate() emits headerDataChanged and dataChanged (cells and tooltips may contain labels).

      Source code in src/cutepandas/utils/i18n.py
      class TranslatableHeaderMixin(TranslateMixin):
          """Item model mixin: horizontal header labels from `HEADER`, translated.
      
          Put it before the Qt model base class. `retranslate()` emits
          `headerDataChanged` and `dataChanged` (cells and tooltips may contain labels).
          """
      
          HEADER: ClassVar[list[str]] = []
      
          def headerData(
              self,
              offset: int,
              orientation: constants.Orientation,
              role: constants.ItemDataRole = constants.DISPLAY_ROLE,
          ):
              if (
                  orientation == constants.HORIZONTAL
                  and role == constants.DISPLAY_ROLE
                  and 0 <= offset < len(self.HEADER)
              ):
                  return self._tr(self.HEADER[offset])
              return None
      
          def retranslate(self):
              model: Any = self
              columns = len(self.HEADER)
              if not columns:
                  return
              model.headerDataChanged.emit(constants.HORIZONTAL, 0, columns - 1)
              if rows := model.rowCount():
                  model.dataChanged.emit(model.index(0, 0), model.index(rows - 1, columns - 1))
      

      :fa-brands-github: Show source on GitHub