Made resource management
[resumebuilder.git] / resumebuilder.go
1 package main
2
3 import (
4 "fmt"
5 "os"
6
7 "github.com/gotk3/gotk3/gtk"
8 )
9
10 type Applicant struct {
11 FirstName string
12 LastName string
13 Age int
14 Sex Sex
15 Education []Education
16 }
17
18 type Education struct {
19 SchoolName string
20 YearOfPassing int
21 PassPercentage float32
22 }
23
24 type Sex int
25
26 var ui *gtk.Builder
27
28 const (
29 Male Sex = 1
30 Female = 2
31 Other = 3
32 )
33
34 /* func SaveToJson(a *Applicant) {
35 b, err := json.Marshal(a)
36
37 if err != nil {
38 fmt.Println(err.Error())
39 os.Exit(2)
40 }
41 err = ioutil.WriteFile("test.json", b, 0644)
42 if err != nil {
43 fmt.Println(err.Error())
44 os.Exit(3)
45 }
46 } */
47
48 func getBasicDetails() (*Applicant, error) {
49 obj, err := ui.GetObject("FirstName")
50 if err != nil {
51 return nil, err
52 }
53 fsname, ok := obj.(*gtk.Entry)
54 if !ok {
55 return nil, err
56 }
57 firstname, err := fsname.GetText()
58 if err != nil {
59 return nil, err
60 }
61 obj, err = ui.GetObject("LastName")
62 if err != nil {
63 return nil, err
64 }
65 lsname, ok := obj.(*gtk.Entry)
66 if !ok {
67 return nil, err
68 }
69 lastname, err := lsname.GetText()
70 if err != nil {
71 return nil, err
72 }
73
74 var applicant = new(Applicant)
75
76 applicant.FirstName = firstname
77 applicant.LastName = lastname
78
79 return applicant, nil
80 }
81
82 func getWindow() (*gtk.Window, error) {
83 obj, err := ui.GetObject("MainWindow")
84 if err != nil {
85 fmt.Println(err.Error())
86 return nil, err
87 }
88 wnd, ok := obj.(*gtk.Window)
89 if !ok {
90 return nil, err
91 }
92 return wnd, nil
93 }
94
95 func getSaveButton() (*gtk.Button, error) {
96 btnobj, err := ui.GetObject("SaveButton")
97 if err != nil {
98 fmt.Println(err.Error())
99 return nil, err
100 }
101 btn, ok := btnobj.(*gtk.Button)
102 if !ok {
103 return nil, err
104 }
105 return btn, nil
106 }
107
108 func LoadMain() {
109 gtk.Init(nil)
110 var err error
111 ui, err = gtk.BuilderNew()
112 if err != nil {
113 fmt.Println(err.Error())
114 os.Exit(1)
115 }
116 asset, err := Asset("resources/resumebuilder.glade")
117 if err != nil {
118 fmt.Println(err.Error())
119 os.Exit(1)
120 }
121 ui.AddFromString(string(asset))
122
123 wnd, err := getWindow()
124 if err != nil {
125 os.Exit(1)
126 }
127
128 btn, err := getSaveButton()
129 if err != nil {
130 os.Exit(1)
131 }
132 btn.Connect("clicked", SaveButtonClicked)
133 wnd.SetTitle("Resume Builder")
134 wnd.ShowAll()
135
136 wnd.Connect("destroy", func() {
137 gtk.MainQuit()
138 })
139 gtk.Main()
140 }
141
142 func SaveButtonClicked() {
143 a, err := getBasicDetails()
144 if err != nil {
145 fmt.Println(err.Error())
146 os.Exit(1)
147 }
148 fmt.Println(*a)
149 }
150
151 func main() {
152 LoadMain()
153 }