Эх сурвалжийг харах

modified the date display so that it's shorter
leave the font size alone

Pat Beirne 9 жил өмнө
parent
commit
6b0442be81
1 өөрчлөгдсөн 37 нэмэгдсэн , 10 устгасан
  1. 37 10
      dirnotes

+ 37 - 10
dirnotes

@@ -76,6 +76,26 @@ class DataBase:
 	@staticmethod
 	def DbToEpoch(dbTime):
 		return time.mktime(time.strptime(dbTime,"%Y-%m-%d %H:%M:%S"))
+	@staticmethod
+	def getShortDate(longDate):
+		e = DataBase.DbToEpoch(longDate)
+		sd = time.strptime(longDate,"%Y-%m-%d %H:%M:%S")
+		# check for this year, or today
+		ty = time.mktime((time.localtime()[0],1,1,0,0,0,0,1,-1))
+		today = time.mktime((time.localtime()[0:3]+(0,0,0,0,1,-1)))
+		if e < ty: 
+			return time.strftime("%b %d %Y",sd)
+		elif e < today:
+			return time.strftime("%b %d",sd)
+		else:
+			return time.strftime("%X",sd)
+	#~ test code for this routine
+	#~ for i in range(int(time.time() - 370*24*3600),
+			#~ int(time.time() + 48*3600),
+			#~ 3599):
+		#~ ds = DataBase.epochToDb(i)
+		#~ print("%d\t%s\t%s" % (i,ds,DataBase.getShortDate(ds)))
+				
 
 		
 def parse():
@@ -131,6 +151,16 @@ 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
+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
@@ -228,12 +258,6 @@ class DirNotes(QMainWindow):
 	def newDir(self):
 		print("change dir to "+self.dirLeft.currentPath())
 		
-	class DnTableWidgetItem(QTableWidgetItem):
-		def __init__(self, text, value):
-			QTableWidgetItem.__init__(self, text, QTableWidgetItem.UserType)
-			self.value = value
-		def __lt__(self, other):
-			return self.value < other.value
 			
 	def refill(self):
 		small_font = QFont("",8)
@@ -257,16 +281,17 @@ class DirNotes(QMainWindow):
 			#lb.itemAt(i,0).setFlags(Qt.ItemIsEnabled) #NoItemFlags) 
 			comment = this_file.getComment()
 			self.lb.setItem(i,3,QTableWidgetItem(comment))
-			da = QTableWidgetItem(this_file.getDate())
-			da.setFont(small_font)
+			dt = this_file.getDate()
+			da = SortableTableWidgetItem(DataBase.getShortDate(dt),dt)
+			#da.setFont(small_font)
 			da.setFlags(QtCore.Qt.ItemIsEnabled)
 			self.lb.setItem(i,1,da)
 			si = this_file.getSize()
 			if si>=0:
-				sa = self.DnTableWidgetItem(str(si),si)
+				sa = SortableTableWidgetItem(str(si),si)
 				item.setIcon(fileIcon)
 			else:
-				sa = self.DnTableWidgetItem('',0)
+				sa = SortableTableWidgetItem('',0)
 				item.setIcon(dirIcon)
 			sa.setTextAlignment(QtCore.Qt.AlignRight)
 			sa.setFlags(QtCore.Qt.ItemIsEnabled)
@@ -334,6 +359,8 @@ 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