|  | @@ -46,10 +46,10 @@ import sys,os,argparse,stat
 | 
	
		
			
				|  |  |  #~ from dirWidget import DirWidget
 | 
	
		
			
				|  |  |  from PyQt5.QtGui import *
 | 
	
		
			
				|  |  |  from PyQt5.QtWidgets import *
 | 
	
		
			
				|  |  | -from PyQt5.QtCore import Qt
 | 
	
		
			
				|  |  | +from PyQt5.QtCore import Qt, pyqtSignal
 | 
	
		
			
				|  |  |  import sqlite3, time
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -VERSION = "0.2"
 | 
	
		
			
				|  |  | +VERSION = "0.3"
 | 
	
		
			
				|  |  |  COMMENT_KEY = "user.xdg.comment"
 | 
	
		
			
				|  |  |  DATABASE_NAME = "~/.dirnotes.db"
 | 
	
		
			
				|  |  |  # convert the ~/ form to a fully qualified path
 | 
	
	
		
			
				|  | @@ -218,6 +218,53 @@ class HelpWidget(QDialog):
 | 
	
		
			
				|  |  |  		self.pb.pressed.connect(self.close)
 | 
	
		
			
				|  |  |  		self.show()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +''' 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 = 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
 | 
	
		
			
				|  |  | +		
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  # sortable TableWidgetItem, based on idea by Aledsandar
 | 
	
		
			
				|  |  |  # http://stackoverflow.com/questions/12673598/python-numerical-sorting-in-qtablewidget
 | 
	
		
			
				|  |  |  # NOTE: the QTableWidgetItem has setData() and data() which may allow data bonding
 |