Changes to templates to include e-mail as a link
[biacv.git] / biacv_mainwindow.py
index 4a98c2d..ec74b82 100644 (file)
@@ -2,18 +2,72 @@
 # class for main window
 
 import PyQt4
+import sys
+
 import biacv_mainwindow_ui as bui
 import biacv_lang as lang
 import biacv_data as data
+import biacv_exporter as exporter
 
 class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
        def __init__ (self):
                PyQt4.QtGui.QMainWindow.__init__ (self)
+               self.show ()
                self.setupUi (self)
                self.currentfile = None
                self.ismodified = False
                self.setWindowTitle ("BiaCV - untitled")
 
+       # on window closing
+       def closeEvent (self, event):
+               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)
+                       # ignore event if not confirmed
+                       if ans <> PyQt4.QtGui.QMessageBox.Yes:
+                               event.ignore ()
+
+       # on help about dialog box
+       def on_help_about (self):
+               PyQt4.QtGui.QMessageBox.about (self, lang.ABOUT_TITLE, lang.ABOUT_TEXT)
+
+       # on file exit
+       def on_exit (self):
+               # call the close event
+               self.close()
+
+       # on file export - export current document to any external format based on
+       # a template
+       def on_file_export (self):
+               # get the template directory
+               templatedir = PyQt4.QtGui.QFileDialog.getExistingDirectory (self,
+                                               lang.OPEN_TEMPLATE_TITLE)
+               if templatedir == "":
+                       return
+
+               # create a new exporter object
+               exp = exporter.BiaCVExporter ()
+
+               # set the document data
+               exp.set_data (self.get_document_data ().data)
+
+               # set the template directory
+               exp.set_template_directory (unicode (templatedir.toUtf8(), "utf-8"))
+
+               # get the output file path
+               outputfile = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
+                       exp.exporter_name, filter=exp.export_filter)
+
+               if outputfile == "":
+                       return
+
+
+               # set the output file
+               exp.set_output (unicode (outputfile.toUtf8(), "utf-8"))
+
+               # carry out the export function
+               exp.export ()
+
        # function to open a file
        def on_file_open (self):
                # if modified, confirm
@@ -25,7 +79,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                                return
 
                # open file dialog
-               openfilename = PyQt4.QtGui.QFileDialog.getOpenFileName (self, lang.OPEN_TITLE)
+               openfilename = PyQt4.QtGui.QFileDialog.getOpenFileName (self, lang.OPEN_TITLE,
+                               filter = lang.BIACV_FILE_FILTER)
                # if no open file name then return
                if openfilename == "":
                        return
@@ -40,6 +95,9 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                # set the personal information fields from document data
                self.set_personal_info (docdata)
 
+               # set the profile highlights
+               self.set_profile_highlights (docdata)
+
                # set the educational qualifications
                self.set_educational_qualifications (docdata)
 
@@ -62,6 +120,19 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                # set the window title
                self.setWindowTitle ("BiaCV - " + self.currentfile)
 
+       # function to save a file as a new document
+       def on_file_save_as (self):
+               savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
+                       lang.SAVE_TITLE, filter=lang.BIACV_FILE_FILTER)
+
+               # if save file name is not none
+               if savefilename <> "":
+                       mydata = self.get_document_data ()
+                       mydata.save_data (savefilename)
+                       self.ismodified = False
+                       self.currentfile = savefilename
+                       self.setWindowTitle ("BiaCV - " + self.currentfile)
+
        # function to save a file
        def on_file_save (self):
                # only save modified file
@@ -71,11 +142,11 @@ 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:
                        savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
-                               lang.SAVE_TITLE)
+                               lang.SAVE_TITLE, filter=lang.BIACV_FILE_FILTER)
 
                        if savefilename <> "":
                                mydata = self.get_document_data ()
-                               mydata.save_data (self.currentfile)
+                               mydata.save_data (savefilename)
                                self.ismodified = False
                                self.currentfile = savefilename
                                self.setWindowTitle ("BiaCV - " + self.currentfile)
@@ -108,6 +179,7 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                                unicode (self.area.text ().toUtf8 (), "utf-8"),
                                unicode (self.city.text ().toUtf8 (), "utf-8"),
                                unicode (self.areacode.text ().toUtf8 (), "utf-8"),
+                               unicode (self.country.text ().toUtf8 (), "utf-8"),
                                unicode (self.countrycode_landline.text ().toUtf8 (), "utf-8"),
                                unicode (self.telephone.text ().toUtf8 (), "utf-8"),
                                unicode (self.countrycode_mobile.text ().toUtf8 (), "utf-8"),
@@ -115,6 +187,11 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                                unicode (self.email.text ().toUtf8 (), "utf-8"),
                                maritalstatus
                        )
+
+               # set the profile highlights
+               profile_highlights = unicode (self.profile.toPlainText ().toUtf8 (), "utf-8").splitlines ()
+               docdata.set_profile (profile_highlights)
+
                # get the list of educational qualifications from the treewidget
                education = []
                i = 0
@@ -204,6 +281,15 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.email.setText ("")
                self.areacode.setText ("")
                self.unspecified.setChecked (True)
+               self.country.setText ("")
+
+       # function to set the profile highlights in the GUI from document data
+       def set_profile_highlights (self, docdata):
+               self.profile.setPlainText (u'\n'.join (docdata.data["profile"]))
+
+       # function to reset profile highlights data in GUI
+       def reset_profile_highlights (self):
+               self.profile.setPlainText ("")
 
        # function to set personal information data in the GUI from document data
        def set_personal_info (self, docdata):
@@ -220,6 +306,8 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.mobilenumber.setText (docdata.data["mobile"])
                self.email.setText (docdata.data["email"])
                self.areacode.setText (docdata.data["areacode"])
+               self.country.setText (docdata.data["country"])
+
                if docdata.data["maritalstatus"] is True:
                        self.married.setChecked (True)
                elif docdata.data["maritalstatus"] is False:
@@ -339,6 +427,7 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                self.title.setText ("")
 
                self.reset_personal_info ()
+               self.reset_profile_highlights ()
                self.reset_professional_history ()
                self.reset_educational_qualifications ()
                self.reset_career_objectives ()
@@ -540,9 +629,9 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                        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"
+               # and set to empty
                if self.currentemployment.isChecked ():
-                       leavedatestr = "current"
+                       leavedatestr = ""
                else:
                        # if the leaving date is < join date
                        if self.leavedate.date () < self.joindate.date ():
@@ -582,9 +671,9 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                        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"
+               # and set to ""
                if self.currentemployment.isChecked ():
-                       leavedatestr = "current"
+                       leavedatestr = ""
                else:
                        # if the leaving date is < join date
                        if self.leavedate.date () < self.joindate.date ():
@@ -620,7 +709,7 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                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":
+               if selitem.text (2) == "":
                        self.leavedate.setEnabled (False)
                        self.currentemployment.setChecked (True)
                else: