Display directory pyqt4 and Python

D

Dunwitch

I've looked around for the answer and have decided to ask an expert
for the solution. Whats suppose to happen is a user pushes a button
and displays the directory content in the text edit window on the gui.
Everything works, apart from the fact that it only shows the last file
in the directory, not a full listing. Here is the code for reference.
Any help would be appreciated, I'm missing something simple.
--
Dunwitch

# File : Video Search
import sys, os, win32net

from PyQt4 import QtGui, QtCore
from findVideos import Ui_MainWindow # UI Files from QT Designer

# New class derived from QMainWindow
class TestApp(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

# Connect the signals andslots
QtCore.QObject.connect(self.ui.findFiles,QtCore.SIGNAL("clicked
()"), self.showVideoFiles)

#----------------------------- Code In Question
---------------------------------
def showVideoFiles(self):
enc7 = ('\\\\1.2.3.4\\somefolder')
fileList=os.listdir(enc7)
for x in (fileList):
self.ui.displayVideo.setText(x) # This only shows the last
file in the directory?
#-------------------------------------------------------------------------------------------

if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = TestApp()
window.show()
sys.exit(app.exec_())
 
D

Diez B. Roggisch

Dunwitch said:
I've looked around for the answer and have decided to ask an expert
for the solution. Whats suppose to happen is a user pushes a button
and displays the directory content in the text edit window on the gui.
Everything works, apart from the fact that it only shows the last file
in the directory, not a full listing. Here is the code for reference.
Any help would be appreciated, I'm missing something simple.
--
Dunwitch

# File : Video Search
import sys, os, win32net

from PyQt4 import QtGui, QtCore
from findVideos import Ui_MainWindow # UI Files from QT Designer

# New class derived from QMainWindow
class TestApp(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

# Connect the signals andslots
QtCore.QObject.connect(self.ui.findFiles,QtCore.SIGNAL("clicked
()"), self.showVideoFiles)

#----------------------------- Code In Question
---------------------------------
def showVideoFiles(self):
enc7 = ('\\\\1.2.3.4\\somefolder')
fileList=os.listdir(enc7)
for x in (fileList):
self.ui.displayVideo.setText(x) # This only shows the last
file in the directory?

Of course, if you always only set the *full* text of the displayVideo to
the current list-item, it will end showing the last set item.

self.ui.displayVideo("\n".join(fileList))

should do the trick (of course you can get rid of the for-loop)

Diez
 
D

Dunwitch

Dunwitch schrieb:









Of course, if you always only set the *full* text of the displayVideo to
the current list-item, it will end showing the last set item.

self.ui.displayVideo("\n".join(fileList))

should do the trick (of course you can get rid of the for-loop)

Diez

Thank you! I was having a rough time with that, time to keep digging
deeper in the docs!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top