00001
00002
00003
00004 licence={}
00005 licence['en']="""
00006 file choixEleves.py
00007 this file is part of the project scolasync
00008
00009 Copyright (C) 2012 Georges Khaznadar <georgesk@ofset.org>
00010
00011 This program is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU General Public License as published by
00013 the Free Software Foundation, either version3 of the License, or
00014 (at your option) any later version.
00015
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 GNU General Public License for more details.
00020
00021 You should have received a copy of the GNU General Public License
00022 along with this program. If not, see <http://www.gnu.org/licenses/>.
00023 """
00024
00025 import gestClasse
00026 from PyQt4.QtGui import *
00027 from PyQt4.QtCore import *
00028 from Ui_choixEleves import Ui_Dialog
00029 import db
00030 import sys, os.path
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class choixElevesDialog(QDialog):
00041
00042
00043
00044
00045
00046
00047
00048
00049 def __init__(self, parent=None, gestionnaire=gestClasse.Sconet):
00050 QDialog.__init__(self, parent=parent)
00051 self.ok=None
00052 self.ui=Ui_Dialog()
00053 self.ui.setupUi(self)
00054 self.prefs=db.readPrefs()
00055 self.gestionnaire=gestionnaire
00056 self.connecteGestionnaire()
00057 self.ui.listWidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
00058 self.ui.listWidget.setSortingEnabled(True)
00059 self.ui.checkBoxNumero.setChecked(True)
00060 self.ui.spinBoxNumero.setValue(1)
00061 self.ui.spinBoxNumero.setEnabled(True)
00062 self.connect(self.ui.pushButtonFile, SIGNAL('clicked()'), self.fichierEleves)
00063 self.connect(self.ui.pushButton_replierArbre, SIGNAL("clicked()"), self.replie)
00064 self.connect(self.ui.pushButton_cocher, SIGNAL("clicked()"), self.coche)
00065 self.connect(self.ui.pushButton_decocher, SIGNAL("clicked()"), self.decoche)
00066 self.connect(self.ui.pushButton_addToList, SIGNAL("clicked()"), self.addToList)
00067 self.connect(self.ui.pushButton_delInList, SIGNAL("clicked()"), self.delInList)
00068 self.connect(self.ui.pushButton_OK, SIGNAL("clicked()"), self.valid)
00069 self.connect(self.ui.pushButton_Esc, SIGNAL("clicked()"), self.escape)
00070 self.connect(self.ui.checkBoxNumero, SIGNAL("stateChanged(int)"), self.checkNum)
00071
00072
00073
00074
00075
00076 def fichierEleves(self):
00077 caption="Choisissez un nouveau fichier de gestion des élèves"
00078 dirname=os.path.dirname(self.prefs["schoolFile"])
00079 newFile=QFileDialog.getOpenFileName (self, caption, dirname)
00080 if os.path.exists(newFile):
00081 self.prefs["schoolFile"]="%s" %newFile.toUtf8()
00082 db.writePrefs(self.prefs)
00083 self.connecteGestionnaire(renew=True)
00084 return
00085
00086
00087
00088
00089
00090
00091 def connecteGestionnaire(self, renew=False):
00092 try:
00093 self.ui.lineEditFile.setText(self.prefs["schoolFile"])
00094 self.ui.treeView.connecteGestionnaire(self.prefs["schoolFile"],
00095 self.gestionnaire,
00096 renew=renew)
00097 except:
00098 QMessageBox.warning(None,
00099 QApplication.translate("Dialog","Échec à l'ouverture du fichier élèves",None, QApplication.UnicodeUTF8),
00100 QApplication.translate("Dialog","Le fichier %1 n'a pas pu être traité",None, QApplication.UnicodeUTF8).arg(self.prefs["schoolFile"]))
00101
00102
00103
00104
00105
00106
00107
00108 def checkNum(self, state):
00109 if state==Qt.Checked:
00110 self.ui.spinBoxNumero.setEnabled(True)
00111 else:
00112 self.ui.spinBoxNumero.setEnabled(False)
00113 return
00114
00115
00116
00117
00118
00119 def replie(self):
00120 self.ui.treeView.collapseAll()
00121 return
00122
00123
00124
00125
00126
00127 def coche(self):
00128 for e in self.ui.treeView.expandedItems():
00129 e.setCheckState(Qt.Checked)
00130 return
00131
00132
00133
00134
00135
00136 def decoche(self):
00137 for e in self.ui.treeView.expandedItems():
00138 e.setCheckState(Qt.Unchecked)
00139 return
00140
00141
00142
00143
00144
00145
00146 def updateParentIcon(self):
00147 self.parent().setAvailableNames(self.ui.listWidget.count() > 0)
00148 return
00149
00150
00151
00152
00153
00154 def addToList(self):
00155 for n in self.listeUnique_Names():
00156 if not self.ui.listWidget.findItems(n,Qt.MatchExactly):
00157 self.ui.listWidget.addItem(n)
00158 self.updateParentIcon()
00159 return
00160
00161
00162
00163
00164
00165 def delInList(self):
00166 rows=[]
00167 for i in self.ui.listWidget.selectedIndexes():
00168 rows.append(i.row())
00169 rows.sort(reverse=True)
00170 for r in rows:
00171 self.ui.listWidget.takeItem(r)
00172 self.updateParentIcon()
00173 return
00174
00175
00176
00177
00178
00179
00180
00181 def pop(self):
00182 if self.count() == 0:
00183 return
00184 i=self.ui.listWidget.takeItem(0)
00185 self.updateParentIcon()
00186 return i.data(Qt.DisplayRole).toString()
00187
00188
00189
00190
00191
00192 def itemStrings(self):
00193 itemList=self.ui.listWidget.findItems(QString("*"),Qt.MatchWrap | Qt.MatchWildcard)
00194 l=[i.data(Qt.DisplayRole).toString() for i in itemList]
00195 l.sort()
00196 return l
00197
00198
00199
00200
00201
00202
00203
00204 def takeItem(self, item):
00205 found=self.ui.listWidget.findItems(item,Qt.MatchExactly)
00206 if len(found) > 0:
00207 r=self.ui.listWidget.row(found[0])
00208 i=self.ui.listWidget.takeItem(r)
00209 self.updateParentIcon()
00210 return i.data(Qt.DisplayRole).toString()
00211 return QString()
00212
00213
00214
00215
00216
00217 def valid(self):
00218 self.ok=True
00219 self.close()
00220 return
00221
00222
00223
00224
00225
00226
00227 def escape(self):
00228 while self.ui.listWidget.count() > 0:
00229 self.ui.listWidget.takeItem(0)
00230 self.updateParentIcon()
00231 self.ok=False
00232 self.close()
00233 return
00234
00235
00236
00237
00238
00239 def listeChoix(self):
00240 return self.ui.treeView.checkedItems()
00241
00242 def listeUnique_Names(self):
00243 result=[]
00244 for e in self.listeChoix():
00245 prefixe=QString()
00246 if self.ui.checkBoxNumero.isChecked():
00247 n=self.ui.spinBoxNumero.value()
00248 prefixe=QString("%1-").arg(n,fieldWidth=2,fillChar=QChar("0"))
00249 self.ui.spinBoxNumero.setValue(n+1)
00250 result.append(prefixe+e.unique_name)
00251 return result
00252
00253 if __name__=="__main__":
00254 app=QApplication(sys.argv)
00255 d=choixElevesDialog("../exemples/SCONET_test.xml", gestionnaire=gestClasse.Sconet)
00256 d.exec_()
00257 print "dialogue ok =", d.ok
00258 i=d.pop()
00259 while i:
00260 print (u"on a dépilé %s" %i).encode("utf-8")
00261 i=d.pop()
00262
00263