소스 검색

moving back to QT
the tkinter widget is not editable....so we'd have to create an overlay Entry box
added 'restore from database' because the xattrs are so fragile

Pat Beirne 9 년 전
부모
커밋
46885fc681
2개의 변경된 파일57개의 추가작업 그리고 47개의 파일을 삭제
  1. 6 3
      dirnotes
  2. 51 44
      dirnotes2

+ 6 - 3
dirnotes

@@ -52,7 +52,7 @@ class DataBase:
 		
 	def getData(self, fileName):
 		c = self.db.cursor()
-		c.execute("select * from dirnotes where name=? order by comment_date desc",(os.path.abspath(fileName),))
+		c.execute("select * from dirnotes where name=? and comment<>'' order by comment_date desc",(os.path.abspath(fileName),))
 		return c.fetchone()
 	def setData(self, fileName, _date, _size, comment):
 		c = self.db.cursor()
@@ -200,9 +200,12 @@ class DirNotes(QMainWindow):
 		print("restore from database")
 		fileName = str(self.lb.item(self.lb.currentRow(),0).text())
 		fo_row = self.db.getData(fileName)
-		if len(fo_row)>1:
+		if fo_row and len(fo_row)>1:
 			comment = fo_row[3]
-			print(fileName,fo_row[0],comment)
+			print(fileName,fo_row[0],comment) 
+			the_file = dn.files[self.lb.currentRow()]
+			the_file.setComment(comment)
+			self.lb.setItem(self.lb.currentRow(),1,QTableWidgetItem(comment))
 		
 if __name__=="__main__":
 	p = parse()

+ 51 - 44
dirnotes2

@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
 """ a simple gui or command line app
 to view and create/edit file comments
 
@@ -15,7 +15,8 @@ these comments stick to the symlink
 
 import sys,os,argparse
 from dirWidget2 import DirWidget
-from tkinter import *
+from Tkinter import *
+from ttk import *
 import xattr, sqlite3, time
 
 VERSION = "0.2"
@@ -94,6 +95,11 @@ class FileObj():
 			pass
 	def getName(self):
 		return self.fileName
+	def getShortName(self):
+		if self.fileName[-1]=='/':	#do show dirs, they can have comments
+			return os.path.basename(self.fileName[:-1])+'/'
+		else:
+			return os.path.basename(self.fileName)
 	def getComment(self):
 		return self.comment
 	def setComment(self,newComment):
@@ -117,19 +123,14 @@ class DirNotes(Frame):
 		has 3 list boxes: dir_left, dir_right (may be invisible) and files
 		
 		'''
-	def __init__(self, filename, db, parent=None):
-		super(DirNotes,self).__init__(parent)
+	def __init__(self, parent, filename, db):
+		Frame.__init__(self,parent)
 		self.db = db
 
-		win = QWidget()
-		self.setCentralWidget(win)
-
-		lb = QTableWidget()
-		self.lb = lb
-		lb.setColumnCount(2)
-		lb.horizontalHeader().setResizeMode( 1, QHeaderView.Stretch );
-		lb.verticalHeader().setDefaultSectionSize(20);	# thinner rows
-		lb.verticalHeader().setVisible(False)
+		self.lb = lb = Treeview(self)
+		lb['columns'] = ('comment')
+		lb.heading('#0',text='Name')
+		lb.heading('comment',text='Comment')
 		
 		# resize the comments column
 		# and resize the parent window to match the directory size
@@ -143,49 +144,50 @@ class DirNotes(Frame):
 		files.sort()
 		
 		d = dirs + files
-		lb.setRowCount(len(d))
 
 		self.files = []
 		for i in range(len(d)):
 			this_file = FileObj(current+'/'+d[i])
 			self.files = self.files + [this_file]
-			item = QTableWidgetItem(this_file.getName())
-			item.setFlags(QtCore.Qt.ItemIsEnabled)
-			lb.setItem(i,0,item)
+			lb.insert('','end',iid=str(i),text=this_file.getShortName(),)
 			#lb.itemAt(i,0).setFlags(Qt.ItemIsEnabled) #NoItemFlags)
 			comment = this_file.getComment()
-			lb.setItem(i,1,QTableWidgetItem(comment))
-		lb.setHorizontalHeaderItem(0,QTableWidgetItem("file"))
-		lb.setHorizontalHeaderItem(1,QTableWidgetItem("comment"))
-		lb.resizeColumnsToContents()
+			lb.set(item=str(i),column='comment',value=comment)
 
-		e = QLabel("View and edit file comments stored in extended attributes user.xdg.comment",win)
+		
+		e2 = Label(self,text="View and edit file comments stored in extended attributes user.xdg.comment")
+		e1 = Label(self,text="Active Directory:")
 
-		b1 = QPushButton("restore from database",win)
-		dirLeft = DirWidget(current,win)
-		dirLeft.setMaximumHeight(140)
-		dirLeft.setMaximumWidth(200)
-		dirRight = DirWidget(current,win)
-		dirRight.setMaximumHeight(140)
-		dirRight.setMaximumWidth(200)
-		dirRight.setEnabled(False)
+		b1 = Button(self,text="restore from database")
+		dirLeft = DirWidget(self,current)
+		#dirLeft.setMaximumHeight(140)
+		#dirLeft.setMaximumWidth(200)
+		dirRight = DirWidget(self,current)
+		#~ dirRight.setMaximumHeight(140)
+		#~ dirRight.setMaximumWidth(200)
+		#~ dirRight.setEnabled(False)
+		
 		
-		layout = QVBoxLayout()
-		upperLayout = QHBoxLayout()
-		layout.addWidget(e)
-		upperLayout.addWidget(dirLeft)
-		upperLayout.addWidget(b1)
-		upperLayout.addWidget(dirRight)
-		layout.addLayout(upperLayout)
-		layout.addWidget(lb)
-		win.setLayout(layout)
+		#~ layout = QVBoxLayout()
+		#~ upperLayout = QHBoxLayout()
+		#~ layout.addWidget(e)
+		#~ upperLayout.addWidget(dirLeft)
+		#~ upperLayout.addWidget(b1)
+		#~ upperLayout.addWidget(dirRight)
+		#~ layout.addLayout(upperLayout)
+		#~ layout.addWidget(lb)
+		#~ win.setLayout(layout)
 		
-		lb.itemChanged.connect(self.change)
-		b1.pressed.connect(self.restore_from_database)
+		#~ lb.itemChanged.connect(self.change)
+		#~ b1.pressed.connect(self.restore_from_database)
 
-		QShortcut(QKeySequence("Ctrl+Q"), self, self.close)	
-		self.setWindowTitle("test")
-		self.setMinimumSize(600,400)
+		#~ QShortcut(QKeySequence("Ctrl+Q"), self, self.close)	
+		#~ self.setWindowTitle("test")
+		#~ self.setMinimumSize(600,400)
+		e1.pack(anchor=W,padx=20)
+		dirLeft.pack(anchor=W,padx=20,pady=5)
+		e2.pack()
+		lb.pack()
 	def closeEvent(self,e):
 		print("closing")
 		
@@ -212,6 +214,7 @@ if __name__=="__main__":
 	db = DataBase()
 
 	tk_basis = Tk()
+	tk_basis.title("DirNotes "+p.dirname)
 	dn = DirNotes(tk_basis,p.dirname,db)
 	dn.pack()
 	
@@ -263,4 +266,8 @@ user.xdg.publisher
 			-choose & cancel buttons
 	
 	'''
+	
+'''
+http://stackoverflow.com/questions/18562123/how-to-make-ttk-treeviews-rows-editable
+'''