Delete professional history item done
[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 professional history button is clicked
13 def on_delete_profession (self):
14 # get the selected items
15 selitems = self.professionlist.selectedItems ()
16 if selitems == []:
17 PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No item selected.")
18 return
19 # confirm deletion
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 # if confirmed
24 if ans == PyQt4.QtGui.QMessageBox.Yes:
25 for item in selitems:
26 self.professionlist.takeTopLevelItem (self.professionlist.indexOfTopLevelItem (item))
27 self.reset_profession_fields ()
28
29 # add professional history button is clicked
30 def on_add_profession (self):
31 if self.designation.text () == "":
32 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required field is missing.")
33 return
34
35 if self.currentemployment.isChecked ():
36 leavedatestr = "current"
37 else:
38 leavedatestr = self.leavedate.date ().toString ("dd MMM, yyyy")
39
40 professionitem = PyQt4.QtGui.QTreeWidgetItem (
41 [
42 self.designation.text (),
43 self.joindate.date ().toString ("dd MMM, yyyy"),
44 leavedatestr,
45 self.organization.text (),
46 self.additionalinfo.text ()
47 ]
48 )
49
50 self.professionlist.addTopLevelItem (professionitem)
51
52 self.reset_profession_fields ()
53
54 # when selection of profession list is changed
55 def on_select_profession (self):
56 self.set_profession_fields ()
57
58 # set the profession fields from the selected item in profession list
59 def set_profession_fields (self):
60 selitems = self.professionlist.selectedItems ()
61 if selitems == []:
62 return
63 selitem = selitems[0]
64 self.designation.setText (selitem.text (0))
65 self.joindate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "dd MMM, yyyy"))
66 if selitem.text (2) == "current":
67 self.leavedate.setEnabled (False)
68 self.currentemployment.setChecked (True)
69 else:
70 self.leavedate.setDate (PyQt4.QtCore.QDate.fromString (selitem.text (2), "dd MMM, yyyy"))
71 self.leavedate.setEnabled (True)
72 self.currentemployment.setChecked (False)
73
74 self.organization.setText (selitem.text (3))
75 self.additionalinfo.setText (selitem.text (4))
76
77 def reset_profession_fields (self):
78 self.designation.setText ("")
79 self.joindate.setDate (PyQt4.QtCore.QDate (2000, 1, 1))
80 self.leavedate.setDate (PyQt4.QtCore.QDate (2003, 1, 1))
81 self.currentemployment.setChecked (False)
82 self.organization.setText ("")
83 self.additionalinfo.setText ("")
84
85 # current employment check box is changed
86 def on_change_currentemployment (self, val):
87 if val == True:
88 self.leavedate.setEnabled (False)
89 else:
90 self.leavedate.setEnabled (True)
91
92 # delete educational qualification
93 def on_delete_education (self):
94 # get the selected items in the education list
95 selitems = self.educationlist.selectedItems ()
96 # if no items are selected
97 if selitems == []:
98 PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
99 # delete the items after confirmation
100 else:
101 ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
102 "Are you sure you wish to delete selected item?",
103 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
104 if ans == PyQt4.QtGui.QMessageBox.Yes:
105 # remove the item selected
106 for item in selitems:
107 self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
108 self.reset_education_fields ()
109
110 # selection is changed
111 def on_select_education (self):
112 self.set_education_fields ()
113
114 # update educational qualification button
115 def on_update_education (self):
116 selitems = self.educationlist.selectedItems ()
117 # if no item is selected
118 if selitems == []:
119 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected")
120 return
121 # if the qualification title is not set
122 if self.degree_name.text () == "":
123 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
124 return
125 selitem = selitems[0]
126
127 selitem.setText (0, self.degree_name.text ())
128 selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
129 selitem.setText (2, self.institution.text ())
130 selitem.setText (3, self.university.text ())
131 selitem.setText (4, self.grade.text ())
132 selitem.setText (5, str (self.percentage.value ()))
133
134 # add educational qualification button
135 def on_add_education (self):
136 # check if the qualification title is set
137 if self.degree_name.text () == "":
138 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required fields is missing.")
139 return
140 educationitem = PyQt4.QtGui.QTreeWidgetItem ([
141 self.degree_name.text (),
142 self.yearofpassing.date ().toString ("MMM, yyyy"),
143 self.institution.text (),
144 self.university.text (),
145 self.grade.text (),
146 str (self.percentage.value ())
147 ])
148 self.educationlist.addTopLevelItem (educationitem)
149 # clear the fields
150 self.reset_education_fields ()
151
152 # set fields in the education tab from current selected item
153 def set_education_fields (self):
154 selitems = self.educationlist.selectedItems ()
155 if selitems == []:
156 return
157 selitem = selitems[0]
158 # set the fields to the data in the selected item in the list
159 self.degree_name.setText (selitem.text (0))
160 self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
161 self.institution.setText (selitem.text (2))
162 self.university.setText (selitem.text (3))
163 self.grade.setText (selitem.text(4))
164 self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
165
166 # reset fields in the education tab
167 def reset_education_fields (self):
168 self.degree_name.setText ("")
169 self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
170 self.institution.setText ("")
171 self.university.setText ("")
172 self.grade.setText ("")
173 self.percentage.setValue (50.0)
174