[PyKDE] Little Python helpers for PyQt

Gordon Tyler gordon at doxxx.net
Fri Jan 23 03:01:01 GMT 2004


Torsten Marek wrote:
> def ListBoxIterator(listbox, selectedOnly = False):
>     i = listbox.firstItem()
>     while i:
>         if selectedOnly and not i.isSelected():
>             continue
>         yield i
>         i = i.next()
>     return

If I'm not mistaken, passing True to selectedOnly will make that 
function loop forever after the first unselected item. How about this:

def ListBoxIterator(listbox, selectedOnly = False):
     i = listbox.firstItem()
     while i:
         if (selectedOnly and i.isSelected()) or not selectedOnly:
             yield i
         i = i.next()
     return

Ciao,
Gordon




More information about the PyQt mailing list