Hi all i wish make little gui with pyqt4 that show the output of "dir c:\windows\" line by line I'm looking for QlistView but i don't understand how do it. Can anyone help me?
+1
A:
import os
for root, dirs, files in os.walk(r'C:\windows'):
//add your QlistView add codes here
S.Mark
2010-04-16 14:59:22
Hi Markthanks for your fast replay.For list dir i use: for filename in os.listdir("c:\\windows"): print filenameMy problem is port the output of command inside the gui (I'm looking for QlistView but i don't know how do it)
ester23
2010-04-16 15:06:55
@ester23, if gui is under your control, you can directly use os.listdir results, instead of printing to console and getting results back.
S.Mark
2010-04-16 15:32:22
Yes is under my control. Is only a test for learn pyqt. I wish print line by line because i want do some action on file (like rename, make a copy, etc). But i'm not know the way for do it so i read about QlistView but i don't know how let work this. Thanks for your help
ester23
2010-04-16 15:56:55
+1
A:
Try QListWidget instead of QListView. QListWidget extends QListView and adds some very helpful methods like addItems
.
I'm going to assume you know how to create the GUI part of the application using Designer.
If you have a QListWidget object qlistwidget
, the code would be:
values = os.listdir("c:\\windows")
qlist = QtCore.QStringList(map(QtCore.QString, values))
qlistwidget.addItems(qlist)
tgray
2010-04-16 21:20:51
Thanks this work! I do it also with QlistView (i made an array and then print the value on Qlistview). If i want to do some action like select one file and copy it in the same dir with another extension can you suggest how do it? Thanks for your replay
ester23
2010-04-17 02:47:01
Check out `shutil.copy(src, dst)`, http://docs.python.org/library/shutil.html#shutil.copy
tgray
2010-04-19 13:30:08