Update educational qualifications completed
[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 educational qualification
13 def on_delete_education (self):
14 # get the selected items in the education list
15 selitems = self.educationlist.selectedItems ()
16 # if no items are selected
17 if selitems == []:
18 PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
19 # delete the items after confirmation
20 else:
21 ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
22 "Are you sure you wish to delete selected item?",
23 PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
24 if ans == PyQt4.QtGui.QMessageBox.Yes:
25 # remove the item selected
26 for item in selitems:
27 self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
28 self.reset_education_fields ()
29
30 # selection is changed
31 def on_select_education (self):
32 self.set_education_fields ()
33
34 # update educational qualification button
35 def on_update_education (self):
36 selitems = self.educationlist.selectedItems ()
37 # if no item is selected
38 if selitems == []:
39 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected")
40 return
41 # if the qualification title is not set
42 if self.degree_name.text () == "":
43 PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
44 return
45 selitem = selitems[0]
46
47 selitem.setText (0, self.degree_name.text ())
48 selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
49 selitem.setText (2, self.institution.text ())
50 selitem.setText (3, self.university.text ())
51 selitem.setText (4, self.grade.text ())
52 selitem.setText (5, str (self.percentage.value ()))
53
54 # add educational qualification button
55 def on_add_education (self):
56 # check if the qualification title is set
57 if self.degree_name.text () == "":
58 PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required fields is missing.")
59 else:
60 educationitem = PyQt4.QtGui.QTreeWidgetItem ([
61 self.degree_name.text (),
62 self.yearofpassing.date ().toString ("MMM, yyyy"),
63 self.institution.text (),
64 self.university.text (),
65 self.grade.text (),
66 str (self.percentage.value ())
67 ])
68 self.educationlist.addTopLevelItem (educationitem)
69 # clear the fields
70 self.reset_education_fields ()
71
72 # set fields in the education tab from current selected item
73 def set_education_fields (self):
74 selitems = self.educationlist.selectedItems ()
75 if selitems == []:
76 return
77 selitem = selitems[0]
78 # set the fields to the data in the selected item in the list
79 self.degree_name.setText (selitem.text (0))
80 self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
81 self.institution.setText (selitem.text (2))
82 self.university.setText (selitem.text (3))
83 self.grade.setText (selitem.text(4))
84 self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
85
86 # reset fields in the education tab
87 def reset_education_fields (self):
88 self.degree_name.setText ("")
89 self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
90 self.institution.setText ("")
91 self.university.setText ("")
92 self.grade.setText ("")
93 self.percentage.setValue (50.0)
94