-
Notifications
You must be signed in to change notification settings - Fork 0
/
fet.py
executable file
·122 lines (86 loc) · 2.95 KB
/
fet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui, uic
from gestib import ImportGestib
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = uic.loadUi("mainwindow.ui",self)
self.connect(self.ui.but_import_gestib,
QtCore.SIGNAL("clicked()"), self.doImportGestib)
self.connect(self.ui.but_export_fet,
QtCore.SIGNAL("clicked()"), self.doExportFet)
self.connect(self.ui.but_delete_courses,
QtCore.SIGNAL("clicked()"), self.deleteCourses)
self.connect(self.ui.but_delete_profs,
QtCore.SIGNAL("clicked()"), self.deleteProfs)
self.importGestib = None
self.updateButtons()
def log(self,string):
self.ui.console.append(string)
def deleteCourses(self):
clist = self.ui.courseList.selectedItems()
for c in clist:
self.importGestib.deleteCourse(unicode(c.text()))
self.ui.courseList.takeItem(self.ui.courseList.row(c))
self.log("Eliminat curs " + c.text())
def deleteProfs(self):
plist = self.ui.profList.selectedItems()
for p in plist:
self.importGestib.deleteProf(unicode(p.text()))
self.ui.profList.takeItem(self.ui.profList.row(p))
self.log("Eliminat professor " + p.text())
def updateButtons(self):
if self.importGestib:
self.ui.but_import_gestib.setEnabled(1)
self.ui.but_export_fet.setEnabled(1)
self.ui.but_delete_courses.setEnabled(1)
self.ui.but_delete_profs.setEnabled(1)
else:
self.ui.but_import_gestib.setEnabled(1)
self.ui.but_export_fet.setEnabled(0)
self.ui.but_delete_courses.setEnabled(0)
self.ui.but_delete_profs.setEnabled(0)
def doImportGestib(self):
self.importGestib = None
filename = QtGui.QFileDialog.getOpenFileName(self,
QtCore.QString("Fitxer gestib"), QtCore.QString(), "XML files (*.xml)")
if filename == '':
self.updateButtons()
return
try:
self.importGestib = ImportGestib(unicode(filename))
self.log('Fitxer ' + filename + ' carregat correctament')
self.updateButtons()
groups = self.importGestib.getGroups()
for g in groups:
self.ui.courseList.addItem(g)
profs = self.importGestib.getProfs()
for p in profs:
self.ui.profList.addItem(p)
except:
msgbox = QtGui.QMessageBox( self )
msgbox.setText( "Error: %s" % sys.exc_info()[0] )
msgbox.setModal( True )
ret = msgbox.exec_()
def doExportFet(self):
filename = QtGui.QFileDialog.getSaveFileName(self,
QtCore.QString("Fitxer FET"), QtCore.QString(), "XML FET (*.fet)")
if filename == '':
return
try:
fn = unicode(filename)
self.importGestib.parse()
self.importGestib.writeToFile(fn)
self.log('Fitxer ' + fn + ' exportat correctament')
except:
msgbox = QtGui.QMessageBox( self )
msgbox.setText( "Error: %s" % sys.exc_info()[0] )
msgbox.setModal( True )
ret = msgbox.exec_()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
app.exec_()