PedroAlvesV / AbsTK

The Abstract Toolkit – a widget toolkit for GUI and text-mode applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to replace the contents of a list?

hishamhm opened this issue · comments

I think we've discussed this at some point, but we may have ended up missing it.

I need to replace the list of options in a selector from a callback. Here's an example of what I'd like to be able to do:

https://gist.github.com/hishamhm/b948ef9e6e8df30d3e3ab8aacff4a80d

Here, if you have two monitors plugged in, I'd like to change the list of resolutions when the other monitor is plugged.

(To test this with a single monitor, use this fake output file:

https://gist.github.com/hishamhm/7db71de28f24b1cac9d1b8569c74576d

and replace io.popen("xrandr", "r") with io.open("xrandr.fake", "r") in the xrandr.lua script (note popen vs. open!) )

This feature is needed in the GoboLinux installer in the screen where you pick the time zone. You type in a substring with part of the time zone name, and the list above it shrinks to include only the elements that match.

Side note: the documentation of Selector argument for set_value is incorrect. It says it takes a boolean, but it takes a number (as its own example shows)

https://pedroalvesv.github.io/AbsTK/modules/abstk.html#Screen:set_value

Yeah, we talked about it, but I don't know what is the best way of solving it. I think it could simply take another table and replace Selector's content. I'll do it this way, unless you have a better solution.

Done: 828f492
I think it works for your purpose, now.

When I finished it, I was thinking about the other feature and, the way I wrote it, it can be implemented to work both ways. It's just a matter of parameters. I mean, if the second parameter is 'nil', set_value() can still work with the index and select the item. It seems intuitive to me.

Cool, I'll give it a try.

After using it a bit and reading the docs, I am afraid that the functions ended up becoming "too magical" (ie, each function does a lot of different stuff). That is convenient when you know what they do, but it could make it harder to figure out stuff when you're starting out. It's a trade-off.

Anyway, I think the best thing now is to exercise the API a little, that is, write stuff with it and see how it feels. That's why I started with the XRandr config short example.

Yeah. Actually, the way it is right now doesn't do such thing (use just the index). I will implement it tonight.
About the tricky way AbsTK is designed, I think it's worth it to make some features clearer to the user.

Btw: I fixed the set_value() section in the API reference.

UPDATE: Just implemented it: 0b1da02