implement file save chooser

This commit is contained in:
Jonas Leder 2025-09-13 23:42:56 +02:00
commit 892a8d34e8
2 changed files with 14 additions and 6 deletions

17
main.go
View file

@ -260,6 +260,17 @@ func main() {
plotCanvas.ScaleMode = canvas.ImageScalePixels
plotCanvas.Resize(fyne.NewSize(1920, 782))
buttonGenerateReport := widget.NewButton("Generate report", func() {
onChosen := func(f fyne.URIWriteCloser, err error) {
recordtime, _ := time.Parse("2006/01/02 15:04", datetimeInput.Text)
pdf.RenderPDF(f.URI().Path(), titleInput.Text, wavelengthInput.Text, pulsewidthInput.Text, fibertypeInput.Text, locationaInput.Text, locationbInput.Text, projectInput.Text, customerInput.Text, remarksInput.Text, &plotCanvas.Image, iorInput.Text, testerInput.Text, contactInfoInput.Text, fiberNoInput.Text, events, fiberLenInput.Text, recordtime)
}
dialog.ShowFileSave(onChosen, mainWindow)
})
buttonGenerateReport.Disable()
buttonReadFile := widget.NewButton("Open .sor file", func() {
onChosen := func(f fyne.URIReadCloser, err error) {
if err != nil {
@ -306,17 +317,13 @@ func main() {
})
tabs.SelectIndex(1)
buttonGenerateReport.Enable()
}
dialog.ShowFileOpen(onChosen, mainWindow)
})
buttonGenerateReport := widget.NewButton("Generate report", func() {
recordtime, _ := time.Parse("2006/01/02 15:04", datetimeInput.Text)
pdf.RenderPDF(titleInput.Text, wavelengthInput.Text, pulsewidthInput.Text, fibertypeInput.Text, locationaInput.Text, locationbInput.Text, projectInput.Text, customerInput.Text, remarksInput.Text, &plotCanvas.Image, iorInput.Text, testerInput.Text, contactInfoInput.Text, fiberNoInput.Text, events, fiberLenInput.Text, recordtime)
})
fileLayout := container.New(layout.NewVBoxLayout(), buttonReadFile, buttonGenerateReport)
tabs.Append(container.NewTabItem("File", fileLayout))

View file

@ -12,6 +12,7 @@ import (
// renderPdf creates a report.pdf with sections similar to the sample.
func RenderPDF(
filepath string,
title string,
wavelength string,
pulsewidth string,
@ -90,7 +91,7 @@ func RenderPDF(
{{"Link Length", link.LinkLengthM}, {"Loss", link.LossdB}},
})
return pdf.OutputFileAndClose("report.pdf")
return pdf.OutputFileAndClose(filepath)
}
// ---- Helper drawing functions ----