File open functionality implemented
authorHarishankar <v.harishankar@gmail.com>
Mon, 5 Dec 2011 16:15:14 +0000 (21:45 +0530)
committerHarishankar <v.harishankar@gmail.com>
Mon, 5 Dec 2011 16:15:14 +0000 (21:45 +0530)
Implemented file opening functionality. Also implemented
setting current file title in the title bar.

biacv_data.py
biacv_lang.py
biacv_mainwindow.py
biacv_mainwindow.ui
biacv_mainwindow_ui.py

index 010e664..1146102 100644 (file)
@@ -12,6 +12,10 @@ class BiaCVData:
        def save_data (self, filepath):
                json.dump (self.data, file (filepath, "w"), indent=4)
 
        def save_data (self, filepath):
                json.dump (self.data, file (filepath, "w"), indent=4)
 
+       # load the data from a file
+       def load_data (self, filepath):
+               self.data = json.load (file (filepath, "rb"))
+
        # set the document title
        def set_document_title (self, title):
                self.data["title"] = title
        # set the document title
        def set_document_title (self, title):
                self.data["title"] = title
index 11d19e2..a0c8f27 100644 (file)
@@ -9,4 +9,5 @@ CONFIRM = "Confirm"
 CONFIRM_DELETE = "Are you sure you wish to delete the selected item?"
 CONFIRM_DISCARD_SAVE = "There are unsaved changes in current document. Do you wish to discard all changes?"
 ERROR_DATE = "There is a problem with the date range selected."
 CONFIRM_DELETE = "Are you sure you wish to delete the selected item?"
 CONFIRM_DISCARD_SAVE = "There are unsaved changes in current document. Do you wish to discard all changes?"
 ERROR_DATE = "There is a problem with the date range selected."
-SAVE_TITLE = "Save File As"
\ No newline at end of file
+SAVE_TITLE = "Save File As"
+OPEN_TITLE = "Open File"
index cdb1305..4a98c2d 100644 (file)
@@ -12,6 +12,55 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.setupUi (self)
                self.currentfile = None
                self.ismodified = False
                self.setupUi (self)
                self.currentfile = None
                self.ismodified = False
+               self.setWindowTitle ("BiaCV - untitled")
+
+       # function to open a file
+       def on_file_open (self):
+               # if modified, confirm
+               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 no, then don't open the file
+                       if ans <> PyQt4.QtGui.QMessageBox.Yes:
+                               return
+
+               # open file dialog
+               openfilename = PyQt4.QtGui.QFileDialog.getOpenFileName (self, lang.OPEN_TITLE)
+               # if no open file name then return
+               if openfilename == "":
+                       return
+
+               # load the document data from open file name
+               docdata = data.BiaCVData ()
+               docdata.load_data (openfilename)
+
+               # set the title
+               self.title.setText (docdata.data["title"])
+
+               # set the personal information fields from document data
+               self.set_personal_info (docdata)
+
+               # set the educational qualifications
+               self.set_educational_qualifications (docdata)
+
+               # set the professional history
+               self.set_professional_history (docdata)
+
+               # set the career objectives
+               self.set_career_objectives (docdata)
+
+               # set the skills list
+               self.set_skillsets_info (docdata)
+
+               # set the additional information
+               self.set_additional_info (docdata)
+
+               # set the current document
+               self.currentfile = openfilename
+               self.ismodified = False
+
+               # set the window title
+               self.setWindowTitle ("BiaCV - " + self.currentfile)
 
        # function to save a file
        def on_file_save (self):
 
        # function to save a file
        def on_file_save (self):
@@ -21,15 +70,15 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
 
                # if no current file get file name from file save dialog
                if self.currentfile is None:
 
                # if no current file get file name from file save dialog
                if self.currentfile is None:
-                       self.currentfile = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
+                       savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
                                lang.SAVE_TITLE)
 
                                lang.SAVE_TITLE)
 
-                       if self.currentfile <> "":
+                       if savefilename <> "":
                                mydata = self.get_document_data ()
                                mydata.save_data (self.currentfile)
                                self.ismodified = False
                                mydata = self.get_document_data ()
                                mydata.save_data (self.currentfile)
                                self.ismodified = False
-                       else:
-                               self.currentfile = None
+                               self.currentfile = savefilename
+                               self.setWindowTitle ("BiaCV - " + self.currentfile)
                else:
                        mydata = self.get_document_data ()
                        mydata.save_data (self.currentfile)
                else:
                        mydata = self.get_document_data ()
                        mydata.save_data (self.currentfile)
