-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
175 lines (152 loc) · 4.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
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
var Version = "dev"
func main() {
var outTE *walk.TextEdit
var urlInput *walk.LineEdit
var pathInput *walk.LineEdit
var proxyInput *walk.LineEdit
// walk.TabPage
var startBtn, stopBtn *walk.PushButton
var down *Download
// stopBtn
var ch = make(chan bool)
var mw *MainWindow
mw = &MainWindow{
Title: "漫画下载器" + Version,
Size: Size{Width: 400, Height: 600},
Layout: VBox{},
MenuItems: []MenuItem{
Menu{
Text: "&Help",
Items: []MenuItem{
Action{
Text: "About",
OnTriggered: func() { aboutAction_Triggered() },
},
Action{
Text: "页面空白",
OnTriggered: func() { tips() },
},
},
},
},
Children: []Widget{
Label{Text: "页面空白的话,切换一下tab", TextColor: walk.RGB(102, 178, 255)},
TabWidget{
Pages: []TabPage{
{
Title: "下载",
// Layout: Grid{Columns: 2},
Visible: true,
Layout: VBox{},
Children: []Widget{
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{Text: "网址", TextColor: walk.RGB(255, 0, 127)},
LineEdit{
Text: "",
AssignTo: &urlInput,
},
Label{Text: "保存路径"},
LineEdit{
Text: ``,
AssignTo: &pathInput,
},
Label{Text: "代理"},
LineEdit{
Text: "",
AssignTo: &proxyInput, ToolTipText: "比如 socks5://127.0.0.1:1080",
},
},
},
PushButton{
Text: "下载",
AssignTo: &startBtn,
MaxSize: Size{Width: 400, Height: 100},
MinSize: Size{Width: 300, Height: 30},
Background: SolidColorBrush{Color: walk.RGB(0x5F, 0x69, 0x8E)},
OnClicked: func() {
url := urlInput.Text()
path := pathInput.Text()
proxy := proxyInput.Text()
if url == "" {
walk.MsgBox(nil, "错误", "网址为空", walk.MsgBoxIconError)
return
}
if path == "" {
walk.MsgBox(nil, "错误", "网址为空", walk.MsgBoxIconError)
return
}
outTE.SetText("开始下载\r\n")
startBtn.SetEnabled(false)
stopBtn.SetEnabled(true)
down = NewDownload(url, path, proxy, outTE)
// 在协程里下载,避免界面卡死
go down.Start(ch)
// 在协程里等待任务执行完成
go func() {
<-ch
startBtn.SetEnabled(true)
stopBtn.SetEnabled(false)
walk.MsgBox(nil, "OK", "任务已结束", walk.MsgBoxOK)
}()
},
},
PushButton{
Text: "停止",
AssignTo: &stopBtn,
MaxSize: Size{Width: 400, Height: 100},
MinSize: Size{Width: 300, Height: 30},
Background: SolidColorBrush{Color: walk.RGB(0x5F, 0x69, 0x8E)},
Enabled: false,
OnClicked: func() {
down.Stop()
},
},
Composite{
Layout: Grid{Columns: 2},
Children: []Widget{
Label{Text: "log", TextColor: walk.RGB(255, 0, 127)},
TextEdit{AssignTo: &outTE, ReadOnly: true, VScroll: true},
},
},
},
},
{
Title: "About",
// Layout: Grid{Columns: 2},
Layout: VBox{},
Visible: true,
Children: []Widget{
Label{Text: "漫画下载器" + Version},
Label{Text: "下载:有的网站会限流,会导致失败;失败的图片不会保存;重新下载即可(多次下载的时候遇到磁盘已有文件就跳过)"},
TextEdit{
Text: "项目地址: https://github.com/hwhaocool/hanman\r\n" +
"支持解析 www.tuwenhanman.com\r\n" +
"支持解析 bingmh.com\r\n",
ReadOnly: true},
},
},
},
},
},
}
mw.Run()
}
func aboutAction_Triggered() {
walk.MsgBox(nil,
"提示",
"漫画下载器, enjoy it~",
walk.MsgBoxOK|walk.MsgBoxIconInformation)
}
func tips() {
walk.MsgBox(nil,
"提示",
"页面空白的话,切换一下tab",
walk.MsgBoxOK|walk.MsgBoxIconInformation)
}