-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
217 lines (166 loc) · 5.16 KB
/
main.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package main
import (
"bufio"
"io/ioutil"
"os"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
type config struct {
startDate *widget.Entry
endDate *widget.Entry
loadButton *widget.Button
saveButton *widget.Button
loadEntry *widget.Entry
saveEntry *widget.Entry
startButton *widget.Button
progressBar *widget.ProgressBar
textDone *widget.Label
sheetList *widget.Label
}
var cnf config
func main() {
a := app.New()
win := a.NewWindow("Excel parser")
r, _ := fyne.LoadResourceFromPath("Icon.png")
// change icon
a.SetIcon(r)
progressBar, textDone, fromButton, toButton, sheetLabel:= cnf.MakeUI(win)
loadButton, startButton, saveButton := cnf.Buttons(win)
startDate, endDate, loadInput, saveInput := cnf.Entries(win)
win.SetContent(container.NewWithoutLayout(
loadButton,
startDate,
loadInput,
saveInput,
endDate,
startButton,
progressBar,
textDone,
saveButton,
fromButton,
toButton,
sheetLabel,
),)
win.Resize(fyne.NewSize(600, 600))
// win.SetFixedSize(true)
win.CenterOnScreen()
win.ShowAndRun()
}
func (app *config) MakeUI(win fyne.Window) (*widget.ProgressBar,*widget.Label, *widget.Button, *widget.Button, *widget.Label) {
w := win.Canvas()
iconFile, _ := os.Open("calendar.jpg")
r := bufio.NewReader(iconFile)
b, _ := ioutil.ReadAll(r)
fromButton := widget.NewButtonWithIcon("", fyne.NewStaticResource("icon", b), func() {
NewCalendarAtPos(w, fyne.NewPos(10, 10),time.Now(), func(t time.Time){
app.startDate.SetText(t.Format("01/02/2006"))
})
})
fromButton.Resize(fyne.NewSize(38, 38))
fromButton.Move(fyne.NewPos(260, 51))
toButton := widget.NewButtonWithIcon("", fyne.NewStaticResource("icon", b), func() {
NewCalendarAtPos(w, fyne.NewPos(300, 10),time.Now(), func(t time.Time){
app.endDate.SetText(t.Format("01/02/2006"))
})
})
toButton.Resize(fyne.NewSize(38, 38))
toButton.Move(fyne.NewPos(550, 51))
sheetsLabel := widget.NewLabel("Sheets: 0/0")
sheetsLabel.Move(fyne.NewPos(10, 270))
sheetsLabel.TextStyle.Bold = true
app.sheetList = sheetsLabel
progressBar := widget.NewProgressBar()
progressBar.Resize(fyne.NewSize(500, 38)) // my widget size
progressBar.Move(fyne.NewPos(10, 300)) // position of widget
app.progressBar = progressBar
textDone := widget.NewLabel("DONE")
textDone.Move(fyne.NewPos(510, 300))
textDone.TextStyle.Bold = true
textDone.Hidden = true
app.textDone = textDone
return progressBar, textDone, fromButton, toButton, sheetsLabel
}
func (app *config) Entries(win fyne.Window) (*widget.Entry, *widget.Entry, *widget.Entry, *widget.Entry){
startDate := widget.NewEntry()
startDate.SetPlaceHolder("mm/dd/yyyy")
startDate.Resize(fyne.NewSize(250, 38)) // my widget size
startDate.Move(fyne.NewPos(10, 50)) // position of widget
endDate := widget.NewEntry()
endDate.SetPlaceHolder("mm/dd/yyyy")
endDate.Resize(fyne.NewSize(250, 38)) // my widget size
endDate.Move(fyne.NewPos(300, 50)) // position of widget
app.startDate = startDate
app.endDate = endDate
loadInput := widget.NewEntry()
loadInput.SetPlaceHolder("")
loadInput.Resize(fyne.NewSize(250, 38)) // my widget size
loadInput.Move(fyne.NewPos(10, 100)) // position of widget
app.loadEntry = loadInput
saveInput := widget.NewEntry()
saveInput.SetPlaceHolder("")
saveInput.Resize(fyne.NewSize(250, 38)) // my widget size
saveInput.Move(fyne.NewPos(10, 150)) // position of widget
app.saveEntry = saveInput
return startDate, endDate, loadInput, saveInput
}
func (app *config) Buttons(win fyne.Window) (*widget.Button, *widget.Button, *widget.Button){
loadButton := widget.NewButton("Load excel file", app.openFunc(win))
loadButton.Resize(fyne.NewSize(170, 38))
loadButton.Move(fyne.NewPos(270, 100))
app.loadButton = loadButton
saveButton := widget.NewButton("Save file", app.saveFunc(win))
saveButton.Resize(fyne.NewSize(170, 38))
saveButton.Move(fyne.NewPos(270, 150))
app.saveButton = saveButton
startButton := widget.NewButton("Start", app.startFunc(win))
startButton.Resize(fyne.NewSize(200, 50))
startButton.Move(fyne.NewPos(10, 200))
app.startButton = startButton
return loadButton, startButton, saveButton
}
func (app *config) openFunc(win fyne.Window) func(){
return func(){
file_Dialog := dialog.NewFileOpen(
func(read fyne.URIReadCloser, err error) {
if err != nil {
dialog.ShowError(err, win)
return
}
if read == nil{
return
}
defer read.Close()
app.loadEntry.SetText(read.URI().Path())
app.loadSheets()
}, win)
file_Dialog.Resize(fyne.NewSize(500, 500))
file_Dialog.Show()
// Show file selection dialog.
}
}
func (app *config) saveFunc(win fyne.Window) func(){
return func(){
saveDialog := dialog.NewFileSave(func(write fyne.URIWriteCloser, err error){
if err != nil{
dialog.ShowError(err, win)
return
}
if write == nil {
// user cancelled
return
}
app.saveEntry.SetText(write.URI().Path())
}, win)
saveDialog.SetFileName("NewFile.xlsx")
saveDialog.Resize(fyne.NewSize(500, 500))
saveDialog.Show()
}
}
func (app *config) startFunc(win fyne.Window) func(){
return app.getData
}