package main import ( "fmt" "os" "strconv" "github.com/gotk3/gotk3/gtk" ) type Applicant struct { FirstName string LastName string DateOfBirth Date Sex Sex Address string ContactNo string Email string Education []Education } type Date struct { Year uint Month uint Day uint } type Education struct { Qualification string Institution string YearOfPassing uint GradeOrPercentage string } type Sex int var ui *gtk.Builder var selectedsex Sex var selecteddate Date const ( Male Sex = 1 Female = 2 Other = 3 ) /* func SaveToJson(a *Applicant) { b, err := json.Marshal(a) if err != nil { fmt.Println(err.Error()) os.Exit(2) } err = ioutil.WriteFile("test.json", b, 0644) if err != nil { fmt.Println(err.Error()) os.Exit(3) } } */ func getLineText(fieldname string) (string, error) { obj, err := ui.GetObject(fieldname) if err != nil { return "", err } field, ok := obj.(*gtk.Entry) if !ok { return "", err } fieldstr, err := field.GetText() if err != nil { return "", err } return fieldstr, nil } func getMultilineText(fieldname string) (string, error) { obj, err := ui.GetObject(fieldname) if err != nil { return "", err } fieldctl, ok := obj.(*gtk.TextView) if !ok { return "", err } textbuf, err := fieldctl.GetBuffer() if err != nil { return "", err } start, end := textbuf.GetBounds() textstr, err := textbuf.GetText(start, end, true) if err != nil { return "", err } return textstr, nil } func getBasicDetails() (*Applicant, error) { // Retrieve all the fields. firstname, err := getLineText("FirstName") if err != nil { return nil, err } lastname, err := getLineText("LastName") if err != nil { return nil, err } address, err := getMultilineText("Address") if err != nil { return nil, err } contact, err := getLineText("ContactNumber") if err != nil { return nil, err } email, err := getLineText("Email") if err != nil { return nil, err } // Store the contents in Applicant object var applicant = new(Applicant) applicant.FirstName = firstname applicant.LastName = lastname applicant.DateOfBirth = selecteddate applicant.Sex = selectedsex applicant.Address = address applicant.ContactNo = contact applicant.Email = email return applicant, nil } func getWindow() (*gtk.Window, error) { obj, err := ui.GetObject("MainWindow") if err != nil { fmt.Println(err.Error()) return nil, err } wnd, ok := obj.(*gtk.Window) if !ok { return nil, err } return wnd, nil } func LoadMain() { gtk.Init(nil) var err error ui, err = gtk.BuilderNew() if err != nil { fmt.Println(err.Error()) os.Exit(1) } asset, err := Asset("resources/resumebuilder.glade") if err != nil { fmt.Println(err.Error()) os.Exit(1) } ui.AddFromString(string(asset)) ui.ConnectSignals(map[string]interface{}{"SexMaleSelected": sexMaleSelected, "SexFemaleSelected": sexFemaleSelected, "SexOtherSelected": sexOtherSelected, "SaveButtonClicked": saveButtonClicked, "DoBSelected": doBSelected, "AddEducationClicked": addEducationClicked}) wnd, err := getWindow() if err != nil { os.Exit(1) } wnd.SetTitle("Resume Builder") wnd.ShowAll() selectedsex = Male wnd.Connect("destroy", func() { gtk.MainQuit() }) gtk.Main() } func sexMaleSelected(male *gtk.RadioButton) { if male.GetActive() { selectedsex = Male } } func sexFemaleSelected(female *gtk.RadioButton) { if female.GetActive() { selectedsex = Female } } func sexOtherSelected(other *gtk.RadioButton) { if other.GetActive() { selectedsex = Other } } func doBSelected(dob *gtk.Calendar) { selecteddate.Year, selecteddate.Month, selecteddate.Day = dob.GetDate() } func getEducationFields() (*Education, error) { ed := new(Education) qual, err := getLineText("QualificationTitle") if err != nil { return nil, err } inst, err := getLineText("InstitutionName") if err != nil { return nil, err } yearp, err := getLineText("YearPassing") if err != nil { return nil, err } year, err := strconv.Atoi(yearp) if err != nil { return nil, err } gradep, err := getLineText("GradeOrPercentag") if err != nil { return nil, err } ed.Qualification = qual ed.Institution = inst ed.YearOfPassing = uint(year) ed.GradeOrPercentage = gradep return ed, nil } func addEducationClicked() { ed, err := getEducationFields() if err != nil { return } lstore, err := ui.GetObject("EducationStore") if err != nil { return } edustore, ok := lstore.(*gtk.ListStore) if !ok { return } iter := edustore.Append() edustore.SetValue(iter, 0, ed.Qualification) edustore.SetValue(iter, 1, ed.Institution) edustore.SetValue(iter, 2, ed.YearOfPassing) edustore.SetValue(iter, 3, ed.GradeOrPercentage) } func saveButtonClicked() { a, err := getBasicDetails() if err != nil { fmt.Println(err.Error()) os.Exit(1) } fmt.Println(*a) } func main() { LoadMain() }