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