more work on ui
This commit is contained in:
parent
b05d7834f6
commit
8e2eed721b
41
gui.go
41
gui.go
@ -23,6 +23,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/andlabs/ui"
|
||||
)
|
||||
|
||||
@ -35,7 +37,7 @@ func gui() error {
|
||||
pathBox.Append(browseButton, false)
|
||||
|
||||
portSpin := ui.NewSpinbox(0, 65535)
|
||||
portSpin.SetValue(9876)
|
||||
portSpin.SetValue(DEFAULT_PORT)
|
||||
|
||||
formatCombo := ui.NewCombobox()
|
||||
formatCombo.Append("EPWING")
|
||||
@ -71,6 +73,43 @@ func gui() error {
|
||||
}
|
||||
})
|
||||
|
||||
importButton.OnClicked(func(*ui.Button) {
|
||||
defer importButton.Enable()
|
||||
importButton.Disable()
|
||||
outputLabel.SetText("")
|
||||
|
||||
var (
|
||||
outputDir string
|
||||
err error
|
||||
)
|
||||
|
||||
if outputDir, err = makeTmpDir(); err != nil {
|
||||
ui.MsgBoxError(window, "Error", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
inputPath := pathEntry.Text()
|
||||
if len(inputPath) == 0 {
|
||||
ui.MsgBoxError(window, "Error", "You must specify a dictionary source path.")
|
||||
return
|
||||
}
|
||||
|
||||
format := []string{"epwing", "edict", "enamdict", "kanjidic"}[formatCombo.Selected()]
|
||||
if format == "epwing" {
|
||||
inputPath = path.Dir(inputPath)
|
||||
}
|
||||
|
||||
if err := exportDb(pathEntry.Text(), outputDir, format, titleEntry.Text(), DEFAULT_STRIDE, false); err != nil {
|
||||
ui.MsgBoxError(window, "Error", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := serveDb(outputDir, portSpin.Value()); err != nil {
|
||||
ui.MsgBoxError(window, "Error", err.Error())
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
window.OnClosing(func(*ui.Window) bool {
|
||||
ui.Quit()
|
||||
return true
|
||||
|
15
main.go
15
main.go
@ -33,6 +33,11 @@ import (
|
||||
"path"
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_STRIDE = 10000
|
||||
DEFAULT_PORT = 9876
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [options] input-path [output-dir]\n", path.Base(os.Args[0]))
|
||||
fmt.Fprint(os.Stderr, "https://foosoft.net/projects/yomichan-import/\n\n")
|
||||
@ -62,13 +67,17 @@ func serveDb(serveDir string, port int) error {
|
||||
return http.ListenAndServe(fmt.Sprintf(":%d", port), http.FileServer(http.Dir(serveDir)))
|
||||
}
|
||||
|
||||
func makeTmpDir() (string, error) {
|
||||
return ioutil.TempDir("", "yomichan_tmp_")
|
||||
}
|
||||
|
||||
func main() {
|
||||
var (
|
||||
format = flag.String("format", "", "dictionary format [edict|enamdict|kanjidic|epwing]")
|
||||
port = flag.Int("port", 9876, "port to serve dictionary JSON on")
|
||||
port = flag.Int("port", DEFAULT_PORT, "port to serve dictionary JSON on")
|
||||
pretty = flag.Bool("pretty", false, "output prettified dictionary JSON")
|
||||
serve = flag.Bool("serve", false, "serve dictionary JSON for extension")
|
||||
stride = flag.Int("stride", 10000, "dictionary bank stride")
|
||||
stride = flag.Int("stride", DEFAULT_STRIDE, "dictionary bank stride")
|
||||
title = flag.String("title", "", "dictionary title")
|
||||
)
|
||||
|
||||
@ -106,7 +115,7 @@ func main() {
|
||||
|
||||
if outputDir == "" {
|
||||
var err error
|
||||
if outputDir, err = ioutil.TempDir("", "yomichan_tmp_"); err != nil {
|
||||
if outputDir, err = makeTmpDir(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user