X-Git-Url: https://harishankar.org/repos/?a=blobdiff_plain;f=biacv_mainwindow.py;h=192ef4c2c4fb2c53073a4e4fd109981c54066b4d;hb=2ea1c764b6ce60b55bb3f44e3f8f121933b66d29;hp=99e6b7c3ad5b7044becdb55415ae2d16e19ee2a3;hpb=d9e350c83c69e02272f44c8ea7cb4e329225e758;p=biacv.git diff --git a/biacv_mainwindow.py b/biacv_mainwindow.py index 99e6b7c..192ef4c 100644 --- a/biacv_mainwindow.py +++ b/biacv_mainwindow.py @@ -1,24 +1,348 @@ +# BiaCV # class for main window import PyQt4 import biacv_mainwindow_ui as bui +import biacv_lang as lang +import biacv_data as data 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 + + # function to save a file + def on_file_save (self): + # only save modified file + if self.ismodified is False: + return + + # if no current file get file name from file save dialog + if self.currentfile is None: + self.currentfile = PyQt4.QtGui.QFileDialog.getSaveFileName (self, + lang.SAVE_TITLE) + + if self.currentfile is not None: + mydata = self.get_document_data () + mydata.save_data (self.currentfile) + self.ismodified = False + else: + mydata = self.get_document_data () + mydata.save_data (self.currentfile) + self.ismodified = False + + # function to set document data from the GUI + def get_document_data (self): + docdata = data.BiaCVData () + + # set the document title + docdata.set_document_title (unicode (self.title.text (), "utf-8")) + + # get the marital status string from check box + if self.married.isChecked (): + maritalstatus = True + elif self.single.isChecked (): + maritalstatus = False + else: + maritalstatus = None + + docdata.set_personal_info ( + unicode (self.nametitle.lineEdit ().text (), "utf-8"), + unicode (self.firstname.text (), "utf-8"), + unicode (self.lastname.text (), "utf-8"), + unicode (self.dateofbirth.date().toString ("dd MMM, yyyy"), "utf-8"), + unicode (self.street.text (), "utf-8"), + unicode (self.area.text (), "utf-8"), + unicode (self.city.text (), "utf-8"), + unicode (self.areacode.text (), "utf-8"), + unicode (self.countrycode_landline.text (), "utf-8"), + unicode (self.telephone.text (), "utf-8"), + unicode (self.countrycode_mobile.text (), "utf-8"), + unicode (self.mobilenumber.text (), "utf-8"), + unicode (self.email.text (), "utf-8"), + maritalstatus + ) + # get the list of educational qualifications from the treewidget + education = [] + i = 0 + while i < self.educationlist.topLevelItemCount (): + curitem = self.educationlist.topLevelItem (i) + curdict = {} + curdict["degree"] = unicode (curitem.text (0), "utf-8") + curdict["graduation"] = unicode (curitem.text (1), "utf-8") + curdict["institution"] = unicode (curitem.text (2), "utf-8") + curdict["university"] = unicode (curitem.text (3), "utf-8") + curdict["grade"] = unicode (curitem.text (4), "utf-8") + curdict["percentage"] = float (curitem.text (5)) + education.append (curdict) + i += 1 + + # set the educational qualifications + docdata.set_educational_qualifications (education) + + # get the list of professional history from the treewidget + professional = [] + i = 0 + while i < self.professionlist.topLevelItemCount (): + curitem = self.professionlist.topLevelItem (i) + curdict = {} + curdict["jobtitle"] = unicode (curitem.text (0), "utf-8") + curdict["joindate"] = unicode (curitem.text (1), "utf-8") + curdict["leavedate"] = unicode (curitem.text (2), "utf-8") + curdict["organization"] = unicode (curitem.text (3), "utf-8") + curdict["additionalinfo"] = unicode (curitem.text (4), "utf-8") + professional.append (curdict) + i += 1 + + # set the professional qualifications + docdata.set_professional_history (professional) + + # set the career objectives + shorttermobjectives = unicode (self.shorttermcareer.toPlainText (), "utf-8").splitlines () + longtermgoals = unicode (self.longtermgoals.toPlainText (), "utf-8").splitlines () + + docdata.set_career_objectives (shorttermobjectives, longtermgoals) + + # set the skill sets + skills = [] + i = 0 + while i < self.skillslist.topLevelItemCount (): + curitem = self.skillslist.topLevelItem (i) + curdict = {} + curdict["skilltitle"] = unicode (curitem.text (0), "utf-8") + curdict["skilldesc"] = unicode (curitem.text (1), "utf-8") + skills.append (curdict) + i += 1 + # set the list of skills + docdata.set_skillsets (skills) + + # get the list of languages + langsknown = [] + i = 0 + while i < self.languageslist.topLevelItemCount (): + curitem = self.languageslist.topLevelItem (i) + curdict = {} + curdict["language"] = unicode (curitem.text (0), "utf-8") + curdict["canspeak" ] = (curitem.text (1) == "True") + curdict["canreadwrite"] = (curitem.text (2) == "True") + curdict["isproficient"] = (curitem.text (3) == "True") + langsknown.append (curdict) + i += 1 + + additionalinformation = unicode (self.additionalinformation.toPlainText (), "utf-8") + + docdata.set_additional_information (langsknown, additionalinformation) + + return docdata + + # 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): + # 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, lang.ERROR_DELETE, lang.ERROR_REQ_MISSING) + return + # confirm + 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, lang.ERROR_ADD, lang.ERROR_REQ_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 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 ("") + 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, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION) + return + if self.skillsettitle.text () == "": + 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): + 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.") + 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: @@ -26,12 +350,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 ( [ @@ -41,6 +367,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): @@ -52,12 +380,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" @@ -66,8 +394,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") @@ -76,28 +403,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" @@ -106,8 +436,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") @@ -124,6 +453,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): @@ -169,17 +500,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): @@ -190,11 +522,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] @@ -204,12 +536,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 (), @@ -222,6 +556,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):