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