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