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