I can't seem to find how to make NiGui to start in a preset directory for SelectDirectoryDialog
For OpenFileDialog this works, but for SelectDirectoryDialog, it always starts at desktop level (Windows 10). There are no compile errors and it's compiled with nim c -r test.nim
Is there something wrong the code ? I got it from the NiGui examples, edited slightly (threw out save dialog)
I'm fairly new to Nim
# This example shows how to use the Open File and Save File As dialogs.
import nigui
app.init()
var window = newWindow()
var mainContainer = newLayoutContainer(Layout_Vertical)
window.add(mainContainer)
var buttons = newLayoutContainer(Layout_Horizontal)
mainContainer.add(buttons)
var textArea = newTextArea()
mainContainer.add(textArea)
var button1 = newButton("Open ...")
buttons.add(button1)
button1.onClick = proc(event: ClickEvent) =
var dialog = newOpenFileDialog()
dialog.title = "Test Open"
dialog.multiple = true
# dialog.directory = ""
dialog.directory = "D:\\Software"
dialog.run()
textArea.addLine($dialog.files.len & " files selected")
if dialog.files.len > 0:
for file in dialog.files:
textArea.addLine(file)
var button2 = newButton("Select Directory ...")
buttons.add(button2)
button2.onClick = proc(event: ClickEvent) =
var dialog = SelectDirectoryDialog()
dialog.title = "Test Select Directory"
dialog.startdirectory = "C:\\Users"
# see if it is set properly
echo "startdirectory: ", dialog.startdirectory
dialog.run()
if dialog.selectedDirectory == "":
textArea.addLine("No directory selected")
else:
textArea.addLine(dialog.selectedDirectory)
window.show()
app.run()