ScolaSync  1.0
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
nameAdrive.py
Aller à la documentation de ce fichier.
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 
4 licence={}
5 licence['en']="""
6  file nameAdrive.py
7  this file is part of the project scolasync
8 
9  Copyright (C) 2012 Georges Khaznadar <georgesk@ofset.org>
10 
11  This program is free software: you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version3 of the License, or
14  (at your option) any later version.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program. If not, see <http://www.gnu.org/licenses/>.
23 """
24 
25 from PyQt4.QtGui import *
26 from PyQt4.QtCore import *
27 import Ui_nameAdrive
28 import re
29 import db
30 
31 ##
32 #
33 # un dialogue pour renommer un baladeur, compte tenu d'une liste
34 # de noms disponibles
35 #
37 
38  ##
39  #
40  # Le constructeur.
41  # @param parent le widget parent
42  # @param oldName le nom précédent du baladeur
43  # @param nameList une liste de noms disponibles
44  # @param driveIdent identité d'un baladeur sous forme d'un triplet (stickId, Uuid, Tattoo)
45  #
46  def __init__(self, parent=None, oldName="", nameList=[], driveIdent=None):
47  QDialog.__init__(self, parent)
48  self.oldName=oldName
49  self.nameList=nameList
50  assert driveIdent != None
51  self.stickId, self.uuid, self.tattoo = driveIdent
52  self.ui=Ui_nameAdrive.Ui_Dialog()
53  self.ui.setupUi(self)
54  for n in self.nameList:
55  self.ui.listWidget.addItem(n)
56  self.ui.lineEditOld.setText(self.oldName)
57  self.numPattern=re.compile("^([0-9][0-9][0-9]?)-.*")
58  self.connect(self.ui.listWidget, SIGNAL("itemSelectionChanged()"), self.selectionChanged)
59  self.connect(self.ui.pushButtonOK, SIGNAL("clicked()"), self.ok)
60  self.connect(self.ui.pushButtonEsc, SIGNAL("clicked()"), self.esc)
61  self.makeSelection()
62 
63 
64  ##
65  #
66  # Si l'ancien nom commence par un numéro, sélectionne le premier élément
67  # de la liste commençant par le même, sinon sélectionne le tout premier
68  # élément de la liste.
69  #
70  def makeSelection(self):
71  m=self.numPattern.match("%s" %self.oldName)
72  lw=self.ui.listWidget
73  if m:
74  num=m.group(1)
75  regexp=QString("^%s-.*" %num)
76  possible=lw.findItems(regexp,Qt.MatchRegExp)
77  if len(possible) > 0:
78  lw.setCurrentItem(possible[0])
79  else:
80  lw.setCurrentItem(lw.item(0))
81  else:
82  lw.setCurrentItem(lw.item(0))
83  return
84 
85  ##
86  #
87  # fonction de rappel quand la sélection change dans la liste;
88  # recopie l'élément sélectionné comme nouveau nom de baladeur
89  #
90  def selectionChanged(self):
91  l=self.ui.listWidget.selectedItems()
92  i=l[0]
93  t=i.data(Qt.DisplayRole).toString()
94  self.ui.lineEditNew.setText(t)
95  return
96 
97  ##
98  #
99  # fonction de rappel quand l'utilisateur valide le choix
100  #
101  def ok(self):
102  newName=u"%s" %self.ui.lineEditNew.text()
103  newName.encode("utf-8")
104  db.writeStudent(self.stickId, self.uuid, self.tattoo, newName)
105  self.parent().namesDialog.takeItem(newName)
106  self.parent().checkDisks(noLoop=True)
107  self.done(QDialog.Accepted)
108  return
109 
110  ##
111  #
112  # fonction de rappel quand l'utilisateur cherche à échapper au choix
113  #
114  def esc(self):
115  self.done(QDialog.Rejected)
116  return
117 
118