File save function implemented
authorHarishankar <v.harishankar@gmail.com>
Mon, 5 Dec 2011 11:46:11 +0000 (17:16 +0530)
committerHarishankar <v.harishankar@gmail.com>
Mon, 5 Dec 2011 11:46:11 +0000 (17:16 +0530)
Implemented file-saving in JSON format.

.gitignore
biacv_data.py [new file with mode: 0644]
biacv_lang.py
biacv_mainwindow.py
biacv_mainwindow.ui
biacv_mainwindow_ui.py

index 0d20b64..70bcf99 100644 (file)
@@ -1 +1,2 @@
 *.pyc
+test*
diff --git a/biacv_data.py b/biacv_data.py
new file mode 100644 (file)
index 0000000..010e664
--- /dev/null
@@ -0,0 +1,58 @@
+# class to save/restore data from a BiaCV file and to export BiaCV to different
+# formats
+
+import json
+
+class BiaCVData:
+       def __init__ (self):
+               # initialize the data to an empty dictionary
+               self.data = {}
+
+       # save the data into a file
+       def save_data (self, filepath):
+               json.dump (self.data, file (filepath, "w"), indent=4)
+
+       # set the document title
+       def set_document_title (self, title):
+               self.data["title"] = title
+
+       # set personal information from gui
+       def set_personal_info (self, nametitle, firstname, lastname, dateofbirth,
+                       street, area, city, areacode, countrycode_landline, landline,
+                       countrycode_mobile, mobile, email, maritalstatus):
+               self.data["nametitle"] = nametitle
+               self.data["firstname"] = firstname
+               self.data["lastname"] = lastname
+               self.data["dateofbirth"] = dateofbirth
+               self.data["street"] = street
+               self.data["area"] = area
+               self.data["city"] = city
+               self.data["areacode"] = areacode
+               self.data["countrycode_landline"] = countrycode_landline
+               self.data["landline"] = landline
+               self.data["countrycode_mobile"] = countrycode_mobile
+               self.data["mobile"] = mobile
+               self.data["email"] = email
+               self.data["maritalstatus"] = maritalstatus
+
+       # set the educational qualifications
+       def set_educational_qualifications (self, listofqualifications):
+               self.data["educationalqualifications"] = listofqualifications
+
+       # set the professional history
+       def set_professional_history (self, listofprofessionalhistory):
+               self.data["professionalhistory"] = listofprofessionalhistory
+
+       # set the career objectives
+       def set_career_objectives (self, listofshortterm, listoflongterm):
+               self.data["shorttermobjectives"] = listofshortterm
+               self.data["longtermgoals"] = listoflongterm
+
+       # set the skill sets
+       def set_skillsets (self, listofskills):
+               self.data["skillsets"] = listofskills
+
+       # set the additional information
+       def set_additional_information (self, listoflanguages, additionalinformation):
+               self.data["languagesknown"] = listoflanguages
+               self.data["additionalinformation"] = additionalinformation
index 5f85c28..11d19e2 100644 (file)
@@ -9,3 +9,4 @@ 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."
+SAVE_TITLE = "Save File As"
\ No newline at end of file
index 7d577da..192ef4c 100644 (file)
@@ -4,6 +4,7 @@
 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):
@@ -12,6 +13,130 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                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 ("")
index 844088e..bb93608 100644 (file)
     </item>
     <item row="1" column="0" colspan="2">
      <widget class="QTabWidget" name="pages">
+      <property name="autoFillBackground">
+       <bool>false</bool>
+      </property>
       <property name="tabShape">
        <enum>QTabWidget::Rounded</enum>
       </property>
       <property name="currentIndex">
        <number>0</number>
       </property>
+      <property name="usesScrollButtons">
+       <bool>true</bool>
+      </property>
       <property name="documentMode">
        <bool>true</bool>
       </property>
      <addaction name="actionOpenDocument_ODT"/>
     </widget>
     <addaction name="action_New"/>
-    <addaction name="action_Save"/>
+    <addaction name="action_Open"/>
     <addaction name="separator"/>
-    <addaction name="action_Save_2"/>
+    <addaction name="action_Save"/>
     <addaction name="actionSave_As"/>
     <addaction name="menu_Export"/>
     <addaction name="separator"/>
     <string>Create a new file</string>
    </property>
   </action>
-  <action name="action_Save">
+  <action name="action_Open">
    <property name="text">
     <string>&amp;Open...</string>
    </property>
     <string>Open an existing file</string>
    </property>
   </action>
-  <action name="action_Save_2">
+  <action name="action_Save">
    <property name="text">
     <string>&amp;Save</string>
    </property>
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>action_Save</sender>
+   <signal>triggered()</signal>
+   <receiver>biacv_mainwindow</receiver>
+   <slot>on_file_save()</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>
   <slot>on_update_lang()</slot>
   <slot>on_document_modified()</slot>
   <slot>on_file_new()</slot>
+  <slot>on_file_save()</slot>
  </slots>
 </ui>
