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