Delete skill set implemented
[biacv.git] / biacv_mainwindow.py
1 # class for main window
2
3 import PyQt4
4 import biacv_mainwindow_ui as bui
5
6 class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
7 def __init__ (self):
8 PyQt4.QtGui.QMainWindow.__init__ (self)
9 self.setupUi (self)
10 self.currentfile = None
11
12 # delete skill set button is clicked
13 def on_delete_skill (self):
14 # get the selected items
15 selitems = self.skillslist.selectedItems ()
16 if selitems == []:
17 PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
18 return
19 # confirm
20 ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
21 "Are you sure you wish to delete the selected item?",
22 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
23 # answer is yes
24 if ans == PyQt4.QtGui.QMessageBox.Yes:
25 for item in selitems:
26 self.skillslist.takeTopLevelItem (self.skillslist.indexOfTopLevelItem (item))
27
28 self.reset_skillset_fields ()
29
30 # add skill set button is clicked
31 def on_add_skill (self):
32 # if the skill title is blank
33 if self.skillsettitle.text () == "":
34 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required field is missing.")
35 return
36 skillitem = PyQt4.QtGui.QTreeWidgetItem (
37 [
38 self.skillsettitle.text (),
39 self.skilldescription.toPlainText ()
40 ]
41 )
42 self.skillslist.addTopLevelItem (skillitem)
43 self.reset_skillset_fields ()
44
45 # clear the skill set fields
46 def reset_skillset_fields (self):
47 self.skillsettitle.setText ("")
48 self.skilldescription.setPlainText ("")
49
50 # update professional history button is clicked
51 def on_update_profession (self):
52 # get the selected item
53 selitems = self.professionlist.selectedItems ()
54 if selitems == []:
55 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected.")
56 return
57 selitem = selitems[0]
58 # if designation is not set
59 if self.designation.text () == "":
60 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
61 return
62 # if currently employed in that position, leaving date is to be disabled
63 # and set to "current"
64 if self.currentemployment.isChecked ():
65 leavedatestr = "current"
66 else:
67 # if the leaving date is < join date
68 if self.leavedate.date () < self.joindate.date ():
69 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add",
70 "Leaving date cannot be earlier than join date.")
71 return
72 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
73
74 selitem.setText (0, self.designation.text ())
75 selitem.setText (1, self.joindate.date ().toString ("dd MMM, yyyy"))
76 selitem.setText (2, leavedatestr)
77 selitem.setText (3, self.organization.text ())
78 selitem.setText (4, self.additionalinfo.text ())
79
80 # delete professional history button is clicked
81 def on_delete_profession (self):
82 # get the selected items
83 selitems = self.professionlist.selectedItems ()
84 if selitems == []:
85 PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No item selected.")
86 return
87 # confirm deletion
88 ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
89 "Are you sure you wish to delete the selected item?",
90 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
91 # if confirmed
92 if ans == PyQt4.QtGui.QMessageBox.Yes:
93 for item in selitems:
94 self.professionlist.takeTopLevelItem (self.professionlist.indexOfTopLevelItem (item))
95 self.reset_profession_fields ()
96
97 # add professional history button is clicked
98 def on_add_profession (self):
99 if self.designation.text () == "":
100 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required field is missing.")
101 return
102 # if currently employed in that position, leaving date is to be disabled
103 # and set to "current"
104 if self.currentemployment.isChecked ():
105 leavedatestr = "current"
106 else:
107 # if the leaving date is < join date
108 if self.leavedate.date () < self.joindate.date ():
109 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add",
110 "Leaving date cannot be earlier than join date.")
111 return
112 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
113
114 professionitem = PyQt4.QtGui.QTreeWidgetItem (
115 [
116 self.designation.text (),
117 self.joindate.date ().toString ("dd MMM, yyyy"),
118 leavedatestr,
119 self.organization.text (),
120 self.additionalinfo.text ()
121 ]
122 )
123
124 self.professionlist.addTopLevelItem (professionitem)
125
126 self.reset_profession_fields ()
127
128 # when selection of profession list is changed
129 def on_select_profession (self):
130 self.set_profession_fields ()
131
132 # set the profession fields from the selected item in profession list
133 def set_profession_fields (self):
134 selitems = self.professionlist.selectedItems ()
135 if selitems == []:
136 return
137 selitem = selitems[0]
138 self.designation.setText (selitem.text (0))
139 self.joindate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "dd MMM, yyyy"))
140 if selitem.text (2) == "current":
141 self.leavedate.setEnabled (False)
142 self.currentemployment.setChecked (True)
143 else:
144 self.leavedate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text (2), "dd MMM, yyyy"))
145 self.leavedate.setEnabled (True)
146 self.currentemployment.setChecked (False)
147
148 self.organization.setText (selitem.text (3))
149 self.additionalinfo.setText (selitem.text (4))
150
151 def reset_profession_fields (self):
152 self.designation.setText ("")
153 self.joindate.setDate (PyQt4.QtCore.QDate (2000, 1, 1))
154 self.leavedate.setDate (PyQt4.QtCore.QDate (2003, 1, 1))
155 self.currentemployment.setChecked (False)
156 self.organization.setText ("")
157 self.additionalinfo.setText ("")
158
159 # current employment check box is changed
160 def on_change_currentemployment (self, val):
161 if val == True:
162 self.leavedate.setEnabled (False)
163 else:
164 self.leavedate.setEnabled (True)
165
166 # delete educational qualification
167 def on_delete_education (self):
168 # get the selected items in the education list
169 selitems = self.educationlist.selectedItems ()
170 # if no items are selected
171 if selitems == []:
172 PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
173 # delete the items after confirmation
174 else:
175 ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
176 "Are you sure you wish to delete selected item?",
177 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
178 if ans == PyQt4.QtGui.QMessageBox.Yes:
179 # remove the item selected
180 for item in selitems:
181 self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
182 self.reset_education_fields ()
183
184 # selection is changed
185 def on_select_education (self):
186 self.set_education_fields ()
187
188 # update educational qualification button
189 def on_update_education (self):
190 selitems = self.educationlist.selectedItems ()
191 # if no item is selected
192 if selitems == []:
193 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected")
194 return
195 # if the qualification title is not set
196 if self.degree_name.text () == "":
197 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
198 return
199 selitem = selitems[0]
200
201 selitem.setText (0, self.degree_name.text ())
202 selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
203 selitem.setText (2, self.institution.text ())
204 selitem.setText (3, self.university.text ())
205 selitem.setText (4, self.grade.text ())
206 selitem.setText (5, str (self.percentage.value ()))
207
208 # add educational qualification button
209 def on_add_education (self):
210 # check if the qualification title is set
211 if self.degree_name.text () == "":
212 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required fields is missing.")
213 return
214 educationitem = PyQt4.QtGui.QTreeWidgetItem ([
215 self.degree_name.text (),
216 self.yearofpassing.date ().toString ("MMM, yyyy"),
217 self.institution.text (),
218 self.university.text (),
219 self.grade.text (),
220 str (self.percentage.value ())
221 ])
222 self.educationlist.addTopLevelItem (educationitem)
223 # clear the fields
224 self.reset_education_fields ()
225
226 # set fields in the education tab from current selected item
227 def set_education_fields (self):
228 selitems = self.educationlist.selectedItems ()
229 if selitems == []:
230 return
231 selitem = selitems[0]
232 # set the fields to the data in the selected item in the list
233 self.degree_name.setText (selitem.text (0))
234 self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
235 self.institution.setText (selitem.text (2))
236 self.university.setText (selitem.text (3))
237 self.grade.setText (selitem.text(4))
238 self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
239
240 # reset fields in the education tab
241 def reset_education_fields (self):
242 self.degree_name.setText ("")
243 self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
244 self.institution.setText ("")
245 self.university.setText ("")
246 self.grade.setText ("")
247 self.percentage.setValue (50.0)
248