-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (60 loc) · 2.01 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
package main
import (
"path/filepath"
"runtime"
"github.com/CyrusRoshan/pickture/input"
"github.com/CyrusRoshan/pickture/logic"
"github.com/CyrusRoshan/pickture/ui"
"github.com/CyrusRoshan/pickture/utils"
"github.com/alexflint/go-arg"
"github.com/gotk3/gotk3/gtk"
)
const (
Title = "pickture"
)
func main() {
// Lock to prevent segfaults on gtk.Main()
// https://github.com/gotk3/gotk3/issues/251
runtime.LockOSThread()
// Initialize GUI library
gtk.Init(nil)
window, err := ui.BuildWindow(Title)
utils.PanicIfErr(err, "Could not build window")
// Initialize pickture logic
rootWidget, updateRender := ui.Root(window)
SetupInternals(window, updateRender)
// Hook in and render the UI
window.Add(rootWidget)
window.ShowAll()
// Execute and block main thread
gtk.Main()
}
func SetupInternals(window *gtk.Window, OnChange func()) {
var args = struct {
Input string `arg:"positional" help:"Input folder (where all input files are stored in)"`
Output string `arg:"positional" help:"Output folder (where the sorted folders and their contents will go)"`
DisableUniqueSuffix bool `arg:"--nosuffix" help:"disable unique suffix for images. Warning: may result in errors if nested input folders have files with conflicting names."`
}{
Input: "./input",
Output: "./output",
DisableUniqueSuffix: false,
}
arg.MustParse(&args)
getAbsPath := func(path string) string {
abs, err := filepath.Abs(path)
utils.PanicIfErr(err, "Could not get absolute path for "+path)
return abs
}
logic.Init(logic.InitProperties{
InputPath: getAbsPath(args.Input),
AOutputPath: getAbsPath(args.Output + "/A"),
SOutputPath: getAbsPath(args.Output + "/S"),
DOutputPath: getAbsPath(args.Output + "/D"),
QOutputPath: getAbsPath(args.Output + "/Q"),
WOutputPath: getAbsPath(args.Output + "/W"),
EOutputPath: getAbsPath(args.Output + "/E"),
DisableUniqueSuffix: args.DisableUniqueSuffix,
InputEvents: input.BindKeyPressEvents(window),
OnChange: OnChange,
})
}