cover-crawler/main.go

97 lines
2.2 KiB
Go

package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"golang.org/x/image/colornames"
)
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("封面获取器")
myWindow.Resize(fyne.NewSize(640, 480))
// 创建显示框
displayBox1 := widget.NewLabel("未选择")
displayBox2 := widget.NewLabel("未选择")
displayBoxInfo := canvas.NewText("", colornames.Blue)
// 创建目录选择框
dirSelect1 := widget.NewButton("选择作品存放目录", func() {
dirDialog := dialog.NewFolderOpen(func(d fyne.ListableURI, err error) {
if err == nil && d != nil {
displayBox1.SetText(d.Path())
}
}, myWindow)
dirDialog.Show()
})
dirSelect2 := widget.NewButton("选择输出目录", func() {
dirDialog := dialog.NewFolderOpen(func(d fyne.ListableURI, err error) {
if err == nil && d != nil {
displayBox2.SetText(d.Path())
}
}, myWindow)
dirDialog.Show()
})
// 创建确定按钮
okButton := widget.NewButton("确 定", func() {
dir1 := displayBox1.Text
dir2 := displayBox2.Text
displayBoxInfo.Color = colornames.Blue
displayBoxInfo.Text = "处理中ing..."
crawler := NewCrawler(dir1, dir2)
if err := crawler.Handle(); err != nil {
displayBoxInfo.Color = colornames.Red
displayBoxInfo.Text = err.Error()
} else {
displayBoxInfo.Color = colornames.Green
displayBoxInfo.Text = "处理完成"
}
})
// 创建水平布局,将目录选择框和显示框并排排列
dirSelect1WithDisplay := container.NewHBox(
dirSelect1,
displayBox1,
)
dirSelect2WithDisplay := container.NewHBox(
dirSelect2,
displayBox2,
)
dirSelect3WithDisplay := container.NewHBox(
layout.NewSpacer(),
displayBoxInfo,
layout.NewSpacer(),
)
// 创建水平布局,将确定按钮居中
okButtonContainer := container.NewHBox(
layout.NewSpacer(),
okButton,
layout.NewSpacer(),
)
// 创建垂直布局,将上述水平布局和确定按钮垂直排列
content := container.NewVBox(
dirSelect1WithDisplay,
dirSelect2WithDisplay,
dirSelect3WithDisplay,
layout.NewSpacer(),
okButtonContainer,
)
myWindow.SetContent(content)
myWindow.ShowAndRun()
}