[PyKDE] brain-deadness

Greg Fortune lists at gregfortune.com
Mon Jan 6 06:58:01 GMT 2003


On Sunday 05 January 2003 07:43 pm, tech at bishop.dhs.org wrote:
> Working through the examples in Boudewijn's book, I've come across
> something.  In chap. 7, it discussing using signals and slots to create
> a little xml parser, which then displays in a tree list view.  It just
> so happens that my next project is using xml and pyqt, so this
> interested me.  However, (and I must be even more braindead than usual
> to not understand this) how do I associate the "data" with the "tag"?
> For instance, when you have a contruct like this: <tag>this is
> data</tag>, the unknown_starttag signal is fired when it reaches <tag>,
> and the handle_data signal is fired when it gets to "this is data", but
> I'm not getting how you would say that "when unknown_starttag fires on
> tag == "tag", then next handle_data should be directed to foo, which is
> what I want/need.
>
> Example code is attached (direct from the book!), along with example xml
> file (and you might see what my project is ;-).  I don't need working
> code in response, just a general idea of what to do.  Oh, and "get more
> sleep, idiot" would be valid, but non-helpful B-)
>
> Thanks,
>
> D.A.Bishop


I haven't used the ListView much, but I think the following patch will work. 
All you needed to do was add a column for the data and then do "some stuff" 
in the Data function...  If the patch doesn't work for you, I can send the 
altered file.  Note: ignore my variable names, etc, 'cause I just hacked 
until it worked ;o)


--- pyget.old.py        Sun Jan  5 21:43:02 2003
+++ pyget.py    Sun Jan  5 21:48:22 2003
@@ -1,4 +1,7 @@
+#!/usr/bin/env python
+
 import sys
+import string
 import xmllib
 from qt import *

@@ -32,6 +35,7 @@
                self.stack=[]
                self.setRootIsDecorated(TRUE)
                self.addColumn("Element")
+               self.addColumn("Data")

        def startDocument(self, tag, attributes ):
                i=QListViewItem(self)
@@ -46,7 +50,10 @@
                self.stack.append(i)

        def Data(self, data):
-               print "",
+               data = string.strip(data)
+               i = self.stack[-1]
+               if(data != ''):
+                       i.setText(1, data)

        def endElement(self, tag):
                del(self.stack[-1])




Have fun,

Greg




More information about the PyQt mailing list