This repository has been archived by the owner on Aug 19, 2020. It is now read-only.
/
progress.go
96 lines (82 loc) · 1.96 KB
/
progress.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
// +build windows
// Copyright 2017 Martin Planer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package windows
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"github.com/martinplaner/gunarchiver/progress"
)
type progressWindow struct {
mainWindow *walk.MainWindow
progressBar *walk.ProgressBar
currentFile *walk.Label
dataBinder *walk.DataBinder
requestedCancel bool
err error
progress *progress.Progress
}
func (w *progressWindow) Show() error {
var cancelButton *walk.PushButton
main := MainWindow{
AssignTo: &w.mainWindow,
Title: "gunarchiver",
MinSize: Size{400, 100},
Layout: VBox{},
DataBinder: DataBinder{
AssignTo: &w.dataBinder,
DataSource: w.progress,
},
Children: []Widget{
Label{
AssignTo: &w.currentFile,
Text: "Starting...",
},
Composite{
Layout: Grid{Columns: 4},
Children: []Widget{
ProgressBar{
ColumnSpan: 3,
AssignTo: &w.progressBar,
MaxValue: 100,
},
PushButton{
ColumnSpan: 1,
AssignTo: &cancelButton,
Text: "Cancel",
MaxSize: Size{50, 50},
OnClicked: func() {
cancelButton.SetText("Canceling...")
cancelButton.SetEnabled(false)
w.requestedCancel = true
},
}},
},
},
}
_, err := main.Run()
return err
}
func (w *progressWindow) Update(p progress.Progress) {
*w.progress = p
if w.progressBar != nil {
w.progressBar.SetValue(p.Percentage)
}
if w.currentFile != nil {
w.currentFile.SetText("Extracting " + p.CurrentFile)
}
if w.mainWindow != nil {
pi := w.mainWindow.ProgressIndicator()
pi.SetTotal(100)
pi.SetCompleted(uint32(p.Percentage))
}
}
func (w *progressWindow) Close() {
for w.mainWindow == nil || w.err != nil {
}
w.mainWindow.Close()
}
func (w *progressWindow) RequestedCancel() bool {
return w.requestedCancel
}