views:

205

answers:

2

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
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
@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
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
+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
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
Check out `shutil.copy(src, dst)`, http://docs.python.org/library/shutil.html#shutil.copy
tgray