flexx icon indicating copy to clipboard operation
flexx copied to clipboard

Tree item in JS

Open Maxyme opened this issue 10 years ago • 4 comments

The TreeWidget should be able to take in dicts are input items rather than only treeitem models. This would allow dynamically populating the TreeWidget from Js.

Maxyme avatar Dec 02 '16 16:12 Maxyme

I think allowing both dicts and treeitem models would be confusing and hard to maintain. For reference the items in a ComboBox are just strings. I think the main question is whether we can implement an effective TreeWidget (i.e. come up with a good API on the widget itself) without its items being models.

Reasons why we would want this are that we can currently only add items from Python, and that very large or dynamic lists may become "heavy".

almarklein avatar Dec 02 '16 16:12 almarklein

If you could initialize an bunch of treewidgetitems in the background (let's say 2000 for this example) then, you could pass objects (dicts) to the Tree Widget from the client side then the items property could check for the following attributes while assigning the item to an already instantiated (in the 2000 above). If it gets more than the max, you could specify a property called something like pre-instanciate.

        def items(self, items=[]):
        def text(self, text=''):
        def title(self, title=''):
        def visible(self, v=True):
        def selected(self, v=False):
        def checked(self, v=None):
        def collapsed(self, v=None):

Maxyme avatar Dec 05 '16 09:12 Maxyme

Do you mean you'd like the dicts have methods? I don't think that will work well, e.g. they won't be models, so you wont be able to connect to them.

If a TreeWidget would have dicts as items, they should be just dicts, I think, and all the API would come on the TreeWidget itself. Let's try to see what that would look like:

tree = TreeWidget(items=[...])
# For booleans it works pretty ok
tree.checked  #-> list of items that are checked
tree.selected  #-> similar
tree.visible  #-> list of items, mmm, not very nice, but ok
tree.text  # -> ???
tree.get_text(100)  # get text of 100th item
tree.set_text(100, 'foo')  # I thought we liked properties?

After thinking this true I think we should stick to models. It is even more effective in a way if a tree changes a lot, since the list of items is just references instead of dicts with multiple attributes.

Back to the original problem. One solution would be to allow creating model objects from JS under specific situations (for specific classes?). This needs a lot of thought though. I am not eager.

Another option could be to think about a new widget (ListWidget?) that is similar to a combobox except its a list; items are just strings and the user can select one or more of them. Than you can get away with a simple API:

list1 = ListWidget(items=[...])
list1.items = [...]
list1.selected  # -> list of indices or list of strings

almarklein avatar Dec 05 '16 10:12 almarklein

TreeItems are now Widgets, which are JsComponents, and thus can be instantiated in JS.

almarklein avatar Feb 06 '18 13:02 almarklein