Browse Source

new layout, no dir chooser any more
filename sorting fixed

Pat Beirne 9 years ago
parent
commit
a763776820
1 changed files with 56 additions and 56 deletions
  1. 56 56
      dirnotes

+ 56 - 56
dirnotes

@@ -17,7 +17,7 @@ where possible, comments are duplicated in
 """
 
 import sys,os,argparse,stat
-from dirWidget import DirWidget
+#~ from dirWidget import DirWidget
 from PyQt4.QtGui import *
 from PyQt4 import QtGui, QtCore
 import xattr, sqlite3, time
@@ -163,16 +163,6 @@ class FileObj():
 	def getSize(self):
 		return self.size
 
-# 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
-class SortableTableWidgetItem(QTableWidgetItem):
-	def __init__(self, text, sortValue):
-		QTableWidgetItem.__init__(self, text, QTableWidgetItem.UserType)
-		self.sortValue = sortValue
-	def __lt__(self, other):
-		return self.sortValue < other.sortValue
-
 class HelpWidget(QDialog):
 	def __init__(self, parent):
 		super(QDialog, self).__init__(parent)
@@ -198,6 +188,17 @@ The small box at the top left lets you navigate the directory listings.
 		self.pb.pressed.connect(self.close)
 		self.show()
 
+# 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
+class SortableTableWidgetItem(QTableWidgetItem):
+	def __init__(self, text, sortValue):
+		QTableWidgetItem.__init__(self, text, QTableWidgetItem.UserType)
+		self.sortValue = sortValue
+	def __lt__(self, other):
+		return self.sortValue < other.sortValue
+		
+		
 class DirNotes(QMainWindow):
 	''' the main window of the app
 		has 3 list boxes: dir_left, dir_right (may be invisible) and files
@@ -206,6 +207,7 @@ class DirNotes(QMainWindow):
 	def __init__(self, argFilename, db, parent=None):
 		super(DirNotes,self).__init__(parent)
 		self.db = db
+		self.refilling = False
 
 		win = QWidget()
 		self.setCentralWidget(win)
@@ -223,7 +225,13 @@ class DirNotes(QMainWindow):
 		# allow multiple entries on the line at this point
 		#d = os.listdir(p.filename[0])
 		#d.sort()
-		self.curPath, filename = os.path.split(argFilename)
+		longPathName = os.path.abspath(argFilename)
+		print("longpathname is {}".format(longPathName))
+		if os.path.isdir(longPathName):
+			self.curPath = longPathName
+			filename = ''
+		else:
+			self.curPath, filename = os.path.split(longPathName)
 		print("working on <"+self.curPath+"> and <"+filename+">")
 		
 		lb.setHorizontalHeaderItem(0,QTableWidgetItem("File"))
@@ -235,37 +243,27 @@ class DirNotes(QMainWindow):
 		self.refill()
 		lb.resizeColumnsToContents()
 		
+		layout = QVBoxLayout()
+
 		e = QLabel("View and edit file comments stored in extended attributes user.xdg.comment",win)
+		layout.addWidget(e)
 
+		bup = QPushButton("up",win)
+		bup.setIcon(QIcon.fromTheme('go-up')) # or go-previous
+		bup.setFixedWidth(100)
 		b1 = QPushButton("restore from database",win)
-		self.dirLeft = dirLeft = DirWidget(self.curPath,win)
-		dirLeft.setMaximumHeight(140)
-		dirLeft.setMaximumWidth(200)
-		dirRight = DirWidget(self.curPath,win)
-		dirRight.setMaximumHeight(140)
-		dirRight.setMaximumWidth(200)
-		dirRight.setEnabled(False)
-		dirLeft.selected.connect(self.newDir)
-		
-		rDate = QRadioButton("Sort by date",win)
-		rSize = QRadioButton("Sort by size",win)
-		
-		layout = QVBoxLayout()
+
 		upperLayout = QHBoxLayout()
-		innerLayout = QVBoxLayout()
-		layout.addWidget(e)
-		upperLayout.addWidget(dirLeft)
-		innerLayout.addWidget(rDate)
-		innerLayout.addWidget(rSize)
-		innerLayout.addWidget(b1)
-		upperLayout.addLayout(innerLayout)
-		upperLayout.addWidget(dirRight)
+		upperLayout.addWidget(bup)
+		upperLayout.addWidget(b1)
 		layout.addLayout(upperLayout)
 		layout.addWidget(lb)
 		win.setLayout(layout)
 		
 		lb.itemChanged.connect(self.change)
+		lb.cellDoubleClicked.connect(self.double)
 		b1.pressed.connect(self.restore_from_database)
+		bup.pressed.connect(self.upOneLevel)
 
 		mb = self.menuBar()
 		mf = mb.addMenu('&File')
@@ -300,9 +298,21 @@ class DirNotes(QMainWindow):
 		self.lb.sortItems(3,QtCore.Qt.DescendingOrder)
 	def newDir(self):
 		print("change dir to "+self.dirLeft.currentPath())
-		
+	def double(self,row,col):
+		print("double click {} {}".format(row, col))
+		fo = self.lb.item(row,col).data(32).toPyObject()
+		if col==0 and fo.getSize() == FileObj.FILE_IS_DIR:
+			print("double click on {}".format(fo.getName()))
+			self.curPath = fo.getName()
+			self.refill()
+	def upOneLevel(self):
+		self.curPath = os.path.abspath(self.curPath + "/..")
+		self.refill()
 			
 	def refill(self):
+		self.refilling = True
+		self.lb.sortingEnabled = False
+		self.lb.clearContents()
 		small_font = QFont("",8)
 		dirIcon = QIcon.fromTheme('folder')
 		fileIcon = QIcon.fromTheme('text-x-generic')
@@ -318,12 +328,16 @@ class DirNotes(QMainWindow):
 		#~ self.files = {}
 		self.files = []
 		# this is a list of all the file
+		#~ print("insert {} items into cleared table {}".format(len(d),current))
 		for i in range(len(d)):
 			this_file = FileObj(current+'/'+d[i])
-			print("insert order check: " + d[i] + " " + str(i))
+			#~ print("insert order check: {} {} {} {}".format(d[i],i,this_file.getName(),this_file.getDate()))
 			#~ self.files.update({this_file.getName(),this_file})
 			self.files = self.files + [this_file]
-			item = QTableWidgetItem(d[i])
+			if this_file.getSize() == FileObj.FILE_IS_DIR:
+				item = SortableTableWidgetItem(d[i],' '+d[i])	# directories sort first
+			else:
+				item = SortableTableWidgetItem(d[i],d[i])
 			item.setFlags(QtCore.Qt.ItemIsEnabled)
 			item.setData(32,this_file)	# keep a hidden copy of the file object
 			self.lb.setItem(i,0,item)
@@ -348,9 +362,13 @@ class DirNotes(QMainWindow):
 			sa.setTextAlignment(QtCore.Qt.AlignRight)
 			sa.setFlags(QtCore.Qt.ItemIsEnabled)
 			self.lb.setItem(i,2,sa)
+		self.refilling = False
+		self.lb.sortingEnabled = True
 		self.lb.resizeColumnToContents(1)
 			
 	def change(self,x):
+		if self.refilling:
+			return
 		print("debugging " + x.text() + " r:" + str(x.row()) + " c:" + str(x.column()))
 		print("      selected file: "+self.lb.item(x.row(),0).data(32).toPyObject().getName())
 		the_file = self.lb.item(x.row(),0).data(32).toPyObject()
@@ -381,7 +399,7 @@ class DirNotes(QMainWindow):
 		
 if __name__=="__main__":
 	p = parse()
-	if p.dirname[-1]=='/':
+	if len(p.dirname)>1 and p.dirname[-1]=='/':
 		p.dirname = p.dirname[:-1]
 	if os.path.isdir(p.dirname):
 		p.dirname = p.dirname + '/'
@@ -420,29 +438,10 @@ user.xdg.language=[RFC3066/ISO639]
 user.xdg.publisher
 '''
 
-''' to allow column-sorting, you use the sortByColumn and set the Horiz-header to clickable
-'''
-
 ''' TODO: add cut-copy-paste for comments '''
 
 ''' TODO: also need a way to display-&-restore comments from the database '''
 
-''' QFileDialog
-	-make my own?
-	-existing one has
-		-history
-		-back button
-		-up button
-		-but we don't need
-			-directory date
-			-icon option
-			-url browser (unless we go network file system)
-			-new folder button
-			-file type chooser
-			-text entry box
-			-choose & cancel buttons
-	
-	'''
 	
 ''' commandline xattr
 getfattr -h (don't follow symlink) -d (dump all properties)
@@ -450,3 +449,4 @@ getfattr -h (don't follow symlink) -d (dump all properties)
 ''' qt set color
                newitem.setData(Qt.BackgroundRole,QBrush(QColor("yellow")))
 '''
+''' if the args line contains a file, jump to it '''