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