Update language in list
[biacv.git] / biacv_mainwindow.py
index 3133477..feaa8d3 100644 (file)
@@ -1,3 +1,4 @@
+# BiaCV
 # class for main window
 
 import PyQt4
@@ -7,18 +8,345 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
        def __init__ (self):
                PyQt4.QtGui.QMainWindow.__init__ (self)
                self.setupUi (self)
+               self.currentfile = None
 
+       # 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, "Cannot update", "No item selected.")
+                       return
+               # check if the language string is not empty
+               if self.language.text () == "":
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is 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 ()))
+
+       # 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.")
+                       return
+               # confirm
+               ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
+                       "Are you sure you wish to delete the selected item?",
+                       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 ()
+
+       # 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.")
+                       return
+               langitem = PyQt4.QtGui.QTreeWidgetItem (
+                               [
+                                       self.language.text (),
+                                       str (self.canspeak.isChecked ()),
+                                       str (self.canreadwrite.isChecked ()),
+                                       str (self.isproficient.isChecked ())
+                               ]
+                       )
+               self.languageslist.addTopLevelItem (langitem)
+               self.reset_language_fields ()
+
+       # 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 ("")
+               self.canspeak.setChecked (True)
+               self.canreadwrite.setChecked (False)
+               self.isproficient.setChecked (False)
+
+       # update the skill set button event
+       def on_update_skill (self):
+               # get the selected item
+               selitems = self.skillslist.selectedItems ()
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected.")
+                       return
+               if self.skillsettitle.text () == "":
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
+                       return
+               selitem = selitems[0]
+
+               selitem.setText (0, self.skillsettitle.text ())
+               selitem.setText (1, self.skilldescription.toPlainText ())
+
+       # selecting a skill from the list event
+       def on_select_skill (self):
+               self.set_skill_fields ()
+
+       # set the skill fields from the selected skill from the list
+       def set_skill_fields (self):
+               # get the selected items
+               selitems = self.skillslist.selectedItems ()
+               if selitems == []:
+                       return
+               selitem = selitems[0]
+               self.skillsettitle.setText (selitem.text (0))
+               self.skilldescription.setPlainText (selitem.text (1))
+
+       # delete skill set button is clicked
+       def on_delete_skill (self):
+               # get the selected items
+               selitems = self.skillslist.selectedItems ()
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
+                       return
+               # confirm
+               ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
+                       "Are you sure you wish to delete the selected item?",
+                       PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
+               # answer is yes
+               if ans == PyQt4.QtGui.QMessageBox.Yes:
+                       for item in selitems:
+                               self.skillslist.takeTopLevelItem (self.skillslist.indexOfTopLevelItem (item))
+
+                       self.reset_skillset_fields ()
+
+       # 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.")
+                       return
+               skillitem = PyQt4.QtGui.QTreeWidgetItem (
+                               [
+                               self.skillsettitle.text (),
+                               self.skilldescription.toPlainText ()
+                               ]
+                       )
+               self.skillslist.addTopLevelItem (skillitem)
+               self.reset_skillset_fields ()
+
+       # clear the skill set fields
+       def reset_skillset_fields (self):
+               self.skillsettitle.setText ("")
+               self.skilldescription.setPlainText ("")
+
+       # update professional history button is clicked
+       def on_update_profession (self):
+               # get the selected item
+               selitems = self.professionlist.selectedItems ()
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected.")
+                       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.")
+                       return
+               # if currently employed in that position, leaving date is to be disabled
+               # and set to "current"
+               if self.currentemployment.isChecked ():
+                       leavedatestr = "current"
+               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.")
+                               return
+                       leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
+
+               selitem.setText (0, self.designation.text ())
+               selitem.setText (1, self.joindate.date ().toString ("dd MMM, yyyy"))
+               selitem.setText (2, leavedatestr)
+               selitem.setText (3, self.organization.text ())
+               selitem.setText (4, self.additionalinfo.text ())
+
+       # 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.")
+                       return
+               # confirm deletion
+               ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
+                       "Are you sure you wish to delete the selected item?",
+                       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 ()
+
+       # 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.")
+                       return
+               # if currently employed in that position, leaving date is to be disabled
+               # and set to "current"
+               if self.currentemployment.isChecked ():
+                       leavedatestr = "current"
+               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.")
+                               return
+                       leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
+
+               professionitem = PyQt4.QtGui.QTreeWidgetItem (
+                       [
+                               self.designation.text (),
+                               self.joindate.date ().toString ("dd MMM, yyyy"),
+                               leavedatestr,
+                               self.organization.text (),
+                               self.additionalinfo.text ()
+                       ]
+                       )
+
+               self.professionlist.addTopLevelItem (professionitem)
+
+               self.reset_profession_fields ()
+
+       # when selection of profession list is changed
+       def on_select_profession (self):
+               self.set_profession_fields ()
+
+       # set the profession fields from the selected item in profession list
+       def set_profession_fields (self):
+               selitems = self.professionlist.selectedItems ()
+               if selitems == []:
+                       return
+               selitem = selitems[0]
+               self.designation.setText (selitem.text (0))
+               self.joindate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "dd MMM, yyyy"))
+               if selitem.text (2) == "current":
+                       self.leavedate.setEnabled (False)
+                       self.currentemployment.setChecked (True)
+               else:
+                       self.leavedate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text (2), "dd MMM, yyyy"))
+                       self.leavedate.setEnabled (True)
+                       self.currentemployment.setChecked (False)
+
+               self.organization.setText (selitem.text (3))
+               self.additionalinfo.setText (selitem.text (4))
+
+       def reset_profession_fields (self):
+               self.designation.setText ("")
+               self.joindate.setDate (PyQt4.QtCore.QDate (2000, 1, 1))
+               self.leavedate.setDate (PyQt4.QtCore.QDate (2003, 1, 1))
+               self.currentemployment.setChecked (False)
+               self.organization.setText ("")
+               self.additionalinfo.setText ("")
+
+       # current employment check box is changed
+       def on_change_currentemployment (self, val):
+               if val == True:
+                       self.leavedate.setEnabled (False)
+               else:
+                       self.leavedate.setEnabled (True)
+
+       # delete educational qualification
+       def on_delete_education (self):
+               # get the selected items in the education list
+               selitems = self.educationlist.selectedItems ()
+               # if no items are selected
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
+               # delete the items after confirmation
+               else:
+                       ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
+                               "Are you sure you wish to delete selected item?",
+                               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 ()
+
+       # selection is changed
+       def on_select_education (self):
+               self.set_education_fields ()
+
+       # update educational qualification button
+       def on_update_education (self):
+               selitems = self.educationlist.selectedItems ()
+               # if no item is selected
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected")
+                       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.")
+                       return
+               selitem = selitems[0]
+
+               selitem.setText (0, self.degree_name.text ())
+               selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
+               selitem.setText (2, self.institution.text ())
+               selitem.setText (3, self.university.text ())
+               selitem.setText (4, self.grade.text ())
+               selitem.setText (5, str (self.percentage.value ()))
+
+       # 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", "Some required fields are missing.")
-               else:
-                       educationitem = PyQt4.QtGui.QTreeWidgetItem ([
-                                       self.degree_name.text (),
-                                       self.yearofpassing.date ().toString ("MMM, yyyy"),
-                                       self.institution.text (),
-                                       self.university.text (),
-                                       self.grade.text (),
-                                       str (self.percentage.value ())
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required fields is missing.")
+                       return
+               educationitem = PyQt4.QtGui.QTreeWidgetItem ([
+                       self.degree_name.text (),
+                       self.yearofpassing.date ().toString ("MMM, yyyy"),
+                       self.institution.text (),
+                       self.university.text (),
+                       self.grade.text (),
+                       str (self.percentage.value ())
                        ])
-                       self.educationlist.addTopLevelItem (educationitem)
\ No newline at end of file
+               self.educationlist.addTopLevelItem (educationitem)
+               # clear the fields
+               self.reset_education_fields ()
+
+       # set fields in the education tab from current selected item
+       def set_education_fields (self):
+               selitems = self.educationlist.selectedItems ()
+               if selitems == []:
+                       return
+               selitem = selitems[0]
+               # set the fields to the data in the selected item in the list
+               self.degree_name.setText (selitem.text (0))
+               self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
+               self.institution.setText (selitem.text (2))
+               self.university.setText (selitem.text (3))
+               self.grade.setText (selitem.text(4))
+               self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
+
+       # reset fields in the education tab
+       def reset_education_fields (self):
+               self.degree_name.setText ("")
+               self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
+               self.institution.setText ("")
+               self.university.setText ("")
+               self.grade.setText ("")
+               self.percentage.setValue (50.0)
+