ScolaSync  1.0
nameAdrive.py
Aller à la documentation de ce fichier.
00001 #!/usr/bin/python
00002 # -*- coding: utf-8 -*-
00003 
00004 licence={}
00005 licence['en']="""
00006     file nameAdrive.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 from PyQt4.QtGui import *
00026 from PyQt4.QtCore import *
00027 import Ui_nameAdrive
00028 import re
00029 import db
00030 
00031 ##
00032 # 
00033 #     un dialogue pour renommer un baladeur, compte tenu d'une liste
00034 #     de noms disponibles
00035 #     
00036 class nameAdriveDialog(QDialog):
00037 
00038     ##
00039     # 
00040     #         Le constructeur.
00041     #         @param parent le widget parent
00042     #         @param oldName le nom précédent du baladeur
00043     #         @param nameList une liste de noms disponibles
00044     #         @param driveIdent identité d'un baladeur sous forme d'un triplet (stickId, Uuid, Tattoo)
00045     #         
00046     def __init__(self, parent=None, oldName="", nameList=[], driveIdent=None):
00047         QDialog.__init__(self, parent)
00048         self.oldName=oldName
00049         self.nameList=nameList
00050         assert driveIdent != None
00051         self.stickId, self.uuid, self.tattoo = driveIdent
00052         self.ui=Ui_nameAdrive.Ui_Dialog()
00053         self.ui.setupUi(self)
00054         for n in self.nameList:
00055             self.ui.listWidget.addItem(n)
00056         self.ui.lineEditOld.setText(self.oldName)
00057         self.numPattern=re.compile("^([0-9][0-9][0-9]?)-.*")
00058         self.connect(self.ui.listWidget, SIGNAL("itemSelectionChanged()"), self.selectionChanged)
00059         self.connect(self.ui.pushButtonOK, SIGNAL("clicked()"), self.ok)
00060         self.connect(self.ui.pushButtonEsc, SIGNAL("clicked()"), self.esc)
00061         self.makeSelection()
00062 
00063     
00064     ##
00065     # 
00066     #         Si l'ancien nom commence par un numéro, sélectionne le premier élément
00067     #         de la liste commençant par le même, sinon sélectionne le tout premier
00068     #         élément de la liste.
00069     #         
00070     def makeSelection(self):
00071         m=self.numPattern.match("%s" %self.oldName)
00072         lw=self.ui.listWidget
00073         if m:
00074             num=m.group(1)
00075             regexp=QString("^%s-.*" %num)
00076             possible=lw.findItems(regexp,Qt.MatchRegExp)
00077             if len(possible) > 0:
00078                 lw.setCurrentItem(possible[0])
00079             else:
00080                 lw.setCurrentItem(lw.item(0))
00081         else:
00082             lw.setCurrentItem(lw.item(0))
00083         return
00084 
00085     ##
00086     # 
00087     #         fonction de rappel quand la sélection change dans la liste;
00088     #         recopie l'élément sélectionné comme nouveau nom de baladeur
00089     #         
00090     def selectionChanged(self):
00091         l=self.ui.listWidget.selectedItems()
00092         i=l[0]
00093         t=i.data(Qt.DisplayRole).toString()
00094         self.ui.lineEditNew.setText(t)
00095         return
00096 
00097     ##
00098     # 
00099     #         fonction de rappel quand l'utilisateur valide le choix
00100     #         
00101     def ok(self):
00102         newName=u"%s" %self.ui.lineEditNew.text()
00103         newName.encode("utf-8")
00104         db.writeStudent(self.stickId, self.uuid, self.tattoo, newName)
00105         self.parent().namesDialog.takeItem(newName)
00106         self.parent().checkDisks(noLoop=True)
00107         self.done(QDialog.Accepted)
00108         return
00109 
00110     ##
00111     # 
00112     #         fonction de rappel quand l'utilisateur cherche à échapper au choix
00113     #         
00114     def esc(self):
00115         self.done(QDialog.Rejected)
00116         return
00117     
00118 
 Tout Classes Espaces de nommage Fichiers Fonctions Variables