Implemented document save status flag
[biacv.git] / biacv_mainwindow.py
index 8c3b132..1bd6563 100644 (file)
@@ -1,36 +1,71 @@
+# BiaCV
 # class for main window
 
 import PyQt4
 import biacv_mainwindow_ui as bui
+import biacv_lang as lang
 
 class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
        def __init__ (self):
                PyQt4.QtGui.QMainWindow.__init__ (self)
                self.setupUi (self)
                self.currentfile = None
+               self.ismodified = False
+
+       # when the document is modified
+       def on_document_modified (self):
+               # set the document modified flag
+               self.ismodified = True
+               print "True"
+
+       # update a language in the list of languages
+       def on_update_lang (self):
+               # get the selected language
+               selitems = self.languageslist.selectedItems ()
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
+                       return
+               # check if the language string is not empty
+               if self.language.text () == "":
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
+                       return
+               selitem = selitems[0]
+               selitem.setText (0, self.language.text ())
+               selitem.setText (1, str (self.canspeak.isChecked ()))
+               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
+               self.set_language_fields ()
 
        # delete a language from the list of languages known
        def on_delete_lang (self):
                # get selected language
                selitems = self.languageslist.selectedItems ()
                if selitems == []:
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_REQ_MISSING)
                        return
                # confirm
-               ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
-                       "Are you sure you wish to delete the selected item?",
+               ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
                        PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
                if ans == PyQt4.QtGui.QMessageBox.Yes:
                        for item in selitems:
                                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):
                # check if the language is set
                if self.language.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required field is missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
                        return
                langitem = PyQt4.QtGui.QTreeWidgetItem (
                                [
@@ -43,6 +78,20 @@ 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 ()
+               if selitems == []:
+                       return
+               selitem = selitems[0]
+               self.language.setText (selitem.text (0))
+               self.canspeak.setChecked (selitem.text (1) == "True")
+               self.canreadwrite.setChecked (selitem.text(2) == "True")
+               self.isproficient.setChecked (selitem.text(3) == "True")
+
        # reset the language fields
        def reset_language_fields (self):
                self.language.setText ("")
@@ -55,15 +104,17 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                # get the selected item
                selitems = self.skillslist.selectedItems ()
                if selitems == []:
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
                        return
                if self.skillsettitle.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
                        return
                selitem = selitems[0]
 
                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):
@@ -84,11 +135,10 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                # get the selected items
                selitems = self.skillslist.selectedItems ()
                if selitems == []:
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
                        return
                # confirm
-               ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
-                       "Are you sure you wish to delete the selected item?",
+               ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
                        PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
                # answer is yes
                if ans == PyQt4.QtGui.QMessageBox.Yes:
@@ -96,12 +146,14 @@ 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):
                # if the skill title is blank
                if self.skillsettitle.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required field is missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
                        return
                skillitem = PyQt4.QtGui.QTreeWidgetItem (
                                [
@@ -111,6 +163,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):
@@ -122,12 +176,12 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                # get the selected item
                selitems = self.professionlist.selectedItems ()
                if selitems == []:
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
                        return
                selitem = selitems[0]
                # if designation is not set
                if self.designation.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
                        return
                # if currently employed in that position, leaving date is to be disabled
                # and set to "current"
@@ -136,8 +190,7 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                else:
                        # if the leaving date is < join date
                        if self.leavedate.date () < self.joindate.date ():
-                               PyQt4.QtGui.QMessageBox.critical (self, "Cannot add",
-                                       "Leaving date cannot be earlier than join date.")
+                               PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
                                return
                        leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
 
@@ -146,28 +199,31 @@ 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):
                # get the selected items
                selitems = self.professionlist.selectedItems ()
                if selitems == []:
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No item selected.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
                        return
                # confirm deletion
-               ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
-                       "Are you sure you wish to delete the selected item?",
+               ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
                        PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
                # if confirmed
                if ans == PyQt4.QtGui.QMessageBox.Yes:
                        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):
                if self.designation.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required field is missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
                        return
                # if currently employed in that position, leaving date is to be disabled
                # and set to "current"
@@ -176,8 +232,7 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                else:
                        # if the leaving date is < join date
                        if self.leavedate.date () < self.joindate.date ():
-                               PyQt4.QtGui.QMessageBox.critical (self, "Cannot add",
-                                       "Leaving date cannot be earlier than join date.")
+                               PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
                                return
                        leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
 
@@ -194,6 +249,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):
@@ -239,17 +296,18 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                selitems = self.educationlist.selectedItems ()
                # if no items are selected
                if selitems == []:
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
                # delete the items after confirmation
                else:
-                       ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
-                               "Are you sure you wish to delete selected item?",
+                       ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
                                PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
                        if ans == PyQt4.QtGui.QMessageBox.Yes:
                                # remove the item selected
                                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):
@@ -260,11 +318,11 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                selitems = self.educationlist.selectedItems ()
                # if no item is selected
                if selitems == []:
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
                        return
                # if the qualification title is not set
                if self.degree_name.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
                        return
                selitem = selitems[0]
 
@@ -274,12 +332,14 @@ 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):
                # check if the qualification title is set
                if self.degree_name.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required fields is missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
                        return
                educationitem = PyQt4.QtGui.QTreeWidgetItem ([
                        self.degree_name.text (),
@@ -292,6 +352,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):