@@ -156,32 +205,130 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.areacode.setText ("")
                self.unspecified.setChecked (True)
 
                self.areacode.setText ("")
                self.unspecified.setChecked (True)
 
+       # function to set personal information data in the GUI from document data
+       def set_personal_info (self, docdata):
+               self.nametitle.setEditText (docdata.data["nametitle"])
+               self.firstname.setText (docdata.data["firstname"])
+               self.lastname.setText (docdata.data["lastname"])
+               self.dateofbirth.setDate (PyQt4.QtCore.QDate.fromString (docdata.data["dateofbirth"], "dd MMM, yyyy"))
+               self.street.setText (docdata.data["street"])
+               self.area.setText (docdata.data["area"])
+               self.city.setText (docdata.data["city"])
+               self.countrycode_landline.setText (docdata.data["countrycode_landline"])
+               self.telephone.setText (docdata.data["landline"])
+               self.countrycode_mobile.setText (docdata.data["countrycode_mobile"])
+               self.mobilenumber.setText (docdata.data["mobile"])
+               self.email.setText (docdata.data["email"])
+               self.areacode.setText (docdata.data["areacode"])
+               if docdata.data["maritalstatus"] is True:
+                       self.married.setChecked (True)
+               elif docdata.data["maritalstatus"] is False:
+                       self.single.setChecked (True)
+               else:
+                       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 professional history in the GUI
        def reset_professional_history (self):
                self.reset_profession_fields ()
                self.professionlist.clear ()
 
+       # function to set the professional history in the GUI from the document data
+       def set_professional_history (self, docdata):
+               # reset the professional history
+               self.reset_professional_history ()
+
+               # add the professional history items to list
+               for item in docdata.data["professionalhistory"]:
+                       professionitem = PyQt4.QtGui.QTreeWidgetItem (
+                                       [
+                                               item["jobtitle"],
+                                               item["joindate"],
+                                               item["leavedate"],
+                                               item["organization"],
+                                               item["additionalinfo"]
+                                       ]
+                               )
+                       self.professionlist.addTopLevelItem (professionitem)
+
        # function to clear educational qualifications in the GUI
        def reset_educational_qualifications (self):
                self.reset_education_fields ()
                self.educationlist.clear ()
 
        # function to clear educational qualifications in the GUI
        def reset_educational_qualifications (self):
                self.reset_education_fields ()
                self.educationlist.clear ()
 
+       # function to set education qualifications in the GUI from document data
+       def set_educational_qualifications (self, docdata):
+               # reset the educational qualifications
+               self.reset_educational_qualifications ()
+
+               # add education items to list
+               for item in docdata.data["educationalqualifications"]:
+                       educationitem = PyQt4.QtGui.QTreeWidgetItem (
+                                       [
+                                               item["degree"],
+                                               item["graduation"],
+                                               item["institution"],
+                                               item["university"],
+                                               item["grade"],
+                                               str (item["percentage"])
+                                       ]
+                               )
+                       self.educationlist.addTopLevelItem (educationitem)
+
        # function to clear career objectives data in the GUI
        def reset_career_objectives (self):
                self.shorttermcareer.setPlainText ("")
                self.longtermgoals.setPlainText ("")
 
        # function to clear career objectives data in the GUI
        def reset_career_objectives (self):
                self.shorttermcareer.setPlainText ("")
                self.longtermgoals.setPlainText ("")
 
+       # function to set career objectives data in the GUI from document data
+       def set_career_objectives (self, docdata):
+               self.shorttermcareer.setPlainText (u'\n'.join (docdata.data["shorttermobjectives"]))
+               self.longtermgoals.setPlainText (u'\n'.join (docdata.data["longtermgoals"]))
+
        # function to clear skill sets data in the GUI
        def reset_skillsets_info (self):
                self.reset_skillset_fields ()
                self.skillslist.clear ()
 
        # function to clear skill sets data in the GUI
        def reset_skillsets_info (self):
                self.reset_skillset_fields ()
                self.skillslist.clear ()
 
