Improve launcher file dialog initial paths (#740)

- In the launcher, if an existing value is set for a file value (e.g.
Model), use that file's directory the initial directory when the
file dialog is opened with 'Browse'.
- In the launcher always set the intial directory for 'Load' to
cwd.
This commit is contained in:
Stefan Kapusniak 2024-03-11 14:05:46 +00:00 committed by GitHub
parent 95c8090967
commit 4dd1c2b81a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1573,7 +1573,9 @@ def show_new_gui():
def makefileentry(parent, text, searchtext, var, row=0, width=200, filetypes=[], onchoosefile=None, singlerow=False, tooltiptxt=""): def makefileentry(parent, text, searchtext, var, row=0, width=200, filetypes=[], onchoosefile=None, singlerow=False, tooltiptxt=""):
makelabel(parent, text, row,0,tooltiptxt) makelabel(parent, text, row,0,tooltiptxt)
def getfilename(var, text): def getfilename(var, text):
fnam = askopenfilename(title=text,filetypes=filetypes) initialDir = os.path.dirname(var.get())
initialDir = initialDir if os.path.isdir(initialDir) else os.getcwd()
fnam = askopenfilename(title=text,filetypes=filetypes, initialdir=initialDir)
if fnam: if fnam:
var.set(fnam) var.set(fnam)
if onchoosefile: if onchoosefile:
@ -2230,7 +2232,7 @@ def show_new_gui():
file_type = [("KoboldCpp Settings", "*.kcpps")] file_type = [("KoboldCpp Settings", "*.kcpps")]
global runmode_untouched global runmode_untouched
runmode_untouched = False runmode_untouched = False
filename = askopenfilename(filetypes=file_type, defaultextension=file_type) filename = askopenfilename(filetypes=file_type, defaultextension=file_type, initialdir=os.getcwd())
if not filename or filename=="": if not filename or filename=="":
return return
with open(filename, 'r') as f: with open(filename, 'r') as f: