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
This commit is contained in:
2015-12-14 08:30:30 -05:00
parent d7a8120045
commit 46885fc681
2 changed files with 59 additions and 49 deletions
+6 -3
View File
@@ -52,7 +52,7 @@ class DataBase:
def getData(self, fileName): def getData(self, fileName):
c = self.db.cursor() 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() return c.fetchone()
def setData(self, fileName, _date, _size, comment): def setData(self, fileName, _date, _size, comment):
c = self.db.cursor() c = self.db.cursor()
@@ -200,9 +200,12 @@ class DirNotes(QMainWindow):
print("restore from database") print("restore from database")
fileName = str(self.lb.item(self.lb.currentRow(),0).text()) fileName = str(self.lb.item(self.lb.currentRow(),0).text())
fo_row = self.db.getData(fileName) fo_row = self.db.getData(fileName)
if len(fo_row)>1: if fo_row and len(fo_row)>1:
comment = fo_row[3] 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__": if __name__=="__main__":
p = parse() p = parse()
+53 -46
View File
@@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/python
""" a simple gui or command line app """ a simple gui or command line app
to view and create/edit file comments to view and create/edit file comments
@@ -15,7 +15,8 @@ these comments stick to the symlink
import sys,os,argparse import sys,os,argparse
from dirWidget2 import DirWidget from dirWidget2 import DirWidget
from tkinter import * from Tkinter import *
from ttk import *
import xattr, sqlite3, time import xattr, sqlite3, time
VERSION = "0.2" VERSION = "0.2"
@@ -94,6 +95,11 @@ class FileObj():
pass pass
def getName(self): def getName(self):
return self.fileName 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): def getComment(self):
return self.comment return self.comment
def setComment(self,newComment): def setComment(self,newComment):
@@ -117,19 +123,14 @@ class DirNotes(Frame):
has 3 list boxes: dir_left, dir_right (may be invisible) and files has 3 list boxes: dir_left, dir_right (may be invisible) and files
''' '''
def __init__(self, filename, db, parent=None): def __init__(self, parent, filename, db):
super(DirNotes,self).__init__(parent) Frame.__init__(self,parent)
self.db = db self.db = db
win = QWidget() self.lb = lb = Treeview(self)
self.setCentralWidget(win) lb['columns'] = ('comment')
lb.heading('#0',text='Name')
lb = QTableWidget() lb.heading('comment',text='Comment')
self.lb = lb
lb.setColumnCount(2)
lb.horizontalHeader().setResizeMode( 1, QHeaderView.Stretch );
lb.verticalHeader().setDefaultSectionSize(20); # thinner rows
lb.verticalHeader().setVisible(False)
# resize the comments column # resize the comments column
# and resize the parent window to match the directory size # and resize the parent window to match the directory size
@@ -143,49 +144,50 @@ class DirNotes(Frame):
files.sort() files.sort()
d = dirs + files d = dirs + files
lb.setRowCount(len(d))
self.files = [] self.files = []
for i in range(len(d)): for i in range(len(d)):
this_file = FileObj(current+'/'+d[i]) this_file = FileObj(current+'/'+d[i])
self.files = self.files + [this_file] self.files = self.files + [this_file]
item = QTableWidgetItem(this_file.getName()) lb.insert('','end',iid=str(i),text=this_file.getShortName(),)
item.setFlags(QtCore.Qt.ItemIsEnabled)
lb.setItem(i,0,item)
#lb.itemAt(i,0).setFlags(Qt.ItemIsEnabled) #NoItemFlags) #lb.itemAt(i,0).setFlags(Qt.ItemIsEnabled) #NoItemFlags)
comment = this_file.getComment() comment = this_file.getComment()
lb.setItem(i,1,QTableWidgetItem(comment)) lb.set(item=str(i),column='comment',value=comment)
lb.setHorizontalHeaderItem(0,QTableWidgetItem("file"))
lb.setHorizontalHeaderItem(1,QTableWidgetItem("comment"))
lb.resizeColumnsToContents()
e = QLabel("View and edit file comments stored in extended attributes user.xdg.comment",win)
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)
layout = QVBoxLayout() e2 = Label(self,text="View and edit file comments stored in extended attributes user.xdg.comment")
upperLayout = QHBoxLayout() e1 = Label(self,text="Active Directory:")
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)
QShortcut(QKeySequence("Ctrl+Q"), self, self.close) b1 = Button(self,text="restore from database")
self.setWindowTitle("test") dirLeft = DirWidget(self,current)
self.setMinimumSize(600,400) #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)
#~ 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)
e1.pack(anchor=W,padx=20)
dirLeft.pack(anchor=W,padx=20,pady=5)
e2.pack()
lb.pack()
def closeEvent(self,e): def closeEvent(self,e):
print("closing") print("closing")
@@ -212,6 +214,7 @@ if __name__=="__main__":
db = DataBase() db = DataBase()
tk_basis = Tk() tk_basis = Tk()
tk_basis.title("DirNotes "+p.dirname)
dn = DirNotes(tk_basis,p.dirname,db) dn = DirNotes(tk_basis,p.dirname,db)
dn.pack() dn.pack()
@@ -263,4 +266,8 @@ user.xdg.publisher
-choose & cancel buttons -choose & cancel buttons
''' '''
'''
http://stackoverflow.com/questions/18562123/how-to-make-ttk-treeviews-rows-editable
'''