-
Notifications
You must be signed in to change notification settings - Fork 0
/
desktop.go
87 lines (71 loc) · 1.82 KB
/
desktop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"log"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/widget"
)
type entryWriter struct {
entry *widget.Entry
}
func (ew entryWriter) Write(p []byte) (int, error) {
ew.entry.Append(string(p))
return len(p), nil
}
// View
func desktopView(controller *Controller) {
a := app.New()
w := a.NewWindow("Okkular Scraper")
logOutputTextArea := widget.NewMultiLineEntry()
writer := entryWriter{logOutputTextArea}
log.SetOutput(writer)
// Set the minimum size for the window
// w.SetFixedSize(true)
w.Resize(fyne.NewSize(1200, 600))
input := widget.NewEntry()
input.SetPlaceHolder("Enter or select Excel file path here")
// File chooser button
fileChooserButton := widget.NewButton("Select File", func() {
fileChooser := dialog.NewFileOpen(func(reader fyne.URIReadCloser, err error) {
if err == nil && reader != nil {
input.SetText(reader.URI().Path())
controller.UpdateExcelFilePath(input.Text)
}
}, w)
fileChooser.SetFilter(storage.NewExtensionFileFilter([]string{".xlsx", "xls"}))
fileChooser.Show()
})
exitButton := widget.NewButton(" Quit ", func() {
w.Close()
})
// Scrape button
scrapeButton := widget.NewButton(" Scrape ", func() {
controller.model.UpdateExcelFilePath(input.Text)
logOutputTextArea.SetText("")
if err := controller.HandleScrape(); err != nil {
dialog.NewError(err, w).Show()
}
})
// Create a layout container
content := container.NewBorder(
container.NewBorder(
nil,
nil,
widget.NewLabel("Excel File Path: "),
fileChooserButton,
input,
),
container.NewHBox(layout.NewSpacer(), scrapeButton, exitButton),
nil,
nil,
container.NewScroll(
logOutputTextArea,
),
)
w.SetContent(content)
w.ShowAndRun()
}