From 34d2683405694fda37763d23873b2309fa2bc157 Mon Sep 17 00:00:00 2001 From: Pat Beirne Date: Fri, 11 Dec 2015 12:34:12 -0500 Subject: [PATCH] re insert the upper widget --- dirWidget.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 dirWidget.py diff --git a/dirWidget.py b/dirWidget.py new file mode 100755 index 0000000..4f811a3 --- /dev/null +++ b/dirWidget.py @@ -0,0 +1,60 @@ +#!/usr/bin/python +''' a widget that shows only a dir listing +''' + +import sys,os,argparse +from PyQt4.QtGui import * +from PyQt4 import QtGui, QtCore + +class DirWidget(QListWidget): + ''' a simple widget that shows a list of directories, staring + at the directory passed into the constructor + + a mouse click or 'enter' key will send a 'selected' signal to + anyone who connects to this. + + the .. parent directory is shown for all dirs except / + + the most interesting parts of the interface are: + constructor - send in the directory to view + method - currentPath() returns text of current path + signal - selected calls a slot with a single arg: new path + ''' + + selected = QtCore.pyqtSignal(str) + def __init__(self, directory='.', parent=None): + super(DirWidget,self).__init__(parent) + self.directory = directory + self.refill() + self.itemActivated.connect(self.selectionByLWI) + # it would be nice to pick up single-mouse-click for selection as well + # but that seems to be a system-preferences global + def selectionByLWI(self, li): + self.directory = os.path.abspath(self.directory + '/' + str(li.text())) + self.refill() + self.selected.emit(self.directory) + def refill(self): + current,dirs,files = os.walk(self.directory,followlinks=True).next() + dirs.sort() + if '/' not in dirs: + dirs = ['..'] + dirs + self.clear() + for d in dirs: + li = QListWidgetItem(d,self) + def currentPath(self): + return self.directory + +if __name__=="__main__": + def alert(some_text): + os.system('notify-send -t 1500 "file: '+str(some_text) + '"') + + a = QApplication([]) + + qmw = QMainWindow() + dw = DirWidget(parent=qmw) + dw.selected.connect(alert) + + qmw.setCentralWidget(dw) + qmw.show() + + a.exec_()