ソースを参照

stable, basic code
heading toward object oriented

Pat Beirne 9 年 前
コミット
0fb3ab084b
1 ファイル変更84 行追加0 行削除
  1. 84 0
      dirnotes

+ 84 - 0
dirnotes

@@ -0,0 +1,84 @@
+#!/usr/bin/python
+""" a simple gui or command line app
+to view and create/edit file comments
+
+comments are stored in xattr user.xdg.comment
+
+depends on python-pyxattr
+"""
+
+COMMENT_KEY = "user.xdg.comment"
+
+import sys,os,argparse
+from PyQt4.QtGui import *
+from PyQt4 import QtGui, QtCore
+import xattr
+
+def parse():
+	parser = argparse.ArgumentParser(description='dirnotes application')
+	parser.add_argument('filename',metavar='filename',type=str,
+		nargs="*",help='filename or directory',default=".")
+	parser.add_argument('-n','--nogui',action="store_const",const="1",
+		help='use text base interface')
+	parser.add_argument('-v','--version',action='version',version='%(prog)s 0.1')
+	return parser.parse_args()
+
+def debug(x):
+	print("debugging " + x.text() + " r:" + str(x.row()) + " c:" + str(x.column()))
+
+class DirNotes(QMainWindow):
+	def __init__(self, parent=None):
+		super(DirNotes,self).__init__(parent)
+		pass
+	def closeEvent(self,e):
+		print("closing")
+		
+if __name__=="__main__":
+	p = parse()
+
+	a = QApplication([])
+
+	# allow multiple entries on the line at this point
+	d = os.listdir(p.filename[0])
+	d.sort()
+
+	lb = QTableWidget()
+	lb.setRowCount(len(d))
+	lb.setColumnCount(2)
+	lb.horizontalHeader().setResizeMode( 1, QHeaderView.Stretch );
+	# resize the comments column
+	# and resize the parent window to match the directory size
+	for i in range(len(d)):
+		item = QTableWidgetItem(d[i])
+		item.setFlags(QtCore.Qt.ItemIsEnabled)
+		lb.setItem(i,0,item)
+		#lb.itemAt(i,0).setFlags(Qt.ItemIsEnabled) #NoItemFlags)
+		comment = ""
+		try:
+			comment = xattr.getxattr(d[i],COMMENT_KEY)
+		except:
+			continue
+		lb.setItem(i,1,QTableWidgetItem(comment))
+	lb.setHorizontalHeaderItem(0,QTableWidgetItem("file"))
+	lb.setHorizontalHeaderItem(1,QTableWidgetItem("comment"))
+	lb.resizeColumnsToContents()
+
+	win = QWidget()
+	layout = QVBoxLayout()
+	win.setLayout(layout)
+	e = QLabel(win)
+	e.setText("View and edit file comments stored in extended attributes user.xdg.comment")
+	layout.addWidget(e)
+	layout.addWidget(lb)
+	
+	lb.itemChanged.connect(debug)
+
+	QShortcut(QKeySequence("Ctrl+Q"), win, win.close)	
+	win.setWindowTitle("test")
+	win.setMinimumSize(600,400)
+	win.show()
+	
+	a.exec_()
+	
+	#xattr.setxattr(filename,COMMENT_KEY,commentText)
+