-
-
Notifications
You must be signed in to change notification settings - Fork 792
Description
What is the problem or limitation you are having?
Displaying a checkbox is a simple way of indicating a true/false value for a row in a Table or Tree. Occasionally a third, indeterminate, value may be called for (eg. in a Tree when some children are checked and some are not).
Currently only the MacOS backend supports displaying checkboxes in a table via using a Switch widget as the cell value. Other backends can fake the effect by using an icon which looks like a checkbox or other icon-style indicator. However all the other backends have support for checkboxes in columns in various ways.
Initially just being able to display a checkbox would be good, but having the option of making them user-editable would potentially be even better, and because they are simple true/false in most cases, it may provide a simpler case to explore adding editability to tables and trees.
Describe the solution you'd like
With #4041 being merged, this should be somewhat easier to implement support. Initially the behaviour we want should be something like:
- if the row value obtained via the accessor is a
bool, then rather than displaying"True"or"False", the table or tree should display a checkbox which is checked if True and unchecked if False. - (possibly) we introduce a third value
Indeterminatewhich shows an indeterminate checkbox - (possibly, but unlikely) if the value is a
Switchwidget, display a checkbox whose value matches the value of the switch (this will be awkward to keep synchronised if editing is allowed). - (possibly) if a cell holds a tuple
(icon, text, ..., checked, ...)then in addition to the icon and text, it should display a checkbox whose state ischecked. Exactly which position thecheckedvalue should take is unclear, since there are other values we may want to put in there; for example having the third item be adetailortooltiptext would be more compatible withDetailedList, and we may want a place for style information to be provided as well (or not). - otherwise no checkbox is displayed.
This is technically not backwards compatible, but not in a way that breaks things terribly.
To support checking/unchecking behaviour, the data source needs to provide row objects such that setattr(row, accessor, value) works and performs an appropriate change notification from the source, and possibly the table should have a global editable setting which can be set true or false. When the user changes the state of the checkbox, the table should set the new value. Code which cares about changes to the checkboxes can listen to the data source for changes and react appropriately.
For backwards compatibility, a table being editable should be opt-in.
Describe alternatives you've considered
Instead of doing this, it might be that complete generic Widget support as in the current MacOS backend is better and is what each backend should strive for.
Additional context
This can be implemented by the ColumnT protocol growing a checked method, and having the AccessorColumn implementation handle the logic above. If column objects are exposed as a public API, different implementations could provide the data for the checked column in different ways.
Editability of checkmarks could similarly be via the protocol growing checkable(row), set_value(row, value) and set_checked(row, checked) methods (or other equivalent names): checkable returns a True/False if the user should be able to change the check value in this row and column, set_value handles setting the value into the row object, and set_checked handles any conversion that's needed to get the value formatted to match the existing value (eg. if given an (icon, text, ..., checked, ...) value, set the value back to a tuple of the same format but with the checked value changed.)
There should be a widget-wide editable/not-editable flag which is false by default.
Editability also requires that whatever the row objects are, they should emit a change notification for the row when the value is set. In the current implementations that means that the AccessorColumn should be simply doing setattr(row, accessor, value) and the row objects need to be able to have attributes set on them, and should make the source emit change notifications (which the default Row and Node objects do, but custom ones would need to implement).
Other editability could then grow from this base (eg. editable text re-using set_value).