From ae44599a6af801e25d2ea64155df044c19d063db Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 4 Jan 2022 13:28:45 +0000 Subject: rescribe: Restrict file types to select for .pdf and .traineddata file pickers --- cmd/rescribe/gui.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'cmd/rescribe') diff --git a/cmd/rescribe/gui.go b/cmd/rescribe/gui.go index 2fed6e2..8458230 100644 --- a/cmd/rescribe/gui.go +++ b/cmd/rescribe/gui.go @@ -18,6 +18,7 @@ import ( "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/layout" + "fyne.io/fyne/v2/storage" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" ) @@ -106,7 +107,7 @@ func trainingSelectOnChange(sel *widget.Select, parent fyne.Window) func(string) if str != "Other..." { return } - dialog.ShowFileOpen(func(uri fyne.URIReadCloser, err error) { + d := dialog.NewFileOpen(func(uri fyne.URIReadCloser, err error) { if err != nil || uri == nil { return } @@ -130,6 +131,8 @@ func trainingSelectOnChange(sel *widget.Select, parent fyne.Window) func(string) sel.Options = opts sel.SetSelectedIndex(0) }, parent) + d.SetFilter(storage.NewExtensionFileFilter([]string{".traineddata"})) + d.Show() } } @@ -181,7 +184,7 @@ func startGui(log log.Logger, cmd string, training string, tessdir string) error }) pdfBtn := widget.NewButtonWithIcon("Choose PDF", theme.DocumentIcon(), func() { - dialog.ShowFileOpen(func(uri fyne.URIReadCloser, err error) { + d := dialog.NewFileOpen(func(uri fyne.URIReadCloser, err error) { if err == nil && uri != nil { uri.Close() dir.SetText(uri.URI().Path()) @@ -190,6 +193,8 @@ func startGui(log log.Logger, cmd string, training string, tessdir string) error gobtn.Enable() } }, myWindow) + d.SetFilter(storage.NewExtensionFileFilter([]string{".pdf"})) + d.Show() }) gbookBtn := widget.NewButtonWithIcon("Get Google Book", theme.SearchIcon(), func() { -- cgit v1.2.1-24-ge1ad