#!/usr/bin/python

import os

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class FileTree(QWidget):
	sig_show_file = pyqtSignal(str)
	
	def __init__(self, parent=None):
		QWidget.__init__(self)
		self.le = QLineEdit()

		self.qt = QTreeWidget(self)
		self.qt.setColumnCount(2)
		self.qt.setHeaderLabels(['File', 'Path'])
		self.qt.setFont(QFont("San Serif", 8))
		self.qt.setIndentation(-2)
		self.qt.setAllColumnsShowFocus(True)

		vlay = QVBoxLayout()
		vlay.addWidget(self.le)
		vlay.addWidget(self.qt)
		self.setLayout(vlay)

		self.le.textChanged.connect(self.le_textChanged)
		self.le.returnPressed.connect(self.le_returnPressed)
		self.qt.itemActivated.connect(self.qt_itemActivated)

	def le_textChanged(self, text):
		if (text == ''):
			return
		self.qt.keyboardSearch('')
		self.qt.keyboardSearch(text)

	def le_returnPressed(self):
		self.le.clear()
		items = self.qt.selectedItems()
		if len(items) == 0:
			return
		self.qt.itemActivated.emit(items[0], 0)

	def qt_itemActivated(self, item):
		filename = str(item.data(1, Qt.DisplayRole).toString())
		self.sig_show_file.emit(filename)

	def keyPressEvent(self, ev):
		if ev.key() in [Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp or Qt.Key_PageDown]:
			self.qt.keyPressEvent(ev)
			return

	def clear(self):
		self.le.clear()
		self.qt.clear()

	def add_files(self, flist):
		self.qt.clear()
		for f in flist:
			item = QTreeWidgetItem([os.path.basename(f), f])
			self.qt.addTopLevelItem(item)
			#if (self.qt.topLevelItemCount() > 0):
				#self.qt.resizeColumnToContents(0)
				#self.qt.resizeColumnToContents(1)
		self.qt.sortByColumn(0, Qt.AscendingOrder)

@@ -93,16 +93,19 @@
 leTree(Q
+Tab
 Widget):
@@ -195,24 +195,49 @@
 nit__(self)%0A
+%09%09self.listw = QWidget()%0A
 %09%09self.le = 
@@ -543,16 +543,22 @@
 %0A%09%09self.
+listw.
 setLayou
@@ -564,16 +564,50 @@
 ut(vlay)
+%0A%09%09self.addTab(self.listw, %22List%22)
 %0A%0A%09%09self
@@ -743,18 +743,382 @@
 ct(self.
-qt
+foldtv_itemActivated)%0A%0A%09%09self.foldm = QFileSystemModel()%0A%09%09self.foldm.setRootPath(QDir.rootPath())%0A%09%09self.foldtv = QTreeView()%0A%09%09self.foldtv.setModel(self.foldm)%0A%09%09header = self.foldtv.header()%0A%09%09for col in range(header.count()):%0A%09%09%09if col %3E 0:%0A%09%09%09%09self.foldtv.setColumnHidden(col, True)%0A%09%09self.addTab(self.foldtv, %22Tree%22)%0A%09%09self.foldtv.activated.connect(self.foldtv
 _itemAct
@@ -1504,42 +1504,302 @@
 )%0A%09%09
-self.sig_show_file.emit(filename)%0A
+if self.replaceroot:%0A%09%09%09filename = filename.replace(%22...%22, self.rootpath)%0A%09%09self.sig_show_file.emit(filename)%0A%0A%09def foldtv_itemActivated(self):%0A%09%09list = self.foldtv.selectionModel().selectedIndexes()%0A%09%09for item in list:%0A%09%09%09self.sig_show_file.emit(self.foldm.fileInfo(item).absoluteFilePath())%0A%09
 %0A%09de
@@ -2050,23 +2050,228 @@
 )%0A%09%09
-for f in flist:
+self.replaceroot = False%0A%09%09self.rootpath = QString(os.path.commonprefix(flist))%0A%09%09if self.rootpath.size() %3E 8:%0A%09%09%09self.replaceroot = True%0A%09%09for f in flist:%0A%09%09%09if self.replaceroot:%0A%09%09%09%09f =  f.replace(self.rootpath, %22...%22)
 %0A%09%09%09
@@ -2517,8 +2517,72 @@
 gOrder)%0A
+%09%09self.foldtv.setRootIndex(self.foldm.index(self.rootpath))%0A%09%09%09%0A

Support for folder view and root path shortening in file view