7d577dabf4adfb18ba194f0d73b638a485860971
[biacv.git] / biacv_mainwindow.py
1 # BiaCV
2 # class for main window
3
4 import PyQt4
5 import biacv_mainwindow_ui as bui
6 import biacv_lang as lang
7
8 class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
9 def __init__ (self):
10 PyQt4.QtGui.QMainWindow.__init__ (self)
11 self.setupUi (self)
12 self.currentfile = None
13 self.ismodified = False
14
15 # function to reset personal information data in the GUI
16 def reset_personal_info (self):
17 self.nametitle.setEditText ("")
18 self.firstname.setText ("")
19 self.lastname.setText ("")
20 self.dateofbirth.setDate (PyQt4.QtCore.QDate (1970, 1, 1))
21 self.street.setText ("")
22 self.area.setText ("")
23 self.city.setText ("")
24 self.countrycode_landline.setText ("")
25 self.telephone.setText ("")
26 self.countrycode_mobile.setText ("")
27 self.mobilenumber.setText ("")
28 self.email.setText ("")
29 self.areacode.setText ("")
30 self.unspecified.setChecked (True)
31
32 # function to clear professional history in the GUI
33 def reset_professional_history (self):
34 self.reset_profession_fields ()
35 self.professionlist.clear ()
36
37 # function to clear educational qualifications in the GUI
38 def reset_educational_qualifications (self):
39 self.reset_education_fields ()
40 self.educationlist.clear ()
41
42 # function to clear career objectives data in the GUI
43 def reset_career_objectives (self):
44 self.shorttermcareer.setPlainText ("")
45 self.longtermgoals.setPlainText ("")
46
47 # function to clear skill sets data in the GUI
48 def reset_skillsets_info (self):
49 self.reset_skillset_fields ()
50 self.skillslist.clear ()
51
52 # function to clear additional information data in the GUI
53 def reset_additional_info (self):
54 self.reset_language_fields ()
55 self.languageslist.clear ()
56 self.additionalinformation.setPlainText ("")
57
58 # function to clear all the fields and reset them to defaults
59 def new_document (self):
60 # first clear the individual record fields in the tabs
61 self.reset_language_fields ()
62 self.reset_skillset_fields ()
63
64 # clear document data
65 self.title.setText ("")
66
67 self.reset_personal_info ()
68 self.reset_professional_history ()
69 self.reset_educational_qualifications ()
70 self.reset_career_objectives ()
71 self.reset_skillsets_info ()
72 self.reset_additional_info ()
73
74 # set the page to first page
75 self.pages.setCurrentIndex (0)
76
77 # set current file to none and modified to false
78 self.currentfile = None
79 self.ismodified = False
80
81 # file new action is triggered
82 def on_file_new (self):
83 # if the previous document is modified
84 # as if it should be discarded
85 if self.ismodified is True:
86 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM,
87 lang.CONFIRM_DISCARD_SAVE,
88 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
89 if ans == PyQt4.QtGui.QMessageBox.Yes:
90 self.new_document ()
91 # if not modified then simply create a new document
92 else:
93 self.new_document ()
94
95 # when the document is modified
96 def on_document_modified (self):
97 # set the document modified flag
98 self.ismodified = True
99
100 # update a language in the list of languages
101 def on_update_lang (self):
102 # get the selected language
103 selitems = self.languageslist.selectedItems ()
104 if selitems == []:
105 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
106 return
107 # check if the language string is not empty
108 if self.language.text () == "":
109 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
110 return
111 selitem = selitems[0]
112 selitem.setText (0, self.language.text ())
113 selitem.setText (1, str (self.canspeak.isChecked ()))
114 selitem.setText (2, str (self.canreadwrite.isChecked ()))
115 selitem.setText (3, str (self.isproficient.isChecked ()))
116
117 # modified the document
118 self.ismodified = True
119
120 # selecting a language from the list of languages
121 def on_select_lang (self):
122 # set the language fields from the selected item
123 self.set_language_fields ()
124
125 # delete a language from the list of languages known
126 def on_delete_lang (self):
127 # get selected language
128 selitems = self.languageslist.selectedItems ()
129 if selitems == []:
130 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_REQ_MISSING)
131 return
132 # confirm
133 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
134 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
135 if ans == PyQt4.QtGui.QMessageBox.Yes:
136 for item in selitems:
137 self.languageslist.takeTopLevelItem (self.languageslist.indexOfTopLevelItem (item))
138
139 self.reset_language_fields ()
140 # set the modified flag
141 self.ismodified = True
142
143 # add a language to the list of languages known
144 def on_add_lang (self):
145 # check if the language is set
146 if self.language.text () == "":
147 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
148 return
149 langitem = PyQt4.QtGui.QTreeWidgetItem (
150 [
151 self.language.text (),
152 str (self.canspeak.isChecked ()),
153 str (self.canreadwrite.isChecked ()),
154 str (self.isproficient.isChecked ())
155 ]
156 )
157 self.languageslist.addTopLevelItem (langitem)
158 self.reset_language_fields ()
159
160 # set the modified flag
161 self.ismodified = True
162
163 # set the language fields from the selected item
164 def set_language_fields (self):
165 selitems = self.languageslist.selectedItems ()
166 if selitems == []:
167 return
168 selitem = selitems[0]
169 self.language.setText (selitem.text (0))
170 self.canspeak.setChecked (selitem.text (1) == "True")
171 self.canreadwrite.setChecked (selitem.text(2) == "True")
172 self.isproficient.setChecked (selitem.text(3) == "True")
173
174 # reset the language fields
175 def reset_language_fields (self):
176 self.language.setText ("")
177 self.canspeak.setChecked (True)
178 self.canreadwrite.setChecked (False)
179 self.isproficient.setChecked (False)
180
181 # update the skill set button event
182 def on_update_skill (self):
183 # get the selected item
184 selitems = self.skillslist.selectedItems ()
185 if selitems == []:
186 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
187 return
188 if self.skillsettitle.text () == "":
189 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
190 return
191 selitem = selitems[0]
192
193 selitem.setText (0, self.skillsettitle.text ())
194 selitem.setText (1, self.skilldescription.toPlainText ())
195 # set the modified flag
196 self.ismodified = True
197
198 # selecting a skill from the list event
199 def on_select_skill (self):
200 self.set_skill_fields ()
201
202 # set the skill fields from the selected skill from the list
203 def set_skill_fields (self):
204 # get the selected items
205 selitems = self.skillslist.selectedItems ()
206 if selitems == []:
207 return
208 selitem = selitems[0]
209 self.skillsettitle.setText (selitem.text (0))
210 self.skilldescription.setPlainText (selitem.text (1))
211
212 # delete skill set button is clicked
213 def on_delete_skill (self):
214 # get the selected items
215 selitems = self.skillslist.selectedItems ()
216 if selitems == []:
217 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
218 return
219 # confirm
220 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
221 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
222 # answer is yes
223 if ans == PyQt4.QtGui.QMessageBox.Yes:
224 for item in selitems:
225 self.skillslist.takeTopLevelItem (self.skillslist.indexOfTopLevelItem (item))
226
227 self.reset_skillset_fields ()
228 # set the modified flag
229 self.ismodified = True
230
231 # add skill set button is clicked
232 def on_add_skill (self):
233 # if the skill title is blank
234 if self.skillsettitle.text () == "":
235 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
236 return
237 skillitem = PyQt4.QtGui.QTreeWidgetItem (
238 [
239 self.skillsettitle.text (),
240 self.skilldescription.toPlainText ()
241 ]
242 )
243 self.skillslist.addTopLevelItem (skillitem)
244 self.reset_skillset_fields ()
245 # set the modified flag
246 self.ismodified = True
247
248 # clear the skill set fields
249 def reset_skillset_fields (self):
250 self.skillsettitle.setText ("")
251 self.skilldescription.setPlainText ("")
252
253 # update professional history button is clicked
254 def on_update_profession (self):
255 # get the selected item
256 selitems = self.professionlist.selectedItems ()
257 if selitems == []:
258 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
259 return
260 selitem = selitems[0]
261 # if designation is not set
262 if self.designation.text () == "":
263 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
264 return
265 # if currently employed in that position, leaving date is to be disabled
266 # and set to "current"
267 if self.currentemployment.isChecked ():
268 leavedatestr = "current"
269 else:
270 # if the leaving date is < join date
271 if self.leavedate.date () < self.joindate.date ():
272 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
273 return
274 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
275
276 selitem.setText (0, self.designation.text ())
277 selitem.setText (1, self.joindate.date ().toString ("dd MMM, yyyy"))
278 selitem.setText (2, leavedatestr)
279 selitem.setText (3, self.organization.text ())
280 selitem.setText (4, self.additionalinfo.text ())
281 # set the modified flag
282 self.ismodified = True
283
284 # delete professional history button is clicked
285 def on_delete_profession (self):
286 # get the selected items
287 selitems = self.professionlist.selectedItems ()
288 if selitems == []:
289 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
290 return
291 # confirm deletion
292 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
293 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
294 # if confirmed
295 if ans == PyQt4.QtGui.QMessageBox.Yes:
296 for item in selitems:
297 self.professionlist.takeTopLevelItem (self.professionlist.indexOfTopLevelItem (item))
298 self.reset_profession_fields ()
299 # set the modified flag
300 self.ismodified = True
301
302 # add professional history button is clicked
303 def on_add_profession (self):
304 if self.designation.text () == "":
305 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
306 return
307 # if currently employed in that position, leaving date is to be disabled
308 # and set to "current"
309 if self.currentemployment.isChecked ():
310 leavedatestr = "current"
311 else:
312 # if the leaving date is < join date
313 if self.leavedate.date () < self.joindate.date ():
314 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
315 return
316 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
317
318 professionitem = PyQt4.QtGui.QTreeWidgetItem (
319 [
320 self.designation.text (),
321 self.joindate.date ().toString ("dd MMM, yyyy"),
322 leavedatestr,
323 self.organization.text (),
324 self.additionalinfo.text ()
325 ]
326 )
327
328 self.professionlist.addTopLevelItem (professionitem)
329
330 self.reset_profession_fields ()
331 # set the modified flag
332 self.ismodified = True
333
334 # when selection of profession list is changed
335 def on_select_profession (self):
336 self.set_profession_fields ()
337
338 # set the profession fields from the selected item in profession list
339 def set_profession_fields (self):
340 selitems = self.professionlist.selectedItems ()
341 if selitems == []:
342 return
343 selitem = selitems[0]
344 self.designation.setText (selitem.text (0))
345 self.joindate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "dd MMM, yyyy"))
346 if selitem.text (2) == "current":
347 self.leavedate.setEnabled (False)
348 self.currentemployment.setChecked (True)
349 else:
350 self.leavedate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text (2), "dd MMM, yyyy"))
351 self.leavedate.setEnabled (True)
352 self.currentemployment.setChecked (False)
353
354 self.organization.setText (selitem.text (3))
355 self.additionalinfo.setText (selitem.text (4))
356
357 def reset_profession_fields (self):
358 self.designation.setText ("")
359 self.joindate.setDate (PyQt4.QtCore.QDate (2000, 1, 1))
360 self.leavedate.setDate (PyQt4.QtCore.QDate (2003, 1, 1))
361 self.currentemployment.setChecked (False)
362 self.organization.setText ("")
363 self.additionalinfo.setText ("")
364
365 # current employment check box is changed
366 def on_change_currentemployment (self, val):
367 if val == True:
368 self.leavedate.setEnabled (False)
369 else:
370 self.leavedate.setEnabled (True)
371
372 # delete educational qualification
373 def on_delete_education (self):
374 # get the selected items in the education list
375 selitems = self.educationlist.selectedItems ()
376 # if no items are selected
377 if selitems == []:
378 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
379 # delete the items after confirmation
380 else:
381 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
382 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
383 if ans == PyQt4.QtGui.QMessageBox.Yes:
384 # remove the item selected
385 for item in selitems:
386 self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
387 self.reset_education_fields ()
388 # set the modified flag
389 self.ismodified = True
390
391 # selection is changed
392 def on_select_education (self):
393 self.set_education_fields ()
394
395 # update educational qualification button
396 def on_update_education (self):
397 selitems = self.educationlist.selectedItems ()
398 # if no item is selected
399 if selitems == []:
400 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
401 return
402 # if the qualification title is not set
403 if self.degree_name.text () == "":
404 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
405 return
406 selitem = selitems[0]
407
408 selitem.setText (0, self.degree_name.text ())
409 selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
410 selitem.setText (2, self.institution.text ())
411 selitem.setText (3, self.university.text ())
412 selitem.setText (4, self.grade.text ())
413 selitem.setText (5, str (self.percentage.value ()))
414 # set the modified flag
415 self.ismodified = True
416
417 # add educational qualification button
418 def on_add_education (self):
419 # check if the qualification title is set
420 if self.degree_name.text () == "":
421 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
422 return
423 educationitem = PyQt4.QtGui.QTreeWidgetItem ([
424 self.degree_name.text (),
425 self.yearofpassing.date ().toString ("MMM, yyyy"),
426 self.institution.text (),
427 self.university.text (),
428 self.grade.text (),
429 str (self.percentage.value ())
430 ])
431 self.educationlist.addTopLevelItem (educationitem)
432 # clear the fields
433 self.reset_education_fields ()
434 # set the modified flag
435 self.ismodified = True
436
437 # set fields in the education tab from current selected item
438 def set_education_fields (self):
439 selitems = self.educationlist.selectedItems ()
440 if selitems == []:
441 return
442 selitem = selitems[0]
443 # set the fields to the data in the selected item in the list
444 self.degree_name.setText (selitem.text (0))
445 self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
446 self.institution.setText (selitem.text (2))
447 self.university.setText (selitem.text (3))
448 self.grade.setText (selitem.text(4))
449 self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
450
451 # reset fields in the education tab
452 def reset_education_fields (self):
453 self.degree_name.setText ("")
454 self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
455 self.institution.setText ("")
456 self.university.setText ("")
457 self.grade.setText ("")
458 self.percentage.setValue (50.0)
459