zip support for gui
This commit is contained in:
parent
4c3e292470
commit
d39df0f3eb
63
gui.go
63
gui.go
@ -44,14 +44,17 @@ func (l *logger) Write(p []byte) (n int, err error) {
|
||||
|
||||
func gui() error {
|
||||
return ui.Main(func() {
|
||||
pathEntry := ui.NewEntry()
|
||||
browseButton := ui.NewButton("Browse...")
|
||||
pathBox := ui.NewHorizontalBox()
|
||||
pathBox.Append(pathEntry, true)
|
||||
pathBox.Append(browseButton, false)
|
||||
pathSourceEntry := ui.NewEntry()
|
||||
pathSourceButton := ui.NewButton("Browse...")
|
||||
pathSourceBox := ui.NewHorizontalBox()
|
||||
pathSourceBox.Append(pathSourceEntry, true)
|
||||
pathSourceBox.Append(pathSourceButton, false)
|
||||
|
||||
portSpin := ui.NewSpinbox(0, 65535)
|
||||
portSpin.SetValue(DEFAULT_PORT)
|
||||
pathTargetEntry := ui.NewEntry()
|
||||
pathTargetButton := ui.NewButton("Browse...")
|
||||
pathTargetBox := ui.NewHorizontalBox()
|
||||
pathTargetBox.Append(pathTargetEntry, true)
|
||||
pathTargetBox.Append(pathTargetButton, false)
|
||||
|
||||
formatCombo := ui.NewCombobox()
|
||||
formatCombo.Append("EPWING")
|
||||
@ -66,11 +69,11 @@ func gui() error {
|
||||
|
||||
mainBox := ui.NewVerticalBox()
|
||||
mainBox.Append(ui.NewLabel("Path to dictionary source (CATALOGS file for EPWING):"), false)
|
||||
mainBox.Append(pathBox, false)
|
||||
mainBox.Append(pathSourceBox, false)
|
||||
mainBox.Append(ui.NewLabel("Path to dictionary target ZIP file"), false)
|
||||
mainBox.Append(pathTargetBox, false)
|
||||
mainBox.Append(ui.NewLabel("Dictionary title (leave blank for default):"), false)
|
||||
mainBox.Append(titleEntry, false)
|
||||
mainBox.Append(ui.NewLabel("Network port for extension server:"), false)
|
||||
mainBox.Append(portSpin, false)
|
||||
mainBox.Append(ui.NewLabel("Dictionary format:"), false)
|
||||
mainBox.Append(formatCombo, false)
|
||||
mainBox.Append(ui.NewLabel("Application output:"), false)
|
||||
@ -82,9 +85,19 @@ func gui() error {
|
||||
window.SetMargined(true)
|
||||
window.SetChild(mainBox)
|
||||
|
||||
browseButton.OnClicked(func(*ui.Button) {
|
||||
pathSourceButton.OnClicked(func(*ui.Button) {
|
||||
if path := ui.OpenFile(window); len(path) > 0 {
|
||||
pathEntry.SetText(path)
|
||||
pathSourceEntry.SetText(path)
|
||||
}
|
||||
})
|
||||
|
||||
pathTargetButton.OnClicked(func(*ui.Button) {
|
||||
if path := ui.SaveFile(window); len(path) > 0 {
|
||||
if len(filepath.Ext(path)) == 0 {
|
||||
path += ".zip"
|
||||
}
|
||||
|
||||
pathTargetEntry.SetText(path)
|
||||
}
|
||||
})
|
||||
|
||||
@ -94,19 +107,16 @@ func gui() error {
|
||||
importButton.Disable()
|
||||
outputEntry.SetText("")
|
||||
|
||||
var (
|
||||
outputDir string
|
||||
err error
|
||||
)
|
||||
|
||||
if outputDir, err = makeTmpDir(); err != nil {
|
||||
ui.MsgBoxError(window, "Error", err.Error())
|
||||
inputPath := pathSourceEntry.Text()
|
||||
if len(inputPath) == 0 {
|
||||
ui.MsgBoxError(window, "Error", "You must specify a dictionary source path.")
|
||||
importButton.Enable()
|
||||
return
|
||||
}
|
||||
|
||||
inputPath := pathEntry.Text()
|
||||
if len(inputPath) == 0 {
|
||||
ui.MsgBoxError(window, "Error", "You must specify a dictionary source path.")
|
||||
outputPath := pathTargetEntry.Text()
|
||||
if len(outputPath) == 0 {
|
||||
ui.MsgBoxError(window, "Error", "You must specify a dictionary target path.")
|
||||
importButton.Enable()
|
||||
return
|
||||
}
|
||||
@ -117,21 +127,14 @@ func gui() error {
|
||||
}
|
||||
|
||||
title := titleEntry.Text()
|
||||
port := portSpin.Value()
|
||||
|
||||
go func() {
|
||||
defer ui.QueueMain(func() {
|
||||
importButton.Enable()
|
||||
})
|
||||
|
||||
if err := exportDb(inputPath, outputDir, format, "english", title, DEFAULT_STRIDE, false); err != nil {
|
||||
if err := exportDb(inputPath, outputPath, format, "english", title, DEFAULT_STRIDE, false); err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := serveDb(outputDir, port); err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
6
main.go
6
main.go
@ -28,7 +28,6 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
@ -63,11 +62,6 @@ func exportDb(inputPath, outputPath, format, language, title string, stride int,
|
||||
return handler(inputPath, outputPath, language, title, stride, pretty)
|
||||
}
|
||||
|
||||
func serveDb(serveDir string, port int) error {
|
||||
log.Printf("starting dictionary server on port %d...\n", port)
|
||||
return http.ListenAndServe(fmt.Sprintf(":%d", port), http.FileServer(http.Dir(serveDir)))
|
||||
}
|
||||
|
||||
func makeTmpDir() (string, error) {
|
||||
return ioutil.TempDir("", "yomichan_tmp_")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user