Thanks detlev for your suggestion.. Could you please give me any example code snippet?. Bcoz. i'm totally new to model/view programming and pyqt.<br><br><div class="gmail_quote">On Sun, Jan 17, 2010 at 5:03 PM, detlev <span dir="ltr"><<a href="mailto:detlev@die-offenbachs.de">detlev@die-offenbachs.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
how about using a QSortFilterProxy model to filter the excluded ones?<br>
<br>
Detlev<br>
<div><div></div><div class="h5"><br>
On Samstag, 16. Januar 2010, Jebagnana Das wrote:<br>
> Hello all,<br>
> Greetings.. After a spending a long time for googling i found the<br>
> way to list the contents of a particular directory. Thanks to QDirModel.<br>
><br>
> My aim here is to allow the user to exclude specific directories<br>
> within the chosen directory.. After adding a particular directory to the<br>
> exclusion list(on the right side)the selected directory and it's<br>
> descendents should be removed(or hidden)from the tree view so that the<br>
> user is not allowed to select the same folder again..<br>
><br>
> Given here the minimal example needed for my app.. In this example<br>
> when the user presses add to exclude list push button the folder is added<br>
> to the exclude folders listwidget..<br>
><br>
> from PyQt4 import QtCore, QtGui<br>
><br>
> class Ui_Dialog(QtGui.QDialog):<br>
><br>
> def __init__(self,parent=None):<br>
> QtGui.QDialog.__init__(self,parent)<br>
> self.resize(600, 500)<br>
><br>
> self.model = QtGui.QDirModel()<br>
> self.tree = QtGui.QTreeView(self)<br>
> self.tree.setModel(self.model)<br>
> self.model.setFilter(QtCore.QDir.Dirs|QtCore.QDir.NoDotAndDotDot)<br>
> self.tree.setSortingEnabled(True)<br>
><br>
> self.tree.setRootIndex(self.model.index("/home/jebagnanadasa/Python-3.1.1")<br>
> )<br>
><br>
> self.tree.hideColumn(1)<br>
> self.tree.setWindowTitle("Dir View")<br>
> self.tree.resize(400, 480)<br>
> self.tree.setColumnWidth(0,150)<br>
> self.tree.show()<br>
><br>
> self.pushButton = QtGui.QPushButton(self)<br>
> self.pushButton.setGeometry(QtCore.QRect(420, 30, 151, 28))<br>
> self.listWidget = QtGui.QListWidget(self)<br>
> self.listWidget.setGeometry(QtCore.QRect(410, 80, 171, 231))<br>
><br>
> QtCore.QObject.connect(self.tree,<br>
> QtCore.SIGNAL("clicked(QModelIndex)"), self.test)<br>
><br>
> QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL('clicked()'),self.addT<br>
</div></div>> oList) QtCore.QMetaObject.connectSlotsByName(self)<br>
<div><div></div><div class="h5">><br>
> self.setWindowTitle(QtGui.QApplication.translate("Dialog",<br>
> "Dialog", None, QtGui.QApplication.UnicodeUTF8))<br>
> self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Add<br>
> to Exclude List", None, QtGui.QApplication.UnicodeUTF8))<br>
><br>
> def test(self,index):<br>
><br>
> if self.model.data(index.parent())=="jebagnanadasa":<br>
> self.selectedDirectoryPath=self.model.data(index)<br>
> print(self.selectedDirectoryPath)<br>
> else:<br>
> dirHierarchy=[]<br>
> dirHierarchy.insert(0,self.model.data(index))<br>
> while (self.model.data(index.parent())!="jebagnanadasa"):<br>
> index=index.parent()<br>
> dirHierarchy.insert(0,self.model.data(index))<br>
> self.selectedDirectoryPath="/".join(dirHierarchy)<br>
> print(self.selectedDirectoryPath)<br>
><br>
> #self.model.removeRow(0,index)<br>
><br>
> def addToList(self):<br>
> self.listWidget.addItem(self.selectedDirectoryPath)<br>
><br>
><br>
> if __name__ == "__main__":<br>
> import sys<br>
> app = QtGui.QApplication(sys.argv)<br>
> ui = Ui_Dialog()<br>
> ui.show()<br>
> sys.exit(app.exec_())<br>
><br>
> See the screenshot also..<br>
><br>
> [image:<br>
> ?ui=2&view=att&th=12637fd44b798078&attid=0.1&disp=attd&realattid=ii_12637fd<br>
> 44b798078&zw]<br>
><br>
> Is there a way that i can make the excluded directories to be ignored when<br>
> displaying the contents of the directory on consecutive startup(since it<br>
> was already on the exclusion list)?<br>
><br>
> Any help would be much appreciated.. Thanks..<br>
><br>
> P.S: remove() and rmdir() is not recommended since it deletes the<br>
> directories entirely from the file System!<br>
><br>
<br>
<br>
</div></div><font color="#888888">--<br>
Detlev Offenbach<br>
<a href="mailto:detlev@die-offenbachs.de">detlev@die-offenbachs.de</a><br>
</font></blockquote></div><br>