[PyKDE] PYSIGNAL, QLIstItem

Rune Hansen rune.hansen at viventus.no
Wed Oct 30 14:13:01 GMT 2002


Hi, I'm trying to bind a PYSIGNAL to a QListItem

--

self.TreeView=QListItem(...

class ...

  def __init__(..)
    self.connect(self.TreeView,PYSIGNAL("sigIdData"),self.printMe)
  
  def printMe(self,e):
    print e

  def populateTree(self,xml_obj,tmp=""):
    if tmp == "":
      tmp=self.TreeView
      for i in range(len(xml_obj)):
        try:
      	  for x in range(len(xml_obj[i].children.item)):
	    _tmp=QListViewItem(tmp,
	   xml_obj[i].children.item[x].name.PCDATA.encode('iso-8859-1'))
             self.TreeView.emit(PYSIGNAL("sigIdData"),
                               (xml_obj[i].children.item[x].id.PCDATA,))
             if int(xml_obj[i].children.item[x].expand.PCDATA) == 1:
               _tmp.setPixmap(0,self.image0)
               _tmp.setOpen(1)
                        
             self.populateTree(xml_obj[i].children.item[x],_tmp)

        except AttributeError:
          pass
--

When I run this code, every attribute bound by PYSIGNAL in
populateTree() gets printed at once. The behavior I want is to get the
attribute when clicking somewhere in the Tree. I guess I will have to
bind another signal to TreeView as well, but I have so far been unable
to accomplish this. This particular problem can be "solved" by storing
the QListItemView instances in a dictionary instead of using a PYSIGNAL,
but can it be solved by using signals as well? 


regards

/rune
 
"Engineering does not require science. Science helps a lot but people
built perfectly good brick walls long before they knew why cement
works."
--Allan Cox




More information about the PyQt mailing list