On Tuesday 11 March 2008 7:35:38 am Silver Salonen wrote:
> Hello!
>
> I've just started messing around with Kommander and I
really can't find any
> information on how to really populate ListBoxes
(actually I don't find any
> information besides the 3 articles and this mailinglist
archive ;).
Did you try the help menu in Kommander Editor?
>
> Anyway, what I want to do is to create a ListBox (named
"SelectConfig")
> that would list items echoed by a script and let user
to choose one of
> these. I did somewhat succeed with a exec-button's
"default" kommander
> text: =====
> SelectConfig.clear
> array_indexedFromString("myArr",
exec("/usr/home/silver/myscript.sh"),
> "n") forEach config in myArr do
> SelectConfig.addUniqueItem(config)
> end
> =====
>
> Pressing the button results numbers (1 2 3 4 ...) being
put into
> ListBox "SelectConfig". The actual list is a
list of words though...
Wow, pardon me, but it is mildly entertaining. You have to
have the latest
release to have the array function you are using, and I'm
sure this is
covered in the docs under widgets and the new parser. Let me
mention a few
things here.
1) populate is pretty much a deprecated functionality. It
tends to confuse
people as you would run a shell script here and you need to
set up a signal
and slot relationship. However you could more easily set up
the dialog
initialization routine to fill any widget with less steps
and less confusion
about why text is handled differently here.
2) the indexed array function creates a zero based indexed
array from a scalar
3) Listboxes do not handle arrays, but insert a scalar with
a default
contiguous zero based index, so a functional array which
disregards any index
that doesn't match. In other words, just give it a list.
4) using foreach with an array gives you the key, which is
useful for hash
values - city = Portland as key=>val
a["city"] = "Portland"
foreach i in a do
debug("i="+i)
debug("a[i]="+a[i])
end
//returns
i=city
a[i]=Portland
5) all of the above is pretty pointless as all Kommander
widgets are designed
to take lines as "anbnc..." and fields as
"1t2t3t..." where n = newline
and t = tab. So you can fill a listbox like so...
ListBox1.insertItems(exec("ls -1"), -1)
since this exec call will produce one item per line.
>
> When I put the same script into ListBox, I'd assume
that the "default" part
> of "Kommander text" is executed, when ListBox
is created. Or the script
> within "population" is executed when the slot
populate() is called via some
> signal. When I connect populate() of the ListBox with
some button, pressing
> the button just clears the ListBox and inserts nothing.
Also nothing
> happens with the script being in "default".
The default section allows for legacy usage. From a button
or script you can
access ListBox1.selection or the current item or whatever.
In the case of a
container like a ListBox the text attribute gives you the
whole list.
Originally we used just a reference to ListBox1 which then
using the old
parser needed to have widgetText in the default to get it's
text. What was
interesting was that you could make a widget modify it's own
output this way.
As interesting as this was it was more fragmented. There is
little point in
using either of these in the widget presently, but they are
there for
primarily legacy support. Actually the legacy stuff is cool
in it's own
right, just not near as powerful.
>
> So a few concrete questions:
> * What is the "default" section of ListBox
for?
See above, legacy script support.
> * How should it be used - does the script have to echo
strings
> one-entry-per-line or should it use addUniqueItem()
function?
Use any of the functions you like. You can add individually,
all at once or
individually with the unique filter. You can also look at
the included demos
(see docs) for how to create a virtual indexed combo or
listbox.
--
Eric Laffoon
Project Lead - kdewebdev module
_______________________________________________
Kommander mailing list
Kommander kdewebdev.org
http://mail.kdewebdev.org/mailman/listinfo/kommander
|