X-Git-Url: https://harishankar.org/repos/?a=blobdiff_plain;f=biacv_mainwindow.py;h=8e4eb5f7febb2c0d4677ae63869fe128d8e62138;hb=f4f6fa0b00ec4dffc7714bb48bacaf6e4e18b926;hp=4a98c2d3167e0cda708d8686aeedf4602fcfbcb1;hpb=bb028ebabf00111ec146cdd64b5cb5c8563bf09b;p=biacv.git diff --git a/biacv_mainwindow.py b/biacv_mainwindow.py index 4a98c2d..8e4eb5f 100644 --- a/biacv_mainwindow.py +++ b/biacv_mainwindow.py @@ -2,18 +2,71 @@ # 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 + + # get the output file path + outputfile = PyQt4.QtGui.QFileDialog.getSaveFileName (self, + lang.EXPORT_TITLE) + + if outputfile == "": + 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")) + + # 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 @@ -62,6 +115,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) + + # 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 @@ -75,7 +141,7 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow): 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 +174,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"), @@ -220,6 +287,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: @@ -540,9 +609,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 +651,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 +689,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: