From: Harishankar Date: Wed, 24 Oct 2018 08:07:11 +0000 (+0530) Subject: Implementing some basic getters/setters X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=fe908b8a22c42cde9132182fd8448040e002d828;p=resumebuilder.git Implementing some basic getters/setters Implementing some basic getters/setters for the Gtk dialog box. --- diff --git a/ResumeBuilder b/ResumeBuilder index c4c2cbf..d472655 100755 Binary files a/ResumeBuilder and b/ResumeBuilder differ diff --git a/resumebuilder.go b/resumebuilder.go index cc78373..82186cc 100644 --- a/resumebuilder.go +++ b/resumebuilder.go @@ -23,6 +23,8 @@ type Education struct { type Sex int +var ui *gtk.Builder + const ( Male Sex = 1 Female = 2 @@ -43,7 +45,41 @@ const ( } } */ -func getWindow(ui gtk.Builder) (*gtk.Window, error) { +func getBasicDetails() (*Applicant, error) { + obj, err := ui.GetObject("FirstName") + if err != nil { + return nil, err + } + fsname, ok := obj.(*gtk.Entry) + if !ok { + return nil, err + } + firstname, err := fsname.GetText() + if err != nil { + return nil, err + } + obj, err = ui.GetObject("LastName") + if err != nil { + return nil, err + } + lsname, ok := obj.(*gtk.Entry) + if !ok { + return nil, err + } + lastname, err := lsname.GetText() + if err != nil { + return nil, err + } + + var applicant = new(Applicant) + + applicant.FirstName = firstname + applicant.LastName = lastname + + return applicant, nil +} + +func getWindow() (*gtk.Window, error) { obj, err := ui.GetObject("MainWindow") if err != nil { fmt.Println(err.Error()) @@ -56,26 +92,35 @@ func getWindow(ui gtk.Builder) (*gtk.Window, error) { return wnd, nil } +func getSaveButton() (*gtk.Button, error) { + btnobj, err := ui.GetObject("SaveButton") + if err != nil { + fmt.Println(err.Error()) + return nil, err + } + btn, ok := btnobj.(*gtk.Button) + if !ok { + return nil, err + } + return btn, nil +} + func LoadMain() { gtk.Init(nil) - ui, err := gtk.BuilderNewFromFile("resumebuilder.glade") + var err error + ui, err = gtk.BuilderNewFromFile("resumebuilder.glade") if err != nil { fmt.Println(err.Error()) os.Exit(1) } - wnd, err := getWindow(*ui) + wnd, err := getWindow() if err != nil { os.Exit(1) } - btnobj, err := ui.GetObject("SaveButton") + btn, err := getSaveButton() if err != nil { - fmt.Println(err.Error()) - os.Exit(1) - } - btn, ok := btnobj.(*gtk.Button) - if !ok { os.Exit(1) } btn.Connect("clicked", SaveButtonClicked) @@ -89,7 +134,12 @@ func LoadMain() { } func SaveButtonClicked() { - + a, err := getBasicDetails() + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + fmt.Println(*a) } func main() {