Implemented document save status flag
[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 # when the document is modified
16 def on_document_modified (self):
17 # set the document modified flag
18 self.ismodified = True
19 print "True"
20
21 # update a language in the list of languages
22 def on_update_lang (self):
23 # get the selected language
24 selitems = self.languageslist.selectedItems ()
25 if selitems == []:
26 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
27 return
28 # check if the language string is not empty
29 if self.language.text () == "":
30 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
31 return
32 selitem = selitems[0]
33 selitem.setText (0, self.language.text ())
34 selitem.setText (1, str (self.canspeak.isChecked ()))
35 selitem.setText (2, str (self.canreadwrite.isChecked ()))
36 selitem.setText (3, str (self.isproficient.isChecked ()))
37
38 # modified the document
39 self.ismodified = True
40
41 # selecting a language from the list of languages
42 def on_select_lang (self):
43 # set the language fields from the selected item
44 self.set_language_fields ()
45
46 # delete a language from the list of languages known
47 def on_delete_lang (self):
48 # get selected language
49 selitems = self.languageslist.selectedItems ()
50 if selitems == []:
51 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_REQ_MISSING)
52 return
53 # confirm
54 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
55 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
56 if ans == PyQt4.QtGui.QMessageBox.Yes:
57 for item in selitems:
58 self.languageslist.takeTopLevelItem (self.languageslist.indexOfTopLevelItem (item))
59
60 self.reset_language_fields ()
61 # set the modified flag
62 self.ismodified = True
63
64 # add a language to the list of languages known
65 def on_add_lang (self):
66 # check if the language is set
67 if self.language.text () == "":
68 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
69 return
70 langitem = PyQt4.QtGui.QTreeWidgetItem (
71 [
72 self.language.text (),
73 str (self.canspeak.isChecked ()),
74 str (self.canreadwrite.isChecked ()),
75 str (self.isproficient.isChecked ())
76 ]
77 )
78 self.languageslist.addTopLevelItem (langitem)
79 self.reset_language_fields ()
80
81 # set the modified flag
82 self.ismodified = True
83
84 # set the language fields from the selected item
85 def set_language_fields (self):
86 selitems = self.languageslist.selectedItems ()
87 if selitems == []:
88 return
89 selitem = selitems[0]
90 self.language.setText (selitem.text (0))
91 self.canspeak.setChecked (selitem.text (1) == "True")
92 self.canreadwrite.setChecked (selitem.text(2) == "True")
93 self.isproficient.setChecked (selitem.text(3) == "True")
94
95 # reset the language fields
96 def reset_language_fields (self):
97 self.language.setText ("")
98 self.canspeak.setChecked (True)
99 self.canreadwrite.setChecked (False)
100 self.isproficient.setChecked (False)
101
102 # update the skill set button event
103 def on_update_skill (self):
104 # get the selected item
105 selitems = self.skillslist.selectedItems ()
106 if selitems == []:
107 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
108 return
109 if self.skillsettitle.text () == "":
110 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
111 return
112 selitem = selitems[0]
113
114 selitem.setText (0, self.skillsettitle.text ())
115 selitem.setText (1, self.skilldescription.toPlainText ())
116 # set the modified flag
117 self.ismodified = True
118
119 # selecting a skill from the list event
120 def on_select_skill (self):
121 self.set_skill_fields ()
122
123 # set the skill fields from the selected skill from the list
124 def set_skill_fields (self):
125 # get the selected items
126 selitems = self.skillslist.selectedItems ()
127 if selitems == []:
128 return
129 selitem = selitems[0]
130 self.skillsettitle.setText (selitem.text (0))
131 self.skilldescription.setPlainText (selitem.text (1))
132
133 # delete skill set button is clicked
134 def on_delete_skill (self):
135 # get the selected items
136 selitems = self.skillslist.selectedItems ()
137 if selitems == []:
138 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
139 return
140 # confirm
141 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
142 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
143 # answer is yes
144 if ans == PyQt4.QtGui.QMessageBox.Yes:
145 for item in selitems:
146 self.skillslist.takeTopLevelItem (self.skillslist.indexOfTopLevelItem (item))
147
148 self.reset_skillset_fields ()
149 # set the modified flag
150 self.ismodified = True
151
152 # add skill set button is clicked
153 def on_add_skill (self):
154 # if the skill title is blank
155 if self.skillsettitle.text () == "":
156 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
157 return
158 skillitem = PyQt4.QtGui.QTreeWidgetItem (
159 [
160 self.skillsettitle.text (),
161 self.skilldescription.toPlainText ()
162 ]
163 )
164 self.skillslist.addTopLevelItem (skillitem)
165 self.reset_skillset_fields ()
166 # set the modified flag
167 self.ismodified = True
168
169 # clear the skill set fields
170 def reset_skillset_fields (self):
171 self.skillsettitle.setText ("")
172 self.skilldescription.setPlainText ("")
173
174 # update professional history button is clicked
175 def on_update_profession (self):
176 # get the selected item
177 selitems = self.professionlist.selectedItems ()
178 if selitems == []:
179 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
180 return
181 selitem = selitems[0]
182 # if designation is not set
183 if self.designation.text () == "":
184 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
185 return
186 # if currently employed in that position, leaving date is to be disabled
187 # and set to "current"
188 if self.currentemployment.isChecked ():
189 leavedatestr = "current"
190 else:
191 # if the leaving date is < join date
192 if self.leavedate.date () < self.joindate.date ():
193 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
194 return
195 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
196
197 selitem.setText (0, self.designation.text ())
198 selitem.setText (1, self.joindate.date ().toString ("dd MMM, yyyy"))
199 selitem.setText (2, leavedatestr)
200 selitem.setText (3, self.organization.text ())
201 selitem.setText (4, self.additionalinfo.text ())
202 # set the modified flag
203 self.ismodified = True
204
205 # delete professional history button is clicked
206 def on_delete_profession (self):
207 # get the selected items
208 selitems = self.professionlist.selectedItems ()
209 if selitems == []:
210 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
211 return
212 # confirm deletion
213 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
214 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
215 # if confirmed
216 if ans == PyQt4.QtGui.QMessageBox.Yes:
217 for item in selitems:
218 self.professionlist.takeTopLevelItem (self.professionlist.indexOfTopLevelItem (item))
219 self.reset_profession_fields ()
220 # set the modified flag
221 self.ismodified = True
222
223 # add professional history button is clicked
224 def on_add_profession (self):
225 if self.designation.text () == "":
226 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
227 return
228 # if currently employed in that position, leaving date is to be disabled
229 # and set to "current"
230 if self.currentemployment.isChecked ():
231 leavedatestr = "current"
232 else:
233 # if the leaving date is < join date
234 if self.leavedate.date () < self.joindate.date ():
235 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_DATE)
236 return
237 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
238
239 professionitem = PyQt4.QtGui.QTreeWidgetItem (
240 [
241 self.designation.text (),
242 self.joindate.date ().toString ("dd MMM, yyyy"),
243 leavedatestr,
244 self.organization.text (),
245 self.additionalinfo.text ()
246 ]
247 )
248
249 self.professionlist.addTopLevelItem (professionitem)
250
251 self.reset_profession_fields ()
252 # set the modified flag
253 self.ismodified = True
254
255 # when selection of profession list is changed
256 def on_select_profession (self):
257 self.set_profession_fields ()
258
259 # set the profession fields from the selected item in profession list
260 def set_profession_fields (self):
261 selitems = self.professionlist.selectedItems ()
262 if selitems == []:
263 return
264 selitem = selitems[0]
265 self.designation.setText (selitem.text (0))
266 self.joindate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "dd MMM, yyyy"))
267 if selitem.text (2) == "current":
268 self.leavedate.setEnabled (False)
269 self.currentemployment.setChecked (True)
270 else:
271 self.leavedate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text (2), "dd MMM, yyyy"))
272 self.leavedate.setEnabled (True)
273 self.currentemployment.setChecked (False)
274
275 self.organization.setText (selitem.text (3))
276 self.additionalinfo.setText (selitem.text (4))
277
278 def reset_profession_fields (self):
279 self.designation.setText ("")
280 self.joindate.setDate (PyQt4.QtCore.QDate (2000, 1, 1))
281 self.leavedate.setDate (PyQt4.QtCore.QDate (2003, 1, 1))
282 self.currentemployment.setChecked (False)
283 self.organization.setText ("")
284 self.additionalinfo.setText ("")
285
286 # current employment check box is changed
287 def on_change_currentemployment (self, val):
288 if val == True:
289 self.leavedate.setEnabled (False)
290 else:
291 self.leavedate.setEnabled (True)
292
293 # delete educational qualification
294 def on_delete_education (self):
295 # get the selected items in the education list
296 selitems = self.educationlist.selectedItems ()
297 # if no items are selected
298 if selitems == []:
299 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_DELETE, lang.ERROR_NO_SELECTION)
300 # delete the items after confirmation
301 else:
302 ans = PyQt4.QtGui.QMessageBox.question (self, lang.CONFIRM, lang.CONFIRM_DELETE,
303 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
304 if ans == PyQt4.QtGui.QMessageBox.Yes:
305 # remove the item selected
306 for item in selitems:
307 self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
308 self.reset_education_fields ()
309 # set the modified flag
310 self.ismodified = True
311
312 # selection is changed
313 def on_select_education (self):
314 self.set_education_fields ()
315
316 # update educational qualification button
317 def on_update_education (self):
318 selitems = self.educationlist.selectedItems ()
319 # if no item is selected
320 if selitems == []:
321 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_NO_SELECTION)
322 return
323 # if the qualification title is not set
324 if self.degree_name.text () == "":
325 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_UPDATE, lang.ERROR_REQ_MISSING)
326 return
327 selitem = selitems[0]
328
329 selitem.setText (0, self.degree_name.text ())
330 selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
331 selitem.setText (2, self.institution.text ())
332 selitem.setText (3, self.university.text ())
333 selitem.setText (4, self.grade.text ())
334 selitem.setText (5, str (self.percentage.value ()))
335 # set the modified flag
336 self.ismodified = True
337
338 # add educational qualification button
339 def on_add_education (self):
340 # check if the qualification title is set
341 if self.degree_name.text () == "":
342 PyQt4.QtGui.QMessageBox.critical (self, lang.ERROR_ADD, lang.ERROR_REQ_MISSING)
343 return
344 educationitem = PyQt4.QtGui.QTreeWidgetItem ([
345 self.degree_name.text (),
346 self.yearofpassing.date ().toString ("MMM, yyyy"),
347 self.institution.text (),
348 self.university.text (),
349 self.grade.text (),
350 str (self.percentage.value ())
351 ])
352 self.educationlist.addTopLevelItem (educationitem)
353 # clear the fields
354 self.reset_education_fields ()
355 # set the modified flag
356 self.ismodified = True
357
358 # set fields in the education tab from current selected item
359 def set_education_fields (self):
360 selitems = self.educationlist.selectedItems ()
361 if selitems == []:
362 return
363 selitem = selitems[0]
364 # set the fields to the data in the selected item in the list
365 self.degree_name.setText (selitem.text (0))
366 self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
367 self.institution.setText (selitem.text (2))
368 self.university.setText (selitem.text (3))
369 self.grade.setText (selitem.text(4))
370 self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
371
372 # reset fields in the education tab
373 def reset_education_fields (self):
374 self.degree_name.setText ("")
375 self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
376 self.institution.setText ("")
377 self.university.setText ("")
378 self.grade.setText ("")
379 self.percentage.setValue (50.0)
380