[PyKDE] KURL.List
Jim Bublitz
jbublitz at nwinternet.com
Wed Sep 17 18:45:01 BST 2003
On Tuesday September 16 2003 22:55, Russell Valentine wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> I am having problems understanding how to use KURL.List
> for example in C++ I would do something like this.
> urls= KFileDialog::getOpenURLs(...)
> for( KURL::List::ConstIterator it = urls.begin(); it !=
> urls.end(); it++){ KURL url = (*it);
> openDocumentFile(url);
> }
> How do I do something like this in python and pykde?
> I've tried:
> it=urls.begin()
> while it != urls.end():
> self.view.openDocument(it)
> it = it+1
> and
> for i in range(urls.count()):
> self.view.openDocument(urls[0])
> and
> for url in urls:
> self.view.openDocument(url)
> and
> for i in range(urls.count()):
> self.view.openDocument(*urls.at(i))
> and
> for i in range(urls.count()):
> self.view.openDocument(urls.at(i))
> I think I'm missing some big concept. I can't seem to figure
> it out, I would be grateful for any help.
PyKDE (and sip) don't currently support C++/Qt iterators, so
begin(), end(), at() and count() should throw errors
(Attribute?). Python already has list processing built in, and
KURL.List *should* behave like a Python list (I'd have to check
on how thoroughly this has been tested - probably not
sufficiently), so the following *should* work:
urllist = KURL.List()
urllist.append (KURL ("http://slashdot.org"))
<append more urls>
listBegin = urllist [0] # begin ()
listEnd = urllist [-1] # end ()
listCount = len (urllist) # count ()
...
x = urllist [i] # at (i)
...
for i in range (len (urllist)):
...
sublist = urllist [3:6]
Other stuff ("for url in urllist", list comprehensions) should
also work, I think. In Python 2.2.x and later, you should also
be able to write generators based on KURL.List. The same should
hold for any other QValueList subclass in PyQt or PyKDE.
Let me know if anything is broken (actually, manualtest.py and
autotest.py in the tests/ directory do some testing on
KURL.List, but the "subscripting" was added after the test was
written, and it needs to be updated).
This is a good subject for docs and more unit testing, so I'll
try to put something in about it in future releases.
Jim
More information about the PyQt
mailing list