1

Update copyrights, UI

This commit is contained in:
Alex Yatskov 2021-01-01 16:18:55 -08:00
parent 795af5caa1
commit ea34cf9a37
17 changed files with 43 additions and 84 deletions

View File

@ -1,4 +1,4 @@
Copyright 2016-2019 Alex Yatskov
Copyright 2016-2021 Alex Yatskov
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -274,8 +273,8 @@ func hasString(needle string, haystack []string) bool {
return false
}
func detectFormat(path *string) (string, error) {
switch filepath.Ext(*path) {
func detectFormat(path string) (string, error) {
switch filepath.Ext(path) {
case ".sqlite":
return "rikai", nil
case ".kanjifreq":
@ -284,25 +283,22 @@ func detectFormat(path *string) (string, error) {
return "termfreq", nil
}
switch filepath.Base(*path) {
switch filepath.Base(path) {
case "JMdict", "JMdict.xml", "JMdict_e", "JMdict_e.xml":
return "edict", nil
case "JMnedict", "JMnedict.xml":
return "enamdict", nil
case "kanjidic2", "kanjidic2.xml":
return "kanjidic", nil
case "CATALOGS":
*path = filepath.Dir(*path)
return "epwing", nil
}
info, err := os.Stat(*path)
info, err := os.Stat(path)
if err != nil {
return "", err
}
if info.IsDir() {
_, err := os.Stat(filepath.Join(*path, "CATALOGS"))
_, err := os.Stat(filepath.Join(path, "CATALOGS"))
if err == nil {
return "epwing", nil
}
@ -324,7 +320,7 @@ func ExportDb(inputPath, outputPath, format, language, title string, stride int,
var err error
if format == DefaultFormat {
if format, err = detectFormat(&inputPath); err != nil {
if format, err = detectFormat(inputPath); err != nil {
return err
}
}

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2017-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>, ajyliew
* Author: ajyliew
* Copyright (c) 2017-2021 Alex Yatskov <alex@foosoft.net>, ajyliew
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>, ajyliew
* Author: ajyliew
* Copyright (c) 2017-2021 Alex Yatskov <alex@foosoft.net>, ajyliew
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2017-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>, ajyliew
* Author: Alex Yatskov <alex@foosoft.net>, ajyliew
* Copyright (c) 2017-2021 Alex Yatskov <alex@foosoft.net>, ajyliew
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2017-2019 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -23,9 +22,8 @@
package main
import (
"log"
"fmt"
"path/filepath"
"strings"
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
@ -33,20 +31,8 @@ import (
yomichan "github.com/FooSoft/yomichan-import"
)
type logger struct {
entry *ui.Entry
}
func (l *logger) Write(p []byte) (n int, err error) {
ui.QueueMain(func() {
l.entry.SetText(strings.Trim(string(p), "\n"))
})
return len(p), nil
}
func gui() error {
return ui.Main(func() {
func main() {
ui.Main(func() {
pathSourceEntry := ui.NewEntry()
pathSourceButton := ui.NewButton("Browse...")
pathSourceBox := ui.NewHorizontalBox()
@ -59,15 +45,14 @@ func gui() error {
pathTargetBox.Append(pathTargetEntry, true)
pathTargetBox.Append(pathTargetButton, false)
importButton := ui.NewButton("Import dictionary...")
titleEntry := ui.NewEntry()
titleEntry.SetText(yomichan.DefaultTitle)
languageEntry := ui.NewEntry()
languageEntry.SetText(yomichan.DefaultLanguage)
outputEntry := ui.NewEntry()
importButton := ui.NewButton("Import dictionary...")
mainBox := ui.NewVerticalBox()
mainBox.Append(ui.NewLabel("Path to dictionary source (CATALOGS file for EPWING)"), false)
mainBox.Append(pathSourceBox, false)
@ -77,12 +62,10 @@ func gui() error {
mainBox.Append(titleEntry, false)
mainBox.Append(ui.NewLabel("Dictionary glossary language (blank for English)"), false)
mainBox.Append(languageEntry, false)
mainBox.Append(ui.NewLabel("Application output"), false)
mainBox.Append(outputEntry, false)
mainBox.Append(ui.NewVerticalBox(), true)
mainBox.Append(importButton, false)
window := ui.NewWindow("Yomichan Import", 640, 320, false)
window := ui.NewWindow("Yomichan Import", 640, 280, false)
window.SetMargined(true)
window.SetChild(mainBox)
@ -102,13 +85,14 @@ func gui() error {
}
})
log.SetOutput(&logger{outputEntry})
importButton.OnClicked(func(*ui.Button) {
importButton.Disable()
outputEntry.SetText("")
inputPath := pathSourceEntry.Text()
if filepath.Base(inputPath) == "CATALOGS" {
inputPath = filepath.Dir(inputPath)
}
if len(inputPath) == 0 {
ui.MsgBoxError(window, "Error", "You must specify a dictionary source path")
importButton.Enable()
@ -123,17 +107,7 @@ func gui() error {
}
go func() {
var err error
defer ui.QueueMain(func() {
importButton.Enable()
if err == nil {
ui.MsgBox(window, "Success", "Conversion process complete")
} else {
ui.MsgBox(window, "Error", "Conversion process failed")
}
})
err = yomichan.ExportDb(
err := yomichan.ExportDb(
inputPath,
outputPath,
yomichan.DefaultFormat,
@ -142,6 +116,15 @@ func gui() error {
yomichan.DefaultStride,
yomichan.DefaultPretty,
)
ui.QueueMain(func() {
importButton.Enable()
if err == nil {
ui.MsgBox(window, "Success", "Conversion process complete")
} else {
ui.MsgBox(window, "Error", fmt.Sprintf("Conversion process failed:\n%e", err))
}
})
}()
})
@ -153,9 +136,3 @@ func gui() error {
window.Show()
})
}
func main() {
if err := gui(); err != nil {
log.Fatal(err)
}
}

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2016 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
* Copyright (c) 2016-2021 Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in