List Info

Thread: populating listbox




populating listbox
country flaguser name
Estonia
2008-03-11 09:35:38
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 ;).

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...

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".

So a few concrete questions:
* What is the "default" section of ListBox for?
* How should it be used - does the script have to echo
strings 
one-entry-per-line or should it use addUniqueItem()
function?

-- 
Silver
_______________________________________________
Kommander mailing list
Kommanderkdewebdev.org

http://mail.kdewebdev.org/mailman/listinfo/kommander

Re: populating listbox
country flaguser name
United States
2008-03-11 10:42:34
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
Kommanderkdewebdev.org

http://mail.kdewebdev.org/mailman/listinfo/kommander

Re: populating listbox
country flaguser name
Estonia
2008-03-12 05:42:46
On Tuesday 11 March 2008 17:42, Eric Laffoon wrote:
> 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?

Actually I did look at this, but it was before I upgraded
KDE from 3.5.8 to 
3.5.9. It seems that the Kommander handbook has improved
greatly in 1.3 
It's a great help of that now for starting with Kommander
(as the opposite to 
the previous version)..

> > 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.

Good you found it amusing :P

But yes, I didn't need to use it and with the new manual
I've sorted out how 
the things I wanted are done 

Thank you for the tips anyway.

-- 
Silver
_______________________________________________
Kommander mailing list
Kommanderkdewebdev.org

http://mail.kdewebdev.org/mailman/listinfo/kommander

Re: populating listbox
country flaguser name
United States
2008-03-12 19:02:57
ON WEDNESDAY 12 MARCH 2008 3:42:46 AM SILVER SALONEN WROTE:
> > DID YOU TRY THE HELP MENU IN KOMMANDER EDITOR?
>
> ACTUALLY I DID LOOK AT THIS, BUT IT WAS BEFORE I
UPGRADED KDE FROM 3.5.8 TO
> 3.5.9. IT SEEMS THAT THE KOMMANDER HANDBOOK HAS
IMPROVED GREATLY IN 1.3 
> IT'S A GREAT HELP OF THAT NOW FOR STARTING WITH
KOMMANDER (AS THE OPPOSITE
> TO THE PREVIOUS VERSION)..

THANK YOU. ALL WE HAD TO DO WAS GIVE UP SLEEPING. 
>
> > > 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.
>
> GOOD YOU FOUND IT AMUSING :P
>
> BUT YES, I DIDN'T NEED TO USE IT AND WITH THE NEW
MANUAL I'VE SORTED OUT
> HOW THE THINGS I WANTED ARE DONE 
>
> THANK YOU FOR THE TIPS ANYWAY.

IT'S PRETTY NICE THAT THERE ARE ACTUALLY SEVERAL WAYS TO DO
THINGS. WE MADE 
SURE IF YOU DID THEM THE OLD WAY YEARS AGO THEY STILL WORK
AND YOU CAN ADD ON 
FEATURES FROM THE NEW WAY WITHOUT HAVING TO START OVER.
ENJOY!

-- 
ERIC LAFFOON
PROJECT LEAD - KDEWEBDEV MODULE
_______________________________________________
KOMMANDER MAILING LIST
KOMMANDERKDEWEBDEV.ORG
HTTP://MAIL.KDEWEBDEV.ORG/MAILMAN/LISTINFO/KOMMANDER

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )