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