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