File -> New action implemented
[biacv.git] / biacv_mainwindow.py
index 0f0f9ad..7d577da 100644 (file)
@@ -10,6 +10,92 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                PyQt4.QtGui.QMainWindow.__init__ (self)
                self.setupUi (self)
                self.currentfile = None
+               self.ismodified = False
+
+       # function to reset personal information data in the GUI
+       def reset_personal_info (self):
+               self.nametitle.setEditText ("")
+               self.firstname.setText ("")
+               self.lastname.setText ("")
+               self.dateofbirth.setDate (PyQt4.QtCore.QDate (1970, 1, 1))
+               self.street.setText ("")
+               self.area.setText ("")
+               self.city.setText ("")
+               self.countrycode_landline.setText ("")
+               self.telephone.setText ("")
+               self.countrycode_mobile.setText ("")
+               self.mobilenumber.setText ("")
+               self.email.setText ("")
+               self.areacode.setText ("")
+               self.unspecified.setChecked (True)
+
+       # function to clear professional history in the GUI
+       def reset_professional_history (self):
+               self.reset_profession_fields ()
+               self.professionlist.clear ()
+
+       # function to clear educational qualifications in the GUI
+       def reset_educational_qualifications (self):
+               self.reset_education_fields ()
+               self.educationlist.clear ()
+
+       # function to clear career objectives data in the GUI
+       def reset_career_objectives (self):
+               self.shorttermcareer.setPlainText ("")
+               self.longtermgoals.setPlainText ("")
+
+       # function to clear skill sets data in the GUI
+       def reset_skillsets_info (self):
+               self.reset_skillset_fields ()
+               self.skillslist.clear ()
+
+       # function to clear additional information data in the GUI
+       def reset_additional_info (self):
+               self.reset_language_fields ()
+               self.languageslist.clear ()
+               self.additionalinformation.setPlainText ("")
+
+       # function to clear all the fields and reset them to defaults
+       def new_document (self):
+               # first clear the individual record fields in the tabs
+               self.reset_language_fields ()
+               self.reset_skillset_fields ()
+
+               # clear document data
+               self.title.setText ("")
+
+               self.reset_personal_info ()
+               self.reset_professional_history ()
+               self.reset_educational_qualifications ()
+               self.reset_career_objectives ()
+               self.reset_skillsets_info ()
+               self.reset_additional_info ()
+
+               # set the page to first page
+               self.pages.setCurrentIndex (0)
+
+               # set current file to none and modified to false
+               self.currentfile = None
+               self.ismodified = False
+
+       # file new action is triggered
+       def on_file_new (self):
+               # if the previous document is modified
+               # as if it should be discarded
+               if self.ismodified is True:
+                       ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM,
+                               lang.CONFIRM_DISCARD_SAVE,
+                               PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
+                       if ans == PyQt4.QtGui.QMessageBox.Yes:
+                               self.new_document ()
+               # if not modified then simply create a new document
+               else:
+                       self.new_document ()
+
+       # when the document is modified
+       def on_document_modified (self):
+               # set the document modified flag
+               self.ismodified = True
 
        # update a language in the list of languages
        def on_update_lang (self):
@@ -28,6 +114,9 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                selitem.setText (2, str (self.canreadwrite.isChecked ()))
                selitem.setText (3, str (self.isproficient.isChecked ()))
 
+               # modified the document
+               self.ismodified = True
+
        # selecting a language from the list of languages
        def on_select_lang (self):
                # set the language fields from the selected item
@@ -48,6 +137,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                                self.languageslist.takeTopLevelItem (self.languageslist.indexOfTopLevelItem (item))
 
                        self.reset_language_fields ()
+                       # set the modified flag
+                       self.ismodified = True
 
        # add a language to the list of languages known
        def on_add_lang (self):
@@ -66,6 +157,9 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.languageslist.addTopLevelItem (langitem)
                self.reset_language_fields ()
 
+               # set the modified flag
+               self.ismodified = True
+
        # set the language fields from the selected item
        def set_language_fields (self):
                selitems = self.languageslist.selectedItems ()
@@ -98,6 +192,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
 
                selitem.setText (0, self.skillsettitle.text ())
                selitem.setText (1, self.skilldescription.toPlainText ())
+               # set the modified flag
+               self.ismodified = True
 
        # selecting a skill from the list event
        def on_select_skill (self):
@@ -129,6 +225,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                                self.skillslist.takeTopLevelItem (self.skillslist.indexOfTopLevelItem (item))
 
                        self.reset_skillset_fields ()
+                       # set the modified flag
+                       self.ismodified = True
 
        # add skill set button is clicked
        def on_add_skill (self):
@@ -144,6 +242,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                        )
                self.skillslist.addTopLevelItem (skillitem)
                self.reset_skillset_fields ()
+               # set the modified flag
+               self.ismodified = True
 
        # clear the skill set fields
        def reset_skillset_fields (self):
@@ -178,6 +278,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                selitem.setText (2, leavedatestr)
                selitem.setText (3, self.organization.text ())
                selitem.setText (4, self.additionalinfo.text ())
+               # set the modified flag
+               self.ismodified = True
 
        # delete professional history button is clicked
        def on_delete_profession (self):
@@ -194,6 +296,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                        for item in selitems:
                                self.professionlist.takeTopLevelItem (self.professionlist.indexOfTopLevelItem (item))
                        self.reset_profession_fields ()
+                       # set the modified flag
+                       self.ismodified = True
 
        # add professional history button is clicked
        def on_add_profession (self):
@@ -224,6 +328,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.professionlist.addTopLevelItem (professionitem)
 
                self.reset_profession_fields ()
+               # set the modified flag
+               self.ismodified = True
 
        # when selection of profession list is changed
        def on_select_profession (self):
@@ -279,6 +385,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                                for item in selitems:
                                        self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
                                self.reset_education_fields ()
+                               # set the modified flag
+                               self.ismodified = True
 
        # selection is changed
        def on_select_education (self):
@@ -303,6 +411,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                selitem.setText (3, self.university.text ())
                selitem.setText (4, self.grade.text ())
                selitem.setText (5, str (self.percentage.value ()))
+               # set the modified flag
+               self.ismodified = True
 
        # add educational qualification button
        def on_add_education (self):
@@ -321,6 +431,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.educationlist.addTopLevelItem (educationitem)
                # clear the fields
                self.reset_education_fields ()
+               # set the modified flag
+               self.ismodified = True
 
        # set fields in the education tab from current selected item
        def set_education_fields (self):