192ef4c2c4fb2c53073a4e4fd109981c54066b4d
2 # class for main window
5 import biacv_mainwindow_ui
as bui
6 import biacv_lang
as lang
7 import biacv_data
as data
9 class Biacv_mainwindow (PyQt4
.QtGui
.QMainWindow
, bui
.Ui_biacv_mainwindow
):
11 PyQt4
.QtGui
.QMainWindow
.__init
__ (self
)
13 self
.currentfile
= None
14 self
.ismodified
= False
16 # function to save a file
17 def on_file_save (self
):
18 # only save modified file
19 if self
.ismodified
is False:
22 # if no current file get file name from file save dialog
23 if self
.currentfile
is None:
24 self
.currentfile
= PyQt4
.QtGui
.QFileDialog
.getSaveFileName (self
,
27 if self
.currentfile
is not None:
28 mydata
= self
.get_document_data ()
29 mydata
.save_data (self
.currentfile
)
30 self
.ismodified
= False
32 mydata
= self
.get_document_data ()
33 mydata
.save_data (self
.currentfile
)
34 self
.ismodified
= False
36 # function to set document data from the GUI
37 def get_document_data (self
):
38 docdata
= data
.BiaCVData ()
40 # set the document title
41 docdata
.set_document_title (unicode (self
.title
.text (), "utf-8"))
43 # get the marital status string from check box
44 if self
.married
.isChecked ():
46 elif self
.single
.isChecked ():
51 docdata
.set_personal_info (
52 unicode (self
.nametitle
.lineEdit ().text (), "utf-8"),
53 unicode (self
.firstname
.text (), "utf-8"),
54 unicode (self
.lastname
.text (), "utf-8"),
55 unicode (self
.dateofbirth
.date().toString ("dd MMM, yyyy"), "utf-8"),
56 unicode (self
.street
.text (), "utf-8"),
57 unicode (self
.area
.text (), "utf-8"),
58 unicode (self
.city
.text (), "utf-8"),
59 unicode (self
.areacode
.text (), "utf-8"),
60 unicode (self
.countrycode_landline
.text (), "utf-8"),
61 unicode (self
.telephone
.text (), "utf-8"),
62 unicode (self
.countrycode_mobile
.text (), "utf-8"),
63 unicode (self
.mobilenumber
.text (), "utf-8"),
64 unicode (self
.email
.text (), "utf-8"),
67 # get the list of educational qualifications from the treewidget
70 while i
< self
.educationlist
.topLevelItemCount ():
71 curitem
= self
.educationlist
.topLevelItem (i
)
73 curdict
["degree"] = unicode (curitem
.text (0), "utf-8")
74 curdict
["graduation"] = unicode (curitem
.text (1), "utf-8")
75 curdict
["institution"] = unicode (curitem
.text (2), "utf-8")
76 curdict
["university"] = unicode (curitem
.text (3), "utf-8")
77 curdict
["grade"] = unicode (curitem
.text (4), "utf-8")
78 curdict
["percentage"] = float (curitem
.text (5))
79 education
.append (curdict
)
82 # set the educational qualifications
83 docdata
.set_educational_qualifications (education
)
85 # get the list of professional history from the treewidget
88 while i
< self
.professionlist
.topLevelItemCount ():
89 curitem
= self
.professionlist
.topLevelItem (i
)
91 curdict
["jobtitle"] = unicode (curitem
.text (0), "utf-8")
92 curdict
["joindate"] = unicode (curitem
.text (1), "utf-8")
93 curdict
["leavedate"] = unicode (curitem
.text (2), "utf-8")
94 curdict
["organization"] = unicode (curitem
.text (3), "utf-8")
95 curdict
["additionalinfo"] = unicode (curitem
.text (4), "utf-8")
96 professional
.append (curdict
)
99 # set the professional qualifications
100 docdata
.set_professional_history (professional
)
102 # set the career objectives
103 shorttermobjectives
= unicode (self
.shorttermcareer
.toPlainText (), "utf-8").splitlines ()
104 longtermgoals
= unicode (self
.longtermgoals
.toPlainText (), "utf-8").splitlines ()
106 docdata
.set_career_objectives (shorttermobjectives
, longtermgoals
)
111 while i
< self
.skillslist
.topLevelItemCount ():
112 curitem
= self
.skillslist
.topLevelItem (i
)
114 curdict
["skilltitle"] = unicode (curitem
.text (0), "utf-8")
115 curdict
["skilldesc"] = unicode (curitem
.text (1), "utf-8")
116 skills
.append (curdict
)
118 # set the list of skills
119 docdata
.set_skillsets (skills
)
121 # get the list of languages
124 while i
< self
.languageslist
.topLevelItemCount ():
125 curitem
= self
.languageslist
.topLevelItem (i
)
127 curdict
["language"] = unicode (curitem
.text (0), "utf-8")
128 curdict
["canspeak" ] = (curitem
.text (1) == "True")
129 curdict
["canreadwrite"] = (curitem
.text (2) == "True")
130 curdict
["isproficient"] = (curitem
.text (3) == "True")
131 langsknown
.append (curdict
)
134 additionalinformation
= unicode (self
.additionalinformation
.toPlainText (), "utf-8")
136 docdata
.set_additional_information (langsknown
, additionalinformation
)
140 # function to reset personal information data in the GUI
141 def reset_personal_info (self
):
142 self
.nametitle
.setEditText ("")
143 self
.firstname
.setText ("")
144 self
.lastname
.setText ("")
145 self
.dateofbirth
.setDate (PyQt4
.QtCore
.QDate (1970, 1, 1))
146 self
.street
.setText ("")
147 self
.area
.setText ("")
148 self
.city
.setText ("")
149 self
.countrycode_landline
.setText ("")
150 self
.telephone
.setText ("")
151 self
.countrycode_mobile
.setText ("")
152 self
.mobilenumber
.setText ("")
153 self
.email
.setText ("")
154 self
.areacode
.setText ("")
155 self
.unspecified
.setChecked (True)
157 # function to clear professional history in the GUI
158 def reset_professional_history (self
):
159 self
.reset_profession_fields ()
160 self
.professionlist
.clear ()
162 # function to clear educational qualifications in the GUI
163 def reset_educational_qualifications (self
):
164 self
.reset_education_fields ()
165 self
.educationlist
.clear ()
167 # function to clear career objectives data in the GUI
168 def reset_career_objectives (self
):
169 self
.shorttermcareer
.setPlainText ("")
170 self
.longtermgoals
.setPlainText ("")
172 # function to clear skill sets data in the GUI
173 def reset_skillsets_info (self
):
174 self
.reset_skillset_fields ()
175 self
.skillslist
.clear ()
177 # function to clear additional information data in the GUI
178 def reset_additional_info (self
):
179 self
.reset_language_fields ()
180 self
.languageslist
.clear ()
181 self
.additionalinformation
.setPlainText ("")
183 # function to clear all the fields and reset them to defaults
184 def new_document (self
):
185 # first clear the individual record fields in the tabs
186 self
.reset_language_fields ()
187 self
.reset_skillset_fields ()
189 # clear document data
190 self
.title
.setText ("")
192 self
.reset_personal_info ()
193 self
.reset_professional_history ()
194 self
.reset_educational_qualifications ()
195 self
.reset_career_objectives ()
196 self
.reset_skillsets_info ()
197 self
.reset_additional_info ()
199 # set the page to first page
200 self
.pages
.setCurrentIndex (0)
202 # set current file to none and modified to false
203 self
.currentfile
= None
204 self
.ismodified
= False
206 # file new action is triggered
207 def on_file_new (self
):
208 # if the previous document is modified
209 # as if it should be discarded
210 if self
.ismodified
is True:
211 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, lang
.CONFIRM
,
212 lang
.CONFIRM_DISCARD_SAVE
,
213 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
214 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
216 # if not modified then simply create a new document
220 # when the document is modified
221 def on_document_modified (self
):
222 # set the document modified flag
223 self
.ismodified
= True
225 # update a language in the list of languages
226 def on_update_lang (self
):
227 # get the selected language
228 selitems
= self
.languageslist
.selectedItems ()
230 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_NO_SELECTION
)
232 # check if the language string is not empty
233 if self
.language
.text () == "":
234 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_REQ_MISSING
)
236 selitem
= selitems
[0]
237 selitem
.setText (0, self
.language
.text ())
238 selitem
.setText (1, str (self
.canspeak
.isChecked ()))
239 selitem
.setText (2, str (self
.canreadwrite
.isChecked ()))
240 selitem
.setText (3, str (self
.isproficient
.isChecked ()))
242 # modified the document
243 self
.ismodified
= True
245 # selecting a language from the list of languages
246 def on_select_lang (self
):
247 # set the language fields from the selected item
248 self
.set_language_fields ()
250 # delete a language from the list of languages known
251 def on_delete_lang (self
):
252 # get selected language
253 selitems
= self
.languageslist
.selectedItems ()
255 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_DELETE
, lang
.ERROR_REQ_MISSING
)
258 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, lang
.CONFIRM
, lang
.CONFIRM_DELETE
,
259 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
260 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
261 for item
in selitems
:
262 self
.languageslist
.takeTopLevelItem (self
.languageslist
.indexOfTopLevelItem (item
))
264 self
.reset_language_fields ()
265 # set the modified flag
266 self
.ismodified
= True
268 # add a language to the list of languages known
269 def on_add_lang (self
):
270 # check if the language is set
271 if self
.language
.text () == "":
272 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_ADD
, lang
.ERROR_REQ_MISSING
)
274 langitem
= PyQt4
.QtGui
.QTreeWidgetItem (
276 self
.language
.text (),
277 str (self
.canspeak
.isChecked ()),
278 str (self
.canreadwrite
.isChecked ()),
279 str (self
.isproficient
.isChecked ())
282 self
.languageslist
.addTopLevelItem (langitem
)
283 self
.reset_language_fields ()
285 # set the modified flag
286 self
.ismodified
= True
288 # set the language fields from the selected item
289 def set_language_fields (self
):
290 selitems
= self
.languageslist
.selectedItems ()
293 selitem
= selitems
[0]
294 self
.language
.setText (selitem
.text (0))
295 self
.canspeak
.setChecked (selitem
.text (1) == "True")
296 self
.canreadwrite
.setChecked (selitem
.text(2) == "True")
297 self
.isproficient
.setChecked (selitem
.text(3) == "True")
299 # reset the language fields
300 def reset_language_fields (self
):
301 self
.language
.setText ("")
302 self
.canspeak
.setChecked (True)
303 self
.canreadwrite
.setChecked (False)
304 self
.isproficient
.setChecked (False)
306 # update the skill set button event
307 def on_update_skill (self
):
308 # get the selected item
309 selitems
= self
.skillslist
.selectedItems ()
311 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_NO_SELECTION
)
313 if self
.skillsettitle
.text () == "":
314 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_REQ_MISSING
)
316 selitem
= selitems
[0]
318 selitem
.setText (0, self
.skillsettitle
.text ())
319 selitem
.setText (1, self
.skilldescription
.toPlainText ())
320 # set the modified flag
321 self
.ismodified
= True
323 # selecting a skill from the list event
324 def on_select_skill (self
):
325 self
.set_skill_fields ()
327 # set the skill fields from the selected skill from the list
328 def set_skill_fields (self
):
329 # get the selected items
330 selitems
= self
.skillslist
.selectedItems ()
333 selitem
= selitems
[0]
334 self
.skillsettitle
.setText (selitem
.text (0))
335 self
.skilldescription
.setPlainText (selitem
.text (1))
337 # delete skill set button is clicked
338 def on_delete_skill (self
):
339 # get the selected items
340 selitems
= self
.skillslist
.selectedItems ()
342 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_DELETE
, lang
.ERROR_NO_SELECTION
)
345 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, lang
.CONFIRM
, lang
.CONFIRM_DELETE
,
346 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
348 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
349 for item
in selitems
:
350 self
.skillslist
.takeTopLevelItem (self
.skillslist
.indexOfTopLevelItem (item
))
352 self
.reset_skillset_fields ()
353 # set the modified flag
354 self
.ismodified
= True
356 # add skill set button is clicked
357 def on_add_skill (self
):
358 # if the skill title is blank
359 if self
.skillsettitle
.text () == "":
360 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_ADD
, lang
.ERROR_REQ_MISSING
)
362 skillitem
= PyQt4
.QtGui
.QTreeWidgetItem (
364 self
.skillsettitle
.text (),
365 self
.skilldescription
.toPlainText ()
368 self
.skillslist
.addTopLevelItem (skillitem
)
369 self
.reset_skillset_fields ()
370 # set the modified flag
371 self
.ismodified
= True
373 # clear the skill set fields
374 def reset_skillset_fields (self
):
375 self
.skillsettitle
.setText ("")
376 self
.skilldescription
.setPlainText ("")
378 # update professional history button is clicked
379 def on_update_profession (self
):
380 # get the selected item
381 selitems
= self
.professionlist
.selectedItems ()
383 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_NO_SELECTION
)
385 selitem
= selitems
[0]
386 # if designation is not set
387 if self
.designation
.text () == "":
388 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_REQ_MISSING
)
390 # if currently employed in that position, leaving date is to be disabled
391 # and set to "current"
392 if self
.currentemployment
.isChecked ():
393 leavedatestr
= "current"
395 # if the leaving date is < join date
396 if self
.leavedate
.date () < self
.joindate
.date ():
397 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_ADD
, lang
.ERROR_DATE
)
399 leavedatestr
= self
.leavedate
.date ().toString ("dd MMM, yyyy")
401 selitem
.setText (0, self
.designation
.text ())
402 selitem
.setText (1, self
.joindate
.date ().toString ("dd MMM, yyyy"))
403 selitem
.setText (2, leavedatestr
)
404 selitem
.setText (3, self
.organization
.text ())
405 selitem
.setText (4, self
.additionalinfo
.text ())
406 # set the modified flag
407 self
.ismodified
= True
409 # delete professional history button is clicked
410 def on_delete_profession (self
):
411 # get the selected items
412 selitems
= self
.professionlist
.selectedItems ()
414 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_DELETE
, lang
.ERROR_NO_SELECTION
)
417 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, lang
.CONFIRM
, lang
.CONFIRM_DELETE
,
418 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
420 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
421 for item
in selitems
:
422 self
.professionlist
.takeTopLevelItem (self
.professionlist
.indexOfTopLevelItem (item
))
423 self
.reset_profession_fields ()
424 # set the modified flag
425 self
.ismodified
= True
427 # add professional history button is clicked
428 def on_add_profession (self
):
429 if self
.designation
.text () == "":
430 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_ADD
, lang
.ERROR_REQ_MISSING
)
432 # if currently employed in that position, leaving date is to be disabled
433 # and set to "current"
434 if self
.currentemployment
.isChecked ():
435 leavedatestr
= "current"
437 # if the leaving date is < join date
438 if self
.leavedate
.date () < self
.joindate
.date ():
439 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_ADD
, lang
.ERROR_DATE
)
441 leavedatestr
= self
.leavedate
.date ().toString ("dd MMM, yyyy")
443 professionitem
= PyQt4
.QtGui
.QTreeWidgetItem (
445 self
.designation
.text (),
446 self
.joindate
.date ().toString ("dd MMM, yyyy"),
448 self
.organization
.text (),
449 self
.additionalinfo
.text ()
453 self
.professionlist
.addTopLevelItem (professionitem
)
455 self
.reset_profession_fields ()
456 # set the modified flag
457 self
.ismodified
= True
459 # when selection of profession list is changed
460 def on_select_profession (self
):
461 self
.set_profession_fields ()
463 # set the profession fields from the selected item in profession list
464 def set_profession_fields (self
):
465 selitems
= self
.professionlist
.selectedItems ()
468 selitem
= selitems
[0]
469 self
.designation
.setText (selitem
.text (0))
470 self
.joindate
.setDate (PyQt4
.QtCore
.QDate
.fromString (selitem
.text(1), "dd MMM, yyyy"))
471 if selitem
.text (2) == "current":
472 self
.leavedate
.setEnabled (False)
473 self
.currentemployment
.setChecked (True)
475 self
.leavedate
.setDate (PyQt4
.QtCore
.QDate
.fromString (selitem
.text (2), "dd MMM, yyyy"))
476 self
.leavedate
.setEnabled (True)
477 self
.currentemployment
.setChecked (False)
479 self
.organization
.setText (selitem
.text (3))
480 self
.additionalinfo
.setText (selitem
.text (4))
482 def reset_profession_fields (self
):
483 self
.designation
.setText ("")
484 self
.joindate
.setDate (PyQt4
.QtCore
.QDate (2000, 1, 1))
485 self
.leavedate
.setDate (PyQt4
.QtCore
.QDate (2003, 1, 1))
486 self
.currentemployment
.setChecked (False)
487 self
.organization
.setText ("")
488 self
.additionalinfo
.setText ("")
490 # current employment check box is changed
491 def on_change_currentemployment (self
, val
):
493 self
.leavedate
.setEnabled (False)
495 self
.leavedate
.setEnabled (True)
497 # delete educational qualification
498 def on_delete_education (self
):
499 # get the selected items in the education list
500 selitems
= self
.educationlist
.selectedItems ()
501 # if no items are selected
503 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_DELETE
, lang
.ERROR_NO_SELECTION
)
504 # delete the items after confirmation
506 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, lang
.CONFIRM
, lang
.CONFIRM_DELETE
,
507 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
508 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
509 # remove the item selected
510 for item
in selitems
:
511 self
.educationlist
.takeTopLevelItem (self
.educationlist
.indexOfTopLevelItem (item
))
512 self
.reset_education_fields ()
513 # set the modified flag
514 self
.ismodified
= True
516 # selection is changed
517 def on_select_education (self
):
518 self
.set_education_fields ()
520 # update educational qualification button
521 def on_update_education (self
):
522 selitems
= self
.educationlist
.selectedItems ()
523 # if no item is selected
525 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_NO_SELECTION
)
527 # if the qualification title is not set
528 if self
.degree_name
.text () == "":
529 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_UPDATE
, lang
.ERROR_REQ_MISSING
)
531 selitem
= selitems
[0]
533 selitem
.setText (0, self
.degree_name
.text ())
534 selitem
.setText (1, self
.yearofpassing
.date ().toString ("MMM, yyyy"))
535 selitem
.setText (2, self
.institution
.text ())
536 selitem
.setText (3, self
.university
.text ())
537 selitem
.setText (4, self
.grade
.text ())
538 selitem
.setText (5, str (self
.percentage
.value ()))
539 # set the modified flag
540 self
.ismodified
= True
542 # add educational qualification button
543 def on_add_education (self
):
544 # check if the qualification title is set
545 if self
.degree_name
.text () == "":
546 PyQt4
.QtGui
.QMessageBox
.critical (self
, lang
.ERROR_ADD
, lang
.ERROR_REQ_MISSING
)
548 educationitem
= PyQt4
.QtGui
.QTreeWidgetItem ([
549 self
.degree_name
.text (),
550 self
.yearofpassing
.date ().toString ("MMM, yyyy"),
551 self
.institution
.text (),
552 self
.university
.text (),
554 str (self
.percentage
.value ())
556 self
.educationlist
.addTopLevelItem (educationitem
)
558 self
.reset_education_fields ()
559 # set the modified flag
560 self
.ismodified
= True
562 # set fields in the education tab from current selected item
563 def set_education_fields (self
):
564 selitems
= self
.educationlist
.selectedItems ()
567 selitem
= selitems
[0]
568 # set the fields to the data in the selected item in the list
569 self
.degree_name
.setText (selitem
.text (0))
570 self
.yearofpassing
.setDate (PyQt4
.QtCore
.QDate
.fromString (selitem
.text(1), "MMM, yyyy"))
571 self
.institution
.setText (selitem
.text (2))
572 self
.university
.setText (selitem
.text (3))
573 self
.grade
.setText (selitem
.text(4))
574 self
.percentage
.setValue (self
.percentage
.valueFromText (selitem
.text(5)))
576 # reset fields in the education tab
577 def reset_education_fields (self
):
578 self
.degree_name
.setText ("")
579 self
.yearofpassing
.setDate (PyQt4
.QtCore
.QDate (1988, 1, 1))
580 self
.institution
.setText ("")
581 self
.university
.setText ("")
582 self
.grade
.setText ("")
583 self
.percentage
.setValue (50.0)