0ceebde6c327263447e164553d32f2d8e161993b
[biacv.git] / biacv_mainwindow.py
1 # BiaCV
2 # class for main window
3
4 import PyQt4
5 import sys
6
7 import biacv_mainwindow_ui as bui
8 import biacv_lang as lang
9 import biacv_data as data
10 import biacv_exporter as exporter
11
12 class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
13 def __init__ (self):
14 PyQt4.QtGui.QMainWindow.__init__ (self)
15 self.setupUi (self)
16 self.currentfile = None
17 self.ismodified = False
18 self.setWindowTitle ("BiaCV - untitled")
19
20 # on window closing
21 def closeEvent (self, event):
22 if self.ismodified is True:
23 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DISCARD_SAVE,
24 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
25 # ignore event if not confirmed
26 if ans <> PyQt4.QtGui.QMessageBox.Yes:
27 event.ignore ()
28
29 # on help about dialog box
30 def on_help_about (self):
31 PyQt4.QtGui.QMessageBox.about (self, lang.ABOUT_TITLE, lang.ABOUT_TEXT)
32
33 # on file exit
34 def on_exit (self):
35 # call the close event
36 self.close()
37
38 # on file export - export current document to any external format based on
39 # a template
40 def on_file_export (self):
41 # get the template directory
42 templatedir = PyQt4.QtGui.QFileDialog.getExistingDirectory (self,
43 lang.OPEN_TEMPLATE_TITLE)
44 if templatedir == "":
45 return
46
47 # get the output file path
48 outputfile = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
49 lang.EXPORT_TITLE)
50
51 if outputfile == "":
52 return
53
54 # create a new exporter object
55 exp = exporter.BiaCVExporter ()
56
57 # set the document data
58 exp.set_data (self.get_document_data ().data)
59
60 # set the template directory
61 exp.set_template_directory (unicode (templatedir.toUtf8(), "utf-8"))
62
63 # set the output file
64 exp.set_output (unicode (outputfile.toUtf8(), "utf-8"))
65
66 # carry out the export function
67 exp.export ()
68
69 # function to open a file
70 def on_file_open (self):
71 # if modified, confirm
72 if self.ismodified is True:
73 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DISCARD_SAVE,
74 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
75 # if no, then don't open the file
76 if ans <> PyQt4.QtGui.QMessageBox.Yes:
77 return
78
79 # open file dialog
80 openfilename = PyQt4.QtGui.QFileDialog.getOpenFileName (self, lang.OPEN_TITLE)
81 # if no open file name then return
82 if openfilename == "":
83 return
84
85 # load the document data from open file name
86 docdata = data.BiaCVData ()
87 docdata.load_data (openfilename)
88
89 # set the title
90 self.title.setText (docdata.data["title"])
91
92 # set the personal information fields from document data
93 self.set_personal_info (docdata)
94
95 # set the educational qualifications
96 self.set_educational_qualifications (docdata)
97
98 # set the professional history
99 self.set_professional_history (docdata)
100
101 # set the career objectives
102 self.set_career_objectives (docdata)
103
104 # set the skills list
105 self.set_skillsets_info (docdata)
106
107 # set the additional information
108 self.set_additional_info (docdata)
109
110 # set the current document
111 self.currentfile = openfilename
112 self.ismodified = False
113
114 # set the window title
115 self.setWindowTitle ("BiaCV - " + self.currentfile)
116
117 # function to save a file as a new document
118 def on_file_save_as (self):
119 savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
120 lang.SAVE_TITLE)
121
122 # if save file name is not none
123 if savefilename <> "":
124 mydata = self.get_document_data ()
125 mydata.save_data (savefilename)
126 self.ismodified = False
127 self.currentfile = savefilename
128 self.setWindowTitle ("BiaCV - " + self.currentfile)
129
130 # function to save a file
131 def on_file_save (self):
132 # only save modified file
133 if self.ismodified is False:
134 return
135
136 # if no current file get file name from file save dialog
137 if self.currentfile is None:
138 savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self,
139 lang.SAVE_TITLE)
140
141 if savefilename <> "":
142 mydata = self.get_document_data ()
143 mydata.save_data (savefilename)
144 self.ismodified = False
145 self.currentfile = savefilename
146 self.setWindowTitle ("BiaCV - " + self.currentfile)
147 else:
148 mydata = self.get_document_data ()
149 mydata.save_data (self.currentfile)
150 self.ismodified = False
151
152 # function to set document data from the GUI
153 def get_document_data (self):
154 docdata = data.BiaCVData ()
155
156 # set the document title
157 docdata.set_document_title (unicode (self.title.text ().toUtf8 (), "utf-8"))
158
159 # get the marital status string from check box
160 if self.married.isChecked ():
161 maritalstatus = True
162 elif self.single.isChecked ():
163 maritalstatus = False
164 else:
165 maritalstatus = None
166
167 docdata.set_personal_info (
168 unicode (self.nametitle.lineEdit ().text ().toUtf8 (), "utf-8"),
169 unicode (self.firstname.text ().toUtf8 (), "utf-8"),
170 unicode (self.lastname.text ().toUtf8 (), "utf-8"),
171 unicode (self.dateofbirth.date().toString ("dd MMM, yyyy"), "utf-8"),
172 unicode (self.street.text ().toUtf8 (), "utf-8"),
173 unicode (self.area.text ().toUtf8 (), "utf-8"),
174 unicode (self.city.text ().toUtf8 (), "utf-8"),
175 unicode (self.areacode.text ().toUtf8 (), "utf-8"),
176 unicode (self.countrycode_landline.text ().toUtf8 (), "utf-8"),
177 unicode (self.telephone.text ().toUtf8 (), "utf-8"),
178 unicode (self.countrycode_mobile.text ().toUtf8 (), "utf-8"),
179 unicode (self.mobilenumber.text ().toUtf8 (), "utf-8"),
180 unicode (self.email.text ().toUtf8 (), "utf-8"),
181 maritalstatus
182 )
183 # get the list of educational qualifications from the treewidget
184 education = []
185 i = 0
186 while i < self.educationlist.topLevelItemCount ():
187 curitem = self.educationlist.topLevelItem (i)
188 curdict = {}
189 curdict["degree"] = unicode (curitem.text (0).toUtf8 (), "utf-8")
190 curdict["graduation"] = unicode (curitem.text (1).toUtf8 (), "utf-8")
191 curdict["institution"] = unicode (curitem.text (2).toUtf8 (), "utf-8")
192 curdict["university"] = unicode (curitem.text (3).toUtf8 (), "utf-8")
193 curdict["grade"] = unicode (curitem.text (4).toUtf8 (), "utf-8")
194 curdict["percentage"] = float (curitem.text (5))
195 education.append (curdict)
196 i += 1
197
198 # set the educational qualifications
199 docdata.set_educational_qualifications (education)
200
201 # get the list of professional history from the treewidget
202 professional = []
203 i = 0
204 while i < self.professionlist.topLevelItemCount ():
205 curitem = self.professionlist.topLevelItem (i)
206 curdict = {}
207 curdict["jobtitle"] = unicode (curitem.text (0).toUtf8 (), "utf-8")
208 curdict["joindate"] = unicode (curitem.text (1), "utf-8")
209 curdict["leavedate"] = unicode (curitem.text (2), "utf-8")
210 curdict["organization"] = unicode (curitem.text (3).toUtf8 (), "utf-8")
211 curdict["additionalinfo"] = unicode (curitem.text (4).toUtf8 (), "utf-8")
212 professional.append (curdict)
213 i += 1
214
215 # set the professional qualifications
216 docdata.set_professional_history (professional)
217
218 # set the career objectives
219 shorttermobjectives = unicode (self.shorttermcareer.toPlainText ().toUtf8 (), "utf-8").splitlines ()
220 longtermgoals = unicode (self.longtermgoals.toPlainText ().toUtf8 (), "utf-8").splitlines ()
221
222 docdata.set_career_objectives (shorttermobjectives, longtermgoals)
223
224 # set the skill sets
225 skills = []
226 i = 0
227 while i < self.skillslist.topLevelItemCount ():
228 curitem = self.skillslist.topLevelItem (i)
229 curdict = {}
230 curdict["skilltitle"] = unicode (curitem.text (0).toUtf8 (), "utf-8")
231 curdict["skilldesc"] = unicode (curitem.text (1).toUtf8 (), "utf-8")
232 skills.append (curdict)
233 i += 1
234 # set the list of skills
235 docdata.set_skillsets (skills)
236
237 # get the list of languages
238 langsknown = []
239 i = 0
240 while i < self.languageslist.topLevelItemCount ():
241 curitem = self.languageslist.topLevelItem (i)
242 curdict = {}
243 curdict["language"] = unicode (curitem.text (0).toUtf8 (), "utf-8")
244 curdict["canspeak" ] = (curitem.text (1) == "True")
245 curdict["canreadwrite"] = (curitem.text (2) == "True")
246 curdict["isproficient"] = (curitem.text (3) == "True")
247 langsknown.append (curdict)
248 i += 1
249
250 additionalinformation = unicode (self.additionalinformation.toPlainText ().toUtf8 (), "utf-8")
251
252 docdata.set_additional_information (langsknown, additionalinformation)
253
254 return docdata
255
256 # function to reset personal information data in the GUI
257 def reset_personal_info (self):
258 self.nametitle.setEditText ("")
259 self.firstname.setText ("")
260 self.lastname.setText ("")
261 self.dateofbirth.setDate (PyQt4.QtCore.QDate (1970, 1, 1))
262 self.street.setText ("")
263 self.area.setText ("")
264 self.city.setText ("")
265 self.countrycode_landline.setText ("")
266 self.telephone.setText ("")
267 self.countrycode_mobile.setText ("")
268 self.mobilenumber.setText ("")
269 self.email.setText ("")
270 self.areacode.setText ("")
271 self.unspecified.setChecked (True)
272
273 # function to set personal information data in the GUI from document data
274 def set_personal_info (self, docdata):
275 self.nametitle.setEditText (docdata.data["nametitle"])
276 self.firstname.setText (docdata.data["firstname"])
277 self.lastname.setText (docdata.data["lastname"])
278 self.dateofbirth.setDate (PyQt4.QtCore.QDate.fromString (docdata.data["dateofbirth"], "dd MMM, yyyy"))
279 self.street.setText (docdata.data["street"])
280 self.area.setText (docdata.data["area"])
281 self.city.setText (docdata.data["city"])
282 self.countrycode_landline.setText (docdata.data["countrycode_landline"])
283 self.telephone.setText (docdata.data["landline"])
284 self.countrycode_mobile.setText (docdata.data["countrycode_mobile"])
285 self.mobilenumber.setText (docdata.data["mobile"])
286 self.email.setText (docdata.data["email"])
287 self.areacode.setText (docdata.data["areacode"])
288 if docdata.data["maritalstatus"] is True:
289 self.married.setChecked (True)
290 elif docdata.data["maritalstatus"] is False:
291 self.single.setChecked (True)
292 else:
293 self.unspecified.setChecked (True)
294
295 # function to clear professional history in the GUI
296 def reset_professional_history (self):
297 self.reset_profession_fields ()
298 self.professionlist.clear ()
299
300 # function to set the professional history in the GUI from the document data
301 def set_professional_history (self, docdata):
302 # reset the professional history
303 self.reset_professional_history ()
304
305 # add the professional history items to list
306 for item in docdata.data["professionalhistory"]:
307 professionitem = PyQt4.QtGui.QTreeWidgetItem (
308 [
309 item["jobtitle"],
310 item["joindate"],
311 item["leavedate"],
312 item["organization"],
313 item["additionalinfo"]
314 ]
315 )
316 self.professionlist.addTopLevelItem (professionitem)
317
318 # function to clear educational qualifications in the GUI
319 def reset_educational_qualifications (self):
320 self.reset_education_fields ()
321 self.educationlist.clear ()
322
323 # function to set education qualifications in the GUI from document data
324 def set_educational_qualifications (self, docdata):
325 # reset the educational qualifications
326 self.reset_educational_qualifications ()
327
328 # add education items to list
329 for item in docdata.data["educationalqualifications"]:
330 educationitem = PyQt4.QtGui.QTreeWidgetItem (
331 [
332 item["degree"],
333 item["graduation"],
334 item["institution"],
335 item["university"],
336 item["grade"],
337 str (item["percentage"])
338 ]
339 )
340 self.educationlist.addTopLevelItem (educationitem)
341
342 # function to clear career objectives data in the GUI
343 def reset_career_objectives (self):
344 self.shorttermcareer.setPlainText ("")
345 self.longtermgoals.setPlainText ("")
346
347 # function to set career objectives data in the GUI from document data
348 def set_career_objectives (self, docdata):
349 self.shorttermcareer.setPlainText (u'\n'.join (docdata.data["shorttermobjectives"]))
350 self.longtermgoals.setPlainText (u'\n'.join (docdata.data["longtermgoals"]))
351
352 # function to clear skill sets data in the GUI
353 def reset_skillsets_info (self):
354 self.reset_skillset_fields ()
355 self.skillslist.clear ()
356
357 # function to set the skill sets data in the GUI from document data
358 def set_skillsets_info (self, docdata):
359 # clear the skill sets information
360 self.reset_skillsets_info ()
361
362 for item in docdata.data["skillsets"]:
363 skillitem = PyQt4.QtGui.QTreeWidgetItem (
364 [
365 item["skilltitle"],
366 item["skilldesc"]
367 ]
368 )
369 self.skillslist.addTopLevelItem (skillitem)
370
371
372 # function to clear additional information data in the GUI
373 def reset_additional_info (self):
374 self.reset_language_fields ()
375 self.languageslist.clear ()
376 self.additionalinformation.setPlainText ("")
377
378 # function to set additional information data in the GUI from the document data
379 def set_additional_info (self, docdata):
380 # clear the additional information
381 self.reset_additional_info ()
382
383 # set the languages list
384 for item in docdata.data["languagesknown"]:
385 langitem = PyQt4.QtGui.QTreeWidgetItem (
386 [
387 item["language"],
388 str (item["canspeak"]),
389 str (item["canreadwrite"]),
390 str (item["isproficient"])
391 ]
392 )
393 self.languageslist.addTopLevelItem (langitem)
394
395 self.additionalinformation.setPlainText (docdata.data["additionalinformation"])
396
397 # function to clear all the fields and reset them to defaults
398 def new_document (self):
399 # first clear the individual record fields in the tabs
400 self.reset_language_fields ()
401 self.reset_skillset_fields ()
402
403 # clear document data
404 self.title.setText ("")
405
406 self.reset_personal_info ()
407 self.reset_professional_history ()
408 self.reset_educational_qualifications ()
409 self.reset_career_objectives ()
410 self.reset_skillsets_info ()
411 self.reset_additional_info ()
412
413 # set the page to first page
414 self.pages.setCurrentIndex (0)
415
416 # set current file to none and modified to false
417 self.currentfile = None
418 self.ismodified = False
419
420 # set the window title
421 self.setWindowTitle ("BiaCV - untitled")
422
423 # file new action is triggered
424 def on_file_new (self):
425 # if the previous document is modified
426 # as if it should be discarded
427 if self.ismodified is True:
428 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM,
429 lang.CONFIRM_DISCARD_SAVE,
430 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
431 if ans == PyQt4.QtGui.QMessageBox.Yes:
432 self.new_document ()
433 # if not modified then simply create a new document
434 else:
435 self.new_document ()
436
437 # when the document is modified
438 def on_document_modified (self):
439 # set the document modified flag
440 self.ismodified = True
441
442 # update a language in the list of languages
443 def on_update_lang (self):
444 # get the selected language
445 selitems = self.languageslist.selectedItems ()
446 if selitems == []:
447 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
448 return
449 # check if the language string is not empty
450 if self.language.text () == "":
451 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
452 return
453 selitem = selitems[0]
454 selitem.setText (0, self.language.text ())
455 selitem.setText (1, str (self.canspeak.isChecked ()))
456 selitem.setText (2, str (self.canreadwrite.isChecked ()))
457 selitem.setText (3, str (self.isproficient.isChecked ()))
458
459 # modified the document
460 self.ismodified = True
461
462 # selecting a language from the list of languages
463 def on_select_lang (self):
464 # set the language fields from the selected item
465 self.set_language_fields ()
466
467 # delete a language from the list of languages known
468 def on_delete_lang (self):
469 # get selected language
470 selitems = self.languageslist.selectedItems ()
471 if selitems == []:
472 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_REQ_MISSING)
473 return
474 # confirm
475 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
476 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
477 if ans == PyQt4.QtGui.QMessageBox.Yes:
478 for item in selitems:
479 self.languageslist.takeTopLevelItem (self.languageslist.indexOfTopLevelItem (item))
480
481 self.reset_language_fields ()
482 # set the modified flag
483 self.ismodified = True
484
485 # add a language to the list of languages known
486 def on_add_lang (self):
487 # check if the language is set
488 if self.language.text () == "":
489 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
490 return
491 langitem = PyQt4.QtGui.QTreeWidgetItem (
492 [
493 self.language.text (),
494 str (self.canspeak.isChecked ()),
495 str (self.canreadwrite.isChecked ()),
496 str (self.isproficient.isChecked ())
497 ]
498 )
499 self.languageslist.addTopLevelItem (langitem)
500 self.reset_language_fields ()
501
502 # set the modified flag
503 self.ismodified = True
504
505 # set the language fields from the selected item
506 def set_language_fields (self):
507 selitems = self.languageslist.selectedItems ()
508 if selitems == []:
509 return
510 selitem = selitems[0]
511 self.language.setText (selitem.text (0))
512 self.canspeak.setChecked (selitem.text (1) == "True")
513 self.canreadwrite.setChecked (selitem.text(2) == "True")
514 self.isproficient.setChecked (selitem.text(3) == "True")
515
516 # reset the language fields
517 def reset_language_fields (self):
518 self.language.setText ("")
519 self.canspeak.setChecked (True)
520 self.canreadwrite.setChecked (False)
521 self.isproficient.setChecked (False)
522
523 # update the skill set button event
524 def on_update_skill (self):
525 # get the selected item
526 selitems = self.skillslist.selectedItems ()
527 if selitems == []:
528 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
529 return
530 if self.skillsettitle.text () == "":
531 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
532 return
533 selitem = selitems[0]
534
535 selitem.setText (0, self.skillsettitle.text ())
536 selitem.setText (1, self.skilldescription.toPlainText ())
537 # set the modified flag
538 self.ismodified = True
539
540 # selecting a skill from the list event
541 def on_select_skill (self):
542 self.set_skill_fields ()
543
544 # set the skill fields from the selected skill from the list
545 def set_skill_fields (self):
546 # get the selected items
547 selitems = self.skillslist.selectedItems ()
548 if selitems == []:
549 return
550 selitem = selitems[0]
551 self.skillsettitle.setText (selitem.text (0))
552 self.skilldescription.setPlainText (selitem.text (1))
553
554 # delete skill set button is clicked
555 def on_delete_skill (self):
556 # get the selected items
557 selitems = self.skillslist.selectedItems ()
558 if selitems == []:
559 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
560 return
561 # confirm
562 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
563 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
564 # answer is yes
565 if ans == PyQt4.QtGui.QMessageBox.Yes:
566 for item in selitems:
567 self.skillslist.takeTopLevelItem (self.skillslist.indexOfTopLevelItem (item))
568
569 self.reset_skillset_fields ()
570 # set the modified flag
571 self.ismodified = True
572
573 # add skill set button is clicked
574 def on_add_skill (self):
575 # if the skill title is blank
576 if self.skillsettitle.text () == "":
577 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
578 return
579 skillitem = PyQt4.QtGui.QTreeWidgetItem (
580 [
581 self.skillsettitle.text (),
582 self.skilldescription.toPlainText ()
583 ]
584 )
585 self.skillslist.addTopLevelItem (skillitem)
586 self.reset_skillset_fields ()
587 # set the modified flag
588 self.ismodified = True
589
590 # clear the skill set fields
591 def reset_skillset_fields (self):
592 self.skillsettitle.setText ("")
593 self.skilldescription.setPlainText ("")
594
595 # update professional history button is clicked
596 def on_update_profession (self):
597 # get the selected item
598 selitems = self.professionlist.selectedItems ()
599 if selitems == []:
600 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
601 return
602 selitem = selitems[0]
603 # if designation is not set
604 if self.designation.text () == "":
605 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
606 return
607 # if currently employed in that position, leaving date is to be disabled
608 # and set to "current"
609 if self.currentemployment.isChecked ():
610 leavedatestr = "current"
611 else:
612 # if the leaving date is < join date
613 if self.leavedate.date () < self.joindate.date ():
614 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
615 return
616 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
617
618 selitem.setText (0, self.designation.text ())
619 selitem.setText (1, self.joindate.date ().toString ("dd MMM, yyyy"))
620 selitem.setText (2, leavedatestr)
621 selitem.setText (3, self.organization.text ())
622 selitem.setText (4, self.additionalinfo.text ())
623 # set the modified flag
624 self.ismodified = True
625
626 # delete professional history button is clicked
627 def on_delete_profession (self):
628 # get the selected items
629 selitems = self.professionlist.selectedItems ()
630 if selitems == []:
631 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
632 return
633 # confirm deletion
634 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
635 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
636 # if confirmed
637 if ans == PyQt4.QtGui.QMessageBox.Yes:
638 for item in selitems:
639 self.professionlist.takeTopLevelItem (self.professionlist.indexOfTopLevelItem (item))
640 self.reset_profession_fields ()
641 # set the modified flag
642 self.ismodified = True
643
644 # add professional history button is clicked
645 def on_add_profession (self):
646 if self.designation.text () == "":
647 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
648 return
649 # if currently employed in that position, leaving date is to be disabled
650 # and set to "current"
651 if self.currentemployment.isChecked ():
652 leavedatestr = "current"
653 else:
654 # if the leaving date is < join date
655 if self.leavedate.date () < self.joindate.date ():
656 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
657 return
658 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
659
660 professionitem = PyQt4.QtGui.QTreeWidgetItem (
661 [
662 self.designation.text (),
663 self.joindate.date ().toString ("dd MMM, yyyy"),
664 leavedatestr,
665 self.organization.text (),
666 self.additionalinfo.text ()
667 ]
668 )
669
670 self.professionlist.addTopLevelItem (professionitem)
671
672 self.reset_profession_fields ()
673 # set the modified flag
674 self.ismodified = True
675
676 # when selection of profession list is changed
677 def on_select_profession (self):
678 self.set_profession_fields ()
679
680 # set the profession fields from the selected item in profession list
681 def set_profession_fields (self):
682 selitems = self.professionlist.selectedItems ()
683 if selitems == []:
684 return
685 selitem = selitems[0]
686 self.designation.setText (selitem.text (0))
687 self.joindate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "dd MMM, yyyy"))
688 if selitem.text (2) == "current":
689 self.leavedate.setEnabled (False)
690 self.currentemployment.setChecked (True)
691 else:
692 self.leavedate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text (2), "dd MMM, yyyy"))
693 self.leavedate.setEnabled (True)
694 self.currentemployment.setChecked (False)
695
696 self.organization.setText (selitem.text (3))
697 self.additionalinfo.setText (selitem.text (4))
698
699 def reset_profession_fields (self):
700 self.designation.setText ("")
701 self.joindate.setDate (PyQt4.QtCore.QDate (2000, 1, 1))
702 self.leavedate.setDate (PyQt4.QtCore.QDate (2003, 1, 1))
703 self.currentemployment.setChecked (False)
704 self.organization.setText ("")
705 self.additionalinfo.setText ("")
706
707 # current employment check box is changed
708 def on_change_currentemployment (self, val):
709 if val == True:
710 self.leavedate.setEnabled (False)
711 else:
712 self.leavedate.setEnabled (True)
713
714 # delete educational qualification
715 def on_delete_education (self):
716 # get the selected items in the education list
717 selitems = self.educationlist.selectedItems ()
718 # if no items are selected
719 if selitems == []:
720 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
721 # delete the items after confirmation
722 else:
723 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
724 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
725 if ans == PyQt4.QtGui.QMessageBox.Yes:
726 # remove the item selected
727 for item in selitems:
728 self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
729 self.reset_education_fields ()
730 # set the modified flag
731 self.ismodified = True
732
733 # selection is changed
734 def on_select_education (self):
735 self.set_education_fields ()
736
737 # update educational qualification button
738 def on_update_education (self):
739 selitems = self.educationlist.selectedItems ()
740 # if no item is selected
741 if selitems == []:
742 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
743 return
744 # if the qualification title is not set
745 if self.degree_name.text () == "":
746 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
747 return
748 selitem = selitems[0]
749
750 selitem.setText (0, self.degree_name.text ())
751 selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
752 selitem.setText (2, self.institution.text ())
753 selitem.setText (3, self.university.text ())
754 selitem.setText (4, self.grade.text ())
755 selitem.setText (5, str (self.percentage.value ()))
756 # set the modified flag
757 self.ismodified = True
758
759 # add educational qualification button
760 def on_add_education (self):
761 # check if the qualification title is set
762 if self.degree_name.text () == "":
763 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
764 return
765 educationitem = PyQt4.QtGui.QTreeWidgetItem ([
766 self.degree_name.text (),
767 self.yearofpassing.date ().toString ("MMM, yyyy"),
768 self.institution.text (),
769 self.university.text (),
770 self.grade.text (),
771 str (self.percentage.value ())
772 ])
773 self.educationlist.addTopLevelItem (educationitem)
774 # clear the fields
775 self.reset_education_fields ()
776 # set the modified flag
777 self.ismodified = True
778
779 # set fields in the education tab from current selected item
780 def set_education_fields (self):
781 selitems = self.educationlist.selectedItems ()
782 if selitems == []:
783 return
784 selitem = selitems[0]
785 # set the fields to the data in the selected item in the list
786 self.degree_name.setText (selitem.text (0))
787 self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
788 self.institution.setText (selitem.text (2))
789 self.university.setText (selitem.text (3))
790 self.grade.setText (selitem.text(4))
791 self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
792
793 # reset fields in the education tab
794 def reset_education_fields (self):
795 self.degree_name.setText ("")
796 self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
797 self.institution.setText ("")
798 self.university.setText ("")
799 self.grade.setText ("")
800 self.percentage.setValue (50.0)
801