From 2c29e91bd98a1354d0cc4772ca629e3f1fc327b5 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 21 Feb 2022 14:54:42 +0000 Subject: rescribe: Add getgbook use to the GUI (not embedded yet) --- cmd/rescribe/gui.go | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'cmd/rescribe/gui.go') diff --git a/cmd/rescribe/gui.go b/cmd/rescribe/gui.go index b8449b5..fde660a 100644 --- a/cmd/rescribe/gui.go +++ b/cmd/rescribe/gui.go @@ -26,6 +26,8 @@ import ( ) var progressPoints = map[float64]string{ + 0.11: "Downloading", + 0.12: "Processing PDF", 0.2: "Preprocessing", 0.5: "OCRing", 0.9: "Analysing", @@ -327,7 +329,7 @@ func startGui(log log.Logger, cmd string, training string, tessdir string) error if dirEntry.Text == "" { dirEntry.SetText(homeDir) } - dir.SetText(fmt.Sprintf("Google Book: %s Savedir: %s", id, dirEntry.Text)) + dir.SetText(fmt.Sprintf("Google Book: %s Save to: %s", id, dirEntry.Text)) dirIcon.SetResource(theme.SearchIcon()) myWindow.SetContent(fullContent) gobtn.Enable() @@ -452,18 +454,37 @@ func startGui(log log.Logger, cmd string, training string, tessdir string) error progressBar.SetValue(0.1) - if strings.HasPrefix(dir.Text, "Google Book:") { - // TODO - dialog.ShowError(errors.New("Coming soon"), myWindow) - progressBar.SetValue(0.0) - for _, v := range []fyne.Disableable{folderBtn, pdfBtn, gbookBtn, trainingOpts, gobtn} { - v.Enable() + if strings.HasPrefix(dir.Text, "Google Book: ") { + progressBar.SetValue(0.11) + start := len("Google Book: ") + bookname = dir.Text[start:start+12] + + start = start + 12 + len(" Save to: ") + bookdir = dir.Text[start:] + savedir = bookdir + + fmt.Printf("Downloading Google Book\n") + d, err := getGoogleBook(ctx, bookname, bookdir) + if err != nil { + if !strings.HasSuffix(err.Error(), "signal: killed") { + msg := fmt.Sprintf("Error downloading Google Book %s: %v\n", bookname, err) + dialog.ShowError(errors.New(msg), myWindow) + fmt.Fprintf(os.Stderr, msg) + } + progressBar.SetValue(0.0) + for _, v := range []fyne.Disableable{folderBtn, pdfBtn, gbookBtn, trainingOpts, gobtn} { + v.Enable() + } + abortbtn.Disable() + return } - abortbtn.Disable() - return + bookdir = d + savedir = d + bookname = filepath.Base(d) } if strings.HasSuffix(dir.Text, ".pdf") && !f.IsDir() { + progressBar.SetValue(0.12) bookdir, err = extractPdfImgs(ctx, bookdir) if err != nil { if !strings.HasSuffix(err.Error(), "context canceled") { -- cgit v1.2.1-24-ge1ad