+       # function to set the skill sets data in the GUI from document data
+       def set_skillsets_info (self, docdata):
+               # clear the skill sets information
+               self.reset_skillsets_info ()
+
+               for item in docdata.data["skillsets"]:
+                       skillitem = PyQt4.QtGui.QTreeWidgetItem (
+                                       [
+                                               item["skilltitle"],
+                                               item["skilldesc"]
+                                       ]
+                               )
+                       self.skillslist.addTopLevelItem (skillitem)
+
+
        # 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 additional information data in the GUI
        def reset_additional_info (self):
                self.reset_language_fields ()
                self.languageslist.clear ()
                self.additionalinformation.setPlainText ("")
 
+       # function to set additional information data in the GUI from the document data
+       def set_additional_info (self, docdata):
+               # clear the additional information
+               self.reset_additional_info ()
+
+               # set the languages list
+               for item in docdata.data["languagesknown"]:
+                       langitem = PyQt4.QtGui.QTreeWidgetItem (
+                                       [
+                                               item["language"],
+                                               str (item["canspeak"]),
+                                               str (item["canreadwrite"]),
+                                               str (item["isproficient"])
+                                       ]
+                               )
+                       self.languageslist.addTopLevelItem (langitem)
+
+               self.additionalinformation.setPlainText (docdata.data["additionalinformation"])
+
        # function to clear all the fields and reset them to defaults
        def new_document (self):
                # first clear the individual record fields in the tabs
        # function to clear all the fields and reset them to defaults
        def new_document (self):
                # first clear the individual record fields in the tabs
@@ -205,6 +352,9 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.currentfile = None
                self.ismodified = False
 
                self.currentfile = None
                self.ismodified = False
 
+               # set the window title
+               self.setWindowTitle ("BiaCV - untitled")
+
        # file new action is triggered
        def on_file_new (self):
                # if the previous document is modified
        # file new action is triggered
        def on_file_new (self):
                # if the previous document is modified
index bb93608..9670324 100644 (file)
     </hint>
    </hints>
   </connection>
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>action_Open</sender>
+   <signal>triggered()</signal>
+   <receiver>biacv_mainwindow</receiver>
+   <slot>on_file_open()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>-1</x>
+     <y>-1</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>364</x>
+     <y>248</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>on_add_education()</slot>
  </connections>
  <slots>
   <slot>on_add_education()</slot>
   <slot>on_document_modified()</slot>
   <slot>on_file_new()</slot>
   <slot>on_file_save()</slot>
   <slot>on_document_modified()</slot>
   <slot>on_file_new()</slot>
   <slot>on_file_save()</slot>
+  <slot>on_file_open()</slot>
  </slots>
 </ui>
  </slots>
 </ui>
index 7554acd..5b34a9b 100644 (file)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'biacv_mainwindow.ui'
 #
 
 # Form implementation generated from reading ui file 'biacv_mainwindow.ui'
 #
-# Created: Mon Dec  5 10:38:07 2011
+# Created: Mon Dec  5 20:12:17 2011
 #      by: PyQt4 UI code generator 4.8.6
 #
 # WARNING! All changes made in this file will be lost!
 #      by: PyQt4 UI code generator 4.8.6
 #
 # WARNING! All changes made in this file will be lost!
@@ -608,6 +608,7 @@ class Ui_biacv_mainwindow(object):
         QtCore.QObject.connect(self.additionalinformation, QtCore.SIGNAL(_fromUtf8("textChanged()")), biacv_mainwindow.on_document_modified)
         QtCore.QObject.connect(self.action_New, QtCore.SIGNAL(_fromUtf8("triggered()")), biacv_mainwindow.on_file_new)
         QtCore.QObject.connect(self.action_Save, QtCore.SIGNAL(_fromUtf8("triggered()")), biacv_mainwindow.on_file_save)
         QtCore.QObject.connect(self.additionalinformation, QtCore.SIGNAL(_fromUtf8("textChanged()")), biacv_mainwindow.on_document_modified)
         QtCore.QObject.connect(self.action_New, QtCore.SIGNAL(_fromUtf8("triggered()")), biacv_mainwindow.on_file_new)
         QtCore.QObject.connect(self.action_Save, QtCore.SIGNAL(_fromUtf8("triggered()")), biacv_mainwindow.on_file_save)
+        QtCore.QObject.connect(self.action_Open, QtCore.SIGNAL(_fromUtf8("triggered()")), biacv_mainwindow.on_file_open)
         QtCore.QMetaObject.connectSlotsByName(biacv_mainwindow)
 
     def retranslateUi(self, biacv_mainwindow):
         QtCore.QMetaObject.connectSlotsByName(biacv_mainwindow)
 
     def retranslateUi(self, biacv_mainwindow):