new layout, no dir chooser any more
filename sorting fixed
This commit is contained in:
@@ -17,7 +17,7 @@ where possible, comments are duplicated in
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys,os,argparse,stat
|
import sys,os,argparse,stat
|
||||||
from dirWidget import DirWidget
|
#~ from dirWidget import DirWidget
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
import xattr, sqlite3, time
|
import xattr, sqlite3, time
|
||||||
@@ -163,16 +163,6 @@ class FileObj():
|
|||||||
def getSize(self):
|
def getSize(self):
|
||||||
return self.size
|
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):
|
class HelpWidget(QDialog):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super(QDialog, self).__init__(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.pb.pressed.connect(self.close)
|
||||||
self.show()
|
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):
|
class DirNotes(QMainWindow):
|
||||||
''' the main window of the app
|
''' the main window of the app
|
||||||
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
|
||||||
@@ -206,6 +207,7 @@ class DirNotes(QMainWindow):
|
|||||||
def __init__(self, argFilename, db, parent=None):
|
def __init__(self, argFilename, db, parent=None):
|
||||||
super(DirNotes,self).__init__(parent)
|
super(DirNotes,self).__init__(parent)
|
||||||
self.db = db
|
self.db = db
|
||||||
|
self.refilling = False
|
||||||
|
|
||||||
win = QWidget()
|
win = QWidget()
|
||||||
self.setCentralWidget(win)
|
self.setCentralWidget(win)
|
||||||
@@ -223,7 +225,13 @@ class DirNotes(QMainWindow):
|
|||||||
# allow multiple entries on the line at this point
|
# allow multiple entries on the line at this point
|
||||||
#d = os.listdir(p.filename[0])
|
#d = os.listdir(p.filename[0])
|
||||||
#d.sort()
|
#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+">")
|
print("working on <"+self.curPath+"> and <"+filename+">")
|
||||||
|
|
||||||
lb.setHorizontalHeaderItem(0,QTableWidgetItem("File"))
|
lb.setHorizontalHeaderItem(0,QTableWidgetItem("File"))
|
||||||
@@ -235,37 +243,27 @@ class DirNotes(QMainWindow):
|
|||||||
self.refill()
|
self.refill()
|
||||||
lb.resizeColumnsToContents()
|
lb.resizeColumnsToContents()
|
||||||
|
|
||||||
e = QLabel("View and edit file comments stored in extended attributes user.xdg.comment",win)
|
|
||||||
|
|
||||||
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()
|
layout = QVBoxLayout()
|
||||||
upperLayout = QHBoxLayout()
|
|
||||||
innerLayout = QVBoxLayout()
|
e = QLabel("View and edit file comments stored in extended attributes user.xdg.comment",win)
|
||||||
layout.addWidget(e)
|
layout.addWidget(e)
|
||||||
upperLayout.addWidget(dirLeft)
|
|
||||||
innerLayout.addWidget(rDate)
|
bup = QPushButton("up",win)
|
||||||
innerLayout.addWidget(rSize)
|
bup.setIcon(QIcon.fromTheme('go-up')) # or go-previous
|
||||||
innerLayout.addWidget(b1)
|
bup.setFixedWidth(100)
|
||||||
upperLayout.addLayout(innerLayout)
|
b1 = QPushButton("restore from database",win)
|
||||||
upperLayout.addWidget(dirRight)
|
|
||||||
|
upperLayout = QHBoxLayout()
|
||||||
|
upperLayout.addWidget(bup)
|
||||||
|
upperLayout.addWidget(b1)
|
||||||
layout.addLayout(upperLayout)
|
layout.addLayout(upperLayout)
|
||||||
layout.addWidget(lb)
|
layout.addWidget(lb)
|
||||||
win.setLayout(layout)
|
win.setLayout(layout)
|
||||||
|
|
||||||
lb.itemChanged.connect(self.change)
|
lb.itemChanged.connect(self.change)
|
||||||
|
lb.cellDoubleClicked.connect(self.double)
|
||||||
b1.pressed.connect(self.restore_from_database)
|
b1.pressed.connect(self.restore_from_database)
|
||||||
|
bup.pressed.connect(self.upOneLevel)
|
||||||
|
|
||||||
mb = self.menuBar()
|
mb = self.menuBar()
|
||||||
mf = mb.addMenu('&File')
|
mf = mb.addMenu('&File')
|
||||||
@@ -300,9 +298,21 @@ class DirNotes(QMainWindow):
|
|||||||
self.lb.sortItems(3,QtCore.Qt.DescendingOrder)
|
self.lb.sortItems(3,QtCore.Qt.DescendingOrder)
|
||||||
def newDir(self):
|
def newDir(self):
|
||||||
print("change dir to "+self.dirLeft.currentPath())
|
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):
|
def refill(self):
|
||||||
|
self.refilling = True
|
||||||
|
self.lb.sortingEnabled = False
|
||||||
|
self.lb.clearContents()
|
||||||
small_font = QFont("",8)
|
small_font = QFont("",8)
|
||||||
dirIcon = QIcon.fromTheme('folder')
|
dirIcon = QIcon.fromTheme('folder')
|
||||||
fileIcon = QIcon.fromTheme('text-x-generic')
|
fileIcon = QIcon.fromTheme('text-x-generic')
|
||||||
@@ -318,12 +328,16 @@ class DirNotes(QMainWindow):
|
|||||||
#~ self.files = {}
|
#~ self.files = {}
|
||||||
self.files = []
|
self.files = []
|
||||||
# this is a list of all the file
|
# this is a list of all the file
|
||||||
|
#~ print("insert {} items into cleared table {}".format(len(d),current))
|
||||||
for i in range(len(d)):
|
for i in range(len(d)):
|
||||||
this_file = FileObj(current+'/'+d[i])
|
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.update({this_file.getName(),this_file})
|
||||||
self.files = self.files + [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.setFlags(QtCore.Qt.ItemIsEnabled)
|
||||||
item.setData(32,this_file) # keep a hidden copy of the file object
|
item.setData(32,this_file) # keep a hidden copy of the file object
|
||||||
self.lb.setItem(i,0,item)
|
self.lb.setItem(i,0,item)
|
||||||
@@ -348,9 +362,13 @@ class DirNotes(QMainWindow):
|
|||||||
sa.setTextAlignment(QtCore.Qt.AlignRight)
|
sa.setTextAlignment(QtCore.Qt.AlignRight)
|
||||||
sa.setFlags(QtCore.Qt.ItemIsEnabled)
|
sa.setFlags(QtCore.Qt.ItemIsEnabled)
|
||||||
self.lb.setItem(i,2,sa)
|
self.lb.setItem(i,2,sa)
|
||||||
|
self.refilling = False
|
||||||
|
self.lb.sortingEnabled = True
|
||||||
self.lb.resizeColumnToContents(1)
|
self.lb.resizeColumnToContents(1)
|
||||||
|
|
||||||
def change(self,x):
|
def change(self,x):
|
||||||
|
if self.refilling:
|
||||||
|
return
|
||||||
print("debugging " + x.text() + " r:" + str(x.row()) + " c:" + str(x.column()))
|
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())
|
print(" selected file: "+self.lb.item(x.row(),0).data(32).toPyObject().getName())
|
||||||
the_file = self.lb.item(x.row(),0).data(32).toPyObject()
|
the_file = self.lb.item(x.row(),0).data(32).toPyObject()
|
||||||
@@ -381,7 +399,7 @@ class DirNotes(QMainWindow):
|
|||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
p = parse()
|
p = parse()
|
||||||
if p.dirname[-1]=='/':
|
if len(p.dirname)>1 and p.dirname[-1]=='/':
|
||||||
p.dirname = p.dirname[:-1]
|
p.dirname = p.dirname[:-1]
|
||||||
if os.path.isdir(p.dirname):
|
if os.path.isdir(p.dirname):
|
||||||
p.dirname = p.dirname + '/'
|
p.dirname = p.dirname + '/'
|
||||||
@@ -420,29 +438,10 @@ user.xdg.language=[RFC3066/ISO639]
|
|||||||
user.xdg.publisher
|
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: add cut-copy-paste for comments '''
|
||||||
|
|
||||||
''' TODO: also need a way to display-&-restore comments from the database '''
|
''' 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
|
''' commandline xattr
|
||||||
getfattr -h (don't follow symlink) -d (dump all properties)
|
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
|
''' qt set color
|
||||||
newitem.setData(Qt.BackgroundRole,QBrush(QColor("yellow")))
|
newitem.setData(Qt.BackgroundRole,QBrush(QColor("yellow")))
|
||||||
'''
|
'''
|
||||||
|
''' if the args line contains a file, jump to it '''
|
||||||
|
|||||||
Reference in New Issue
Block a user