Current
The current table option for plugins is completely undocumented, and from my experience trying to implement one, very unintuitive. Here is a quick breakdown of how they work currently:
[TABLE]
label = "Test" # Same as every other item
type = "table"
toolTip = "This is a table" # Same as every other item
tab = "Basic" # Same as every other item
# Toggle ability to select entire rows. No support to select columns.
selectable = false
# The number of columns will grow to support however many headers are here
headers = ["header1", "header2", "header3"]
# Pass in defaults column-wise, also resizes table to fit all values
columns = [
["row0_col0", "row1_col0"],
["row0_col1", "row1_col1"],
["row0_col2", "row1_col2"],
]
# Alternatively, pass in defaults row-wise.
# If this is provided with columns, any overlap will be overwritten by rows
# This also will resize the table if necessary
rows = [
["row0_col0", "row0_col1", "row0_col2"],
["row1_col0", "row1_col1", "row1_col2"],
]
# This overrides both rows and columns, and will resize the table if necessary
default = "row0_col0\trow0_col1\trow0_col2\nrow1_col0\trow1_col1\trow1_col2"
# Delimiter will change the format of "default"
delimiter = "\t"
# Sortable does something, but I could not figure out its function
sortable = False
The plugin then receives (in this case) a string that represents tab-separated values in the same form as default:
{
"TABLE": "row0_col0\trow0_col1\trow0_col2\nrow1_col0\trow1_col1\trow1_col2"
}
Proposed Changes
Some discussion with @matterhorn103 led to this proposed revision.
A more intuitive way to create a table would be to pass in an array of rows/columns, which could each contain information about what that entry in the table would look like, things like the header/label, the datatype, the defaults, and whether or not that row/column is editable. Additionally, passing both rows and columns would not be allowed, and passing default would be outright removed. Additionally, within a row/column, the datatype would be homogeneous.
This is what that would look like in TOML:
[TABLE]
label = "Test"
type = "table"
toolTip = "This is a table"
tab = "Basic"
[[TABLE.columns]]
label = "col1"
type = "integer"
minimum = 0
maximum = 9
defaults = [2, 5]
[[TABLE.columns]]
label = "col2"
type = "string"
defaults = ["row0_col1", "row1_col1"]
[[TABLE.columns]]
label = "col3"
type = "boolean"
editable = false
defaults = [true, false]
This allows for a number of important things. One, you can now control the widget inside the box (QTableWidgetItem for strings, QSpinBox and QDoubleSpinBox for integers and floats, respectively, and QCheckBox for bools), just like you would in other widgets. Being able to set a row/column as editable also would serve to enable a sort of row/column label if you have already labeled the other. This is useful for situations where the plugin sets a value based on the molecule passed, and the others need to be filled in by a user.
The table produced from this TOML is shown here:
In addition to updating the table specification, the return value from the table would also be updated to match the input more closely. This means that instead of return a string, Avogadro would return a JSON array with the rows/columns inside it, like this:
{
"TABLE": [
{"col1": [2, 5]},
{"col2": ["row1_col2", "row2_col2"]},
{"col3": [false, false]}
]
}
This would make it much more intuitive to work with since the column labels you put in are exactly what you get back out, and the types match what you expect.
While this would break existing plugins using tables, I don’t actually think there are many plugins that use tables, since their API was quite complicated and completely undocumented, as mentioned at the beginning of this post.
I’ve already done the implementation of this in a branch, just to see if it is possible. If there is positive feedback, I’ll open a PR.

