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