-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (74 loc) · 2.25 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
m "./morse"
"github.com/gotk3/gotk3/gtk"
"github.com/hajimehoshi/oto"
"log"
)
func main() {
gtk.Init(nil)
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
if err != nil {
log.Fatal("Unable to create window:", err)
}
m.SetWindowOptions(win)
grid, err := gtk.GridNew()
if err != nil {
log.Fatal("Unable to create grid:", err)
}
m.SetGridOptions(grid)
toLabel, _ := gtk.LabelNew("To Morse")
fromLabel, _ := gtk.LabelNew("From Morse")
toLabelResult, _ := gtk.LabelNew("To Morse Translation:")
fromLabelResult, _ := gtk.LabelNew("From Morse Translation:")
grid.Attach(toLabel, 0,0,1,1)
grid.Attach(fromLabel, 0,1,1,1)
grid.Attach(toLabelResult, 0,3,1,1)
grid.Attach(fromLabelResult, 0,4,1,1)
toEntry, _ := gtk.EntryNew()
fromEntry, _ := gtk.EntryNew()
grid.Attach(toEntry, 1,0,2,1)
grid.Attach(fromEntry, 1,1,2,1)
translateToBox := m.SetupBox(gtk.ORIENTATION_HORIZONTAL)
translateToTextView := m.SetupTview()
translateToBox.PackStart(translateToTextView, true, true, 0)
translateFromBox := m.SetupBox(gtk.ORIENTATION_HORIZONTAL)
translateFromTextView := m.SetupTview()
translateFromBox.PackStart(translateFromTextView, true, true, 0)
grid.Attach(translateToBox, 1,3,3,1)
grid.Attach(translateFromBox, 1,4,3,1)
toButton := m.SetupButton("Translate to", func() {
text := m.GetTextFromEntry(toEntry)
translation := m.TranslateToMorse(text)
buffer, err := translateToTextView.GetBuffer()
if err != nil {
log.Fatal("Unable to get the buffer", err)
}
buffer.SetText(translation)
})
fromButton := m.SetupButton("Translate from", func() {
text := m.GetTextFromEntry(fromEntry)
translation := m.TranslateFromMorse(text)
buffer, err := translateFromTextView.GetBuffer()
if err != nil {
log.Fatal("Unable to get the buffer", err)
}
buffer.SetText(translation)
})
c, err := oto.NewContext(20000, 2, 2, 4096)
if err != nil {
log.Fatal(err)
}
p := c.NewPlayer()
playButton := m.SetupButton("Play Morse Code", func() {
morseSequence := m.GetTextFromTview(translateToTextView)
m.MorseToSound(morseSequence, c, p)
})
grid.Attach(toButton, 3, 0, 1, 1)
grid.Attach(fromButton, 3, 1, 1, 1)
grid.Attach(playButton, 1,5,1,1)
win.Add(grid)
win.Connect("destroy", gtk.MainQuit)
win.ShowAll()
gtk.Main()
}