[PyKDE] Possible PyQt bug?? (simple test file attached)
Huaicai Mo
huaicai at nanorex.com
Fri Aug 26 23:19:17 BST 2005
Skipped content of type multipart/alternative-------------- next part --------------
import sys
from qt import *
class FileItem(QListViewItem):
def __init__(self, parent, fio, name=None):
QListViewItem.__init__(self, parent, name)
self.fileInfo = fio
def getFileInfo(self):
return self.fileInfo
class Directory(QListViewItem):
def __init__(self, parent, name=None):
apply(QListViewItem.__init__,(self,parent, name))
if isinstance(parent, QListView):
self.p = None
self.f = '/'
else:
self.p = parent
self.f = name
def setOpen(self, o):
if o and not self.childCount():
s = self.fullName()
thisDir = QDir(s)
if not thisDir.isReadable():
self.readable = 0
return
files = thisDir.entryInfoList()
if files:
for f in files:
fileName = str(f.fileName())
if fileName == '.' or fileName == '..':
continue
elif f.isSymLink():
d = QListViewItem(self, fileName)#, 'Symbolic Link')
elif f.isDir():
d = Directory(self, fileName)
else:
if f.isFile():
s = 'File'
else:
s = 'Special'
passByName = 0 ### Line 47
if passByName:
d = FileItem(self, f.absFilePath(), fileName)
else:
d = FileItem(self, f, fileName)
QListViewItem.setOpen(self, o)
def setup(self):
self.setExpandable(1)
QListViewItem.setup(self)
def fullName(self):
if self.p:
s = self.p.fullName() + self.f
else:
s = self.f
return s
def text(self, column):
if column == 0:
return self.f
class DirView(QListView):
def __init__(self, parent=None, name=None):
QListView.__init__(self, parent, name)
self.connect(self, SIGNAL("selectionChanged(QListViewItem *)"), self.fileChanged)
def fileChanged(self, item):
if isinstance(item, FileItem):
fi = item.getFileInfo()
if isinstance(fi, QFileInfo):
print "Passed by QFileInfo."
print "The selected file is: ", str(fi.absFilePath())
else:
print "The selected file is: ", str(fi)
if __name__ == '__main__':
a = QApplication(sys.argv)
mw = DirView()
a.setMainWidget(mw)
mw.setCaption('PyQt Example - Directory Browser')
mw.addColumn("Name")
mw.resize(400, 400)
mw.setTreeStepSize(20)
root = Directory(mw)
root.setOpen(1)
mw.show()
a.exec_loop()
More information about the PyQt
mailing list