lots of cleanup in dirnotes-gui; eliminate cursor; only open the database once; use the QFileDialog as a dir-picker; implement fileCopy; add a dir-picker to dirnotes-tui; add a desktop icon and .destop file
This commit is contained in:
+60
-31
@@ -186,7 +186,7 @@ class Pane:
|
||||
self.setStatus("The xattr and database comments differ where shown in green")
|
||||
# time.sleep(2)
|
||||
|
||||
self.file_pad.refresh(self.first_visible,0,2,1,self.h-3,self.w-2)
|
||||
self.file_pad.refresh(self.first_visible,0, 2,1, self.h-3,self.w-2)
|
||||
|
||||
def refill(self):
|
||||
self.win.bkgdset(' ',curses.color_pair(CP_BODY))
|
||||
@@ -498,61 +498,90 @@ class FileObj():
|
||||
|
||||
########## dest folder picker ###############
|
||||
# returns None if the user hits <esc>
|
||||
# the dir_pad contents are indexed from 0,0, matching self.fs
|
||||
class showFolderPicker:
|
||||
def __init__(self,starting_dir,title):
|
||||
self.selected = None
|
||||
self.title = title
|
||||
self.starting_dir = self.cwd = os.path.abspath(starting_dir)
|
||||
|
||||
# draw the perimeter...it doesn't change
|
||||
self.W = curses.newwin(20,60,5,5)
|
||||
self.W.bkgd(' ',COLOR_HELP)
|
||||
self.h, self.w = self.W.getmaxyx()
|
||||
self.W.keypad(True)
|
||||
self.title = title
|
||||
self.starting_dir = starting_dir
|
||||
self.cwd = starting_dir
|
||||
self.fill()
|
||||
self.selected = None
|
||||
#self.W.clear()
|
||||
self.W.border()
|
||||
self.W.addnstr(0,1,self.title,self.w-2)
|
||||
self.W.addstr(self.h-1,1,"<Enter> to select or change dir, <esc> to exit")
|
||||
self.W.refresh()
|
||||
|
||||
indialog = True
|
||||
self.fill()
|
||||
|
||||
inDialog = True
|
||||
selected = ''
|
||||
while indialog:
|
||||
while inDialog:
|
||||
c = self.W.getch()
|
||||
y,x = self.W.getyx()
|
||||
y,x = self.dir_pad.getyx()
|
||||
if c == curses.KEY_UP:
|
||||
if y>1: self.W.move(y-1,1)
|
||||
if y==0:
|
||||
continue
|
||||
y -= 1
|
||||
self.dir_pad.move(y,0)
|
||||
if y < self.first_visible:
|
||||
self.first_visible = y
|
||||
self.refresh()
|
||||
elif c == curses.KEY_DOWN:
|
||||
if y<len(self.fs)+1: self.W.move(y+1,1)
|
||||
if y == len(self.fs)-1:
|
||||
continue
|
||||
y += 1
|
||||
self.dir_pad.move(y,0)
|
||||
if y-self.first_visible > self.h-3:
|
||||
self.first_visible += 1
|
||||
self.refresh()
|
||||
elif c == CMD_CD:
|
||||
# cd to new dir and refill
|
||||
if y==1 and self.fs[0].startswith('<'): # current dir
|
||||
if y==0 and self.fs[0].startswith('<use'): # current dir
|
||||
self.selected = self.cwd
|
||||
indialog = False
|
||||
inDialog = False
|
||||
else:
|
||||
self.cwd = self.cwd + '/' + self.fs[y-1]
|
||||
self.cwd = os.path.realpath(self.cwd)
|
||||
self.cwd = os.path.abspath(self.cwd + '/' + self.fs[y])
|
||||
#logging.info(f"change dir to {self.cwd}")
|
||||
self.fill()
|
||||
self.fill() # throw away the old self.dir_pad
|
||||
elif c == CMD_ESC:
|
||||
indialog = False
|
||||
inDialog = False
|
||||
del self.W
|
||||
|
||||
def value(self):
|
||||
#logging.info(f"dir picker returns {self.selected}")
|
||||
logging.info(f"dir picker returns {self.selected}")
|
||||
return self.selected
|
||||
|
||||
def refresh(self):
|
||||
y,x = self.W.getbegyx()
|
||||
self.dir_pad.refresh(self.first_visible,0, x+1,y+1, x+self.h-2,y+self.w-2)
|
||||
|
||||
def fill(self):
|
||||
h, w = self.W.getmaxyx()
|
||||
self.W.clear()
|
||||
self.W.border()
|
||||
self.W.addnstr(0,1,self.title,w-2)
|
||||
self.W.addstr(h-1,1,"<Enter> to select or change dir, <esc> to exit")
|
||||
self.fs = os.listdir(self.cwd)
|
||||
self.fs = [a for a in self.fs if os.path.isdir(a)]
|
||||
# change to os.path.walk() and just use the directories
|
||||
# self.fs is the list of candidates, prefixed by "use this" and ".."
|
||||
d, self.fs, _ = next(os.walk(self.cwd))
|
||||
self.fs.sort()
|
||||
if self.cwd != '/':
|
||||
self.fs.insert(0,"..")
|
||||
if self.cwd != self.starting_dir:
|
||||
self.fs.insert(0,f"<use this dir> {os.path.basename(self.cwd)}")
|
||||
for i,f in enumerate(self.fs):
|
||||
self.W.addnstr(i+1,1,f,w-2)
|
||||
self.W.move(1,1)
|
||||
|
||||
# create a pad big enough to hold all the entries
|
||||
self.pad_height = max(self.h-2,len(self.fs))
|
||||
self.dir_pad = curses.newpad(self.pad_height, self.w - 2)
|
||||
self.dir_pad.bkgdset(' ',curses.color_pair(CP_BODY))
|
||||
self.dir_pad.clear()
|
||||
self.first_visible = 0
|
||||
|
||||
# and fill it with strings
|
||||
for i,f in enumerate(self.fs):
|
||||
self.dir_pad.addnstr(i,0,f,self.w-2)
|
||||
self.dir_pad.move(0,0)
|
||||
self.refresh()
|
||||
|
||||
########### comment management code #################
|
||||
|
||||
@@ -867,7 +896,7 @@ def main(w, cwd):
|
||||
# and copy the database record
|
||||
f = FileObj(dest)
|
||||
f.setDbComment(files[mywin.cursor].getDbComment())
|
||||
mywin.refresh()
|
||||
mywin.refresh()
|
||||
|
||||
elif c == CMD_MOVE:
|
||||
if files[mywin.cursor].displayName == "..":
|
||||
@@ -885,9 +914,9 @@ def main(w, cwd):
|
||||
shutil.move(src, dest_dir)
|
||||
# and copy the database record
|
||||
f = FileObj(dest)
|
||||
f.setDbComment(files[mywin.cursor].getDbComment())
|
||||
f.setDbComment(files[mywin.cursor].getDbComment())
|
||||
files = Files(cwd)
|
||||
mywin = Pane(w,cwd,files)
|
||||
mywin = Pane(w,cwd,files) # is this the way to refresh the main pane? TODO
|
||||
|
||||
elif c == curses.KEY_RESIZE:
|
||||
mywin.resize()
|
||||
|
||||
Reference in New Issue
Block a user