index 0d88db2..7554acd 100644 (file)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'biacv_mainwindow.ui'
 #
-# Created: Sun Dec  4 16:35:10 2011
+# Created: Mon Dec  5 10:38:07 2011
 #      by: PyQt4 UI code generator 4.8.6
 #
 # WARNING! All changes made in this file will be lost!
@@ -31,7 +31,9 @@ class Ui_biacv_mainwindow(object):
         self.title.setObjectName(_fromUtf8("title"))
         self.gridLayout_2.addWidget(self.title, 0, 1, 1, 1)
         self.pages = QtGui.QTabWidget(self.centralwidget)
+        self.pages.setAutoFillBackground(False)
         self.pages.setTabShape(QtGui.QTabWidget.Rounded)
+        self.pages.setUsesScrollButtons(True)
         self.pages.setDocumentMode(True)
         self.pages.setObjectName(_fromUtf8("pages"))
         self.tab = QtGui.QWidget()
@@ -519,15 +521,15 @@ class Ui_biacv_mainwindow(object):
         self.action_New.setText(QtGui.QApplication.translate("biacv_mainwindow", "&New", None, QtGui.QApplication.UnicodeUTF8))
         self.action_New.setStatusTip(QtGui.QApplication.translate("biacv_mainwindow", "Create a new file", None, QtGui.QApplication.UnicodeUTF8))
         self.action_New.setObjectName(_fromUtf8("action_New"))
+        self.action_Open = QtGui.QAction(biacv_mainwindow)
+        self.action_Open.setText(QtGui.QApplication.translate("biacv_mainwindow", "&Open...", None, QtGui.QApplication.UnicodeUTF8))
+        self.action_Open.setStatusTip(QtGui.QApplication.translate("biacv_mainwindow", "Open an existing file", None, QtGui.QApplication.UnicodeUTF8))
+        self.action_Open.setObjectName(_fromUtf8("action_Open"))
         self.action_Save = QtGui.QAction(biacv_mainwindow)
-        self.action_Save.setText(QtGui.QApplication.translate("biacv_mainwindow", "&Open...", None, QtGui.QApplication.UnicodeUTF8))
-        self.action_Save.setStatusTip(QtGui.QApplication.translate("biacv_mainwindow", "Open an existing file", None, QtGui.QApplication.UnicodeUTF8))
+        self.action_Save.setText(QtGui.QApplication.translate("biacv_mainwindow", "&Save", None, QtGui.QApplication.UnicodeUTF8))
+        self.action_Save.setStatusTip(QtGui.QApplication.translate("biacv_mainwindow", "Save current file", None, QtGui.QApplication.UnicodeUTF8))
+        self.action_Save.setShortcut(QtGui.QApplication.translate("biacv_mainwindow", "Ctrl+S", None, QtGui.QApplication.UnicodeUTF8))
         self.action_Save.setObjectName(_fromUtf8("action_Save"))
-        self.action_Save_2 = QtGui.QAction(biacv_mainwindow)
-        self.action_Save_2.setText(QtGui.QApplication.translate("biacv_mainwindow", "&Save", None, QtGui.QApplication.UnicodeUTF8))
-        self.action_Save_2.setStatusTip(QtGui.QApplication.translate("biacv_mainwindow", "Save current file", None, QtGui.QApplication.UnicodeUTF8))
-        self.action_Save_2.setShortcut(QtGui.QApplication.translate("biacv_mainwindow", "Ctrl+S", None, QtGui.QApplication.UnicodeUTF8))
-        self.action_Save_2.setObjectName(_fromUtf8("action_Save_2"))
         self.actionSave_As = QtGui.QAction(biacv_mainwindow)
         self.actionSave_As.setText(QtGui.QApplication.translate("biacv_mainwindow", "Save &As...", None, QtGui.QApplication.UnicodeUTF8))
         self.actionSave_As.setStatusTip(QtGui.QApplication.translate("biacv_mainwindow", "Save as a different file", None, QtGui.QApplication.UnicodeUTF8))
@@ -550,9 +552,9 @@ class Ui_biacv_mainwindow(object):
         self.menu_Export.addAction(self.action_HTML)
         self.menu_Export.addAction(self.actionOpenDocument_ODT)
         self.menu_File.addAction(self.action_New)
-        self.menu_File.addAction(self.action_Save)
+        self.menu_File.addAction(self.action_Open)
         self.menu_File.addSeparator()
-        self.menu_File.addAction(self.action_Save_2)
+        self.menu_File.addAction(self.action_Save)
         self.menu_File.addAction(self.actionSave_As)
         self.menu_File.addAction(self.menu_Export.menuAction())
         self.menu_File.addSeparator()
@@ -605,6 +607,7 @@ class Ui_biacv_mainwindow(object):
         QtCore.QObject.connect(self.longtermgoals, QtCore.SIGNAL(_fromUtf8("textChanged()")), biacv_mainwindow.on_document_modified)
         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.QMetaObject.connectSlotsByName(biacv_mainwindow)
 
     def retranslateUi(self, biacv_mainwindow):