# dupeGuru 4.3.1 documentation

## hscommon.gui.column

`Columns`(table[, prefaccess, savename]) | Cross-toolkit GUI-enabled column set for tables or outlines.
`Column`(name[, display, visible, optional]) | Holds column attributes such as its name, width, visibility, etc.
`ColumnsView`() | Expected interface for `Columns`'s view.
`PrefAccessInterface`() | Expected interface for `Columns`'s prefaccess.

class hscommon.gui.column.Columns(table: GUITable, prefaccess=None, savename: str | None = None)

  Cross-toolkit GUI-enabled column set for tables or outlines.

  Manages a column set’s order, visibility and width. We also manage the persistence of these attributes so that we can restore them on the next run.

  Subclasses `GUIObject`. Expected view: `ColumnsView`.

  Parameters:

    - table – The table the columns belong to. It’s from there that we retrieve our column configuration and it must have a `COLUMNS` attribute which is a list of `Column`. We also call `save_edits()` on it from time to time. Technically, this argument can also be a tree, but there’s probably some sorting in the code to do to support this option cleanly.

    - prefaccess – An object giving access to user preferences for the currently running app. We use this to make column attributes persistent. Must follow `PrefAccessInterface`.

    - savename (str) – The name under which column preferences will be saved. This name is in fact a prefix. Preferences are saved under more than one name, but they will all have that same prefix.

  _view_updated() → None

    (Virtual) Called after `view` has been set.

    Doing nothing by default, this method is called after `view` has been set (it isn’t called when it’s unset, however). Use this for initialization code that requires a view (which is often the whole of the initialization code).

  column_by_index(index: int)

    Return the `Column` having the `logical_index` `index`.

  column_by_name(name: str)

    Return the `Column` having the `name` `name`.

  column_display(colname: str) → str

    Returns display name for column named `colname`, or `''` if there’s none.

  column_is_visible(colname: str) → bool

    Returns visibility for column named `colname`, or `True` if there’s none.

  column_width(colname: str) → int

    Returns width for column named `colname`, or `0` if there’s none.

  columns_count() → int

    Returns the number of columns in our set.

  columns_to_right(colname: str) → List[str]

    Returns the list of all columns to the right of `colname`.

    “right” meaning “having a higher `Column.ordered_index`” in our left-to-right civilization.

  menu_items() → List[Tuple[str, bool]]

    Returns a list of items convenient for quick visibility menu generation.

    Returns a list of `(display_name, is_marked)` items for each optional column in the current view (`is_marked` means that it’s visible).

    You can use this to generate a menu to let the user toggle the visibility of an optional column. That is why we only show optional column, because the visibility of mandatory columns can’t be toggled.

  move_column(colname: str, index: int) → None

    Moves column `colname` to `index`.

    The column will be placed just in front of the column currently having that index, or to the end of the list if there’s none.

  reset_to_defaults() → None

    Reset all columns’ width and visibility to their default values.

  resize_column(colname: str, newwidth: int) → None

    Set column `colname`’s width to `newwidth`.

  restore_columns() → None

    Restore’s column persistent attributes from the last `save_columns()`.

  save_columns() → None

    Save column attributes in persistent storage for restoration in `restore_columns()`.

  set_column_order(colnames) → None

    Change the columns order so it matches the order in `colnames`.

    Parameters:

      colnames – A list of column names in the desired order.

  set_column_visible(colname: str, visible: bool) → None

    Set the visibility of column `colname`.

  set_default_width(colname: str, width: int) → None

    Set the default width or column `colname`.

  toggle_menu_item(index: int) → bool

    Toggles the visibility of an optional column.

    You know, that optional column menu you’ve generated in `menu_items()`? Well, `index` is the index of them menu item in that menu that the user has clicked on to toggle it.

    Returns whether the column in question ends up being visible or not.

  property colnames: List[str]

    List of column names in visible order.

  property ordered_columns: List[Column]

    List of `Column` in visible order.

class hscommon.gui.column.Column(name: str, display: str = '', visible: bool = True, optional: bool = False)

  Holds column attributes such as its name, width, visibility, etc.

  These attributes are then used to correctly configure the column on the “view” side.

  default_visible

    Whether the column is visible by default. It will be used if column restoration doesn’t contain any “remembered” widths.

  default_width

    Default width of the column. This value usually depends on the platform and is set on columns initialisation. It will be used if column restoration doesn’t contain any “remembered” widths.

  display

    Display name (title) of the column.

  logical_index

    Immutable index of the column. Doesn’t change even when columns are re-ordered. Used in `Columns.column_by_index()`.

  name

    “programmatical” (not for display) name. Used as a reference in a couple of place, such as `Columns.column_by_name()`.

  optional

    Whether the column can have `visible` set to false.

  ordered_index

    Index of the column in the ordered set of columns.

  visible

    Whether the column is visible.

  width

    Width of the column.

class hscommon.gui.column.ColumnsView

  Expected interface for `Columns`’s view.

  Not actually used in the code. For documentation purposes only.

  Our view, the columns controller of a table or outline, is expected to properly respond to callbacks.

  restore_columns() → None

    Update all columns according to the model.

    When this is called, our view has to update the columns title, order and visibility of all columns.

  set_column_visible(colname: str, visible: bool) → None

    Update visibility of column `colname`.

    Called when the user toggles the visibility of a column, we must update the column `colname`’s visibility status to `visible`.

class hscommon.gui.column.PrefAccessInterface

  Expected interface for `Columns`’s prefaccess.

  Not actually used in the code. For documentation purposes only.

  get_default(key: str, fallback_value: Any | None) → Any

    Retrieve the value for `key` in the currently running app’s preference store.

    If the key doesn’t exist, return `fallback_value`.

  set_default(key: str, value: Any) → None

    Set the value `value` for `key` in the currently running app’s preference store.