ScolaSync  4.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 python3safe=True
26 
27 from PyQt4.QtGui import *
28 from PyQt4.QtCore import *
29 import Ui_nameAdrive
30 import re
31 import db
32 
33 ##
34 #
35 # un dialogue pour renommer un baladeur, compte tenu d'une liste
36 # de noms disponibles
37 #
39 
40  ##
41  #
42  # Le constructeur.
43  # @param parent le widget parent
44  # @param oldName le nom précédent du baladeur
45  # @param nameList une liste de noms disponibles
46  # @param driveIdent identité d'un baladeur sous forme d'un triplet (stickId, Uuid, Tattoo)
47  #
48  def __init__(self, parent=None, oldName="", nameList=[], driveIdent=None):
49  QDialog.__init__(self, parent)
50  self.oldName=oldName
51  self.nameList=nameList
52  assert driveIdent != None
53  self.stickId, self.uuid, self.tattoo = driveIdent
54  self.ui=Ui_nameAdrive.Ui_Dialog()
55  self.ui.setupUi(self)
56  for n in self.nameList:
57  self.ui.listWidget.addItem(n)
58  self.ui.lineEditOld.setText(self.oldName)
59  self.numPattern=re.compile("^([0-9][0-9][0-9]?)-.*")
60  self.connect(self.ui.listWidget, SIGNAL("itemSelectionChanged()"), self.selectionChanged)
61  self.connect(self.ui.pushButtonOK, SIGNAL("clicked()"), self.ok)
62  self.connect(self.ui.pushButtonEsc, SIGNAL("clicked()"), self.esc)
63  self.makeSelection()
64 
65 
66  ##
67  #
68  # Si l'ancien nom commence par un numéro, sélectionne le premier élément
69  # de la liste commençant par le même, sinon sélectionne le tout premier
70  # élément de la liste.
71  #
72  def makeSelection(self):
73  m=self.numPattern.match("%s" %self.oldName)
74  lw=self.ui.listWidget
75  if m:
76  num=m.group(1)
77  regexp="^%s-.*" %num
78  possible=lw.findItems(regexp,Qt.MatchRegExp)
79  if len(possible) > 0:
80  lw.setCurrentItem(possible[0])
81  else:
82  lw.setCurrentItem(lw.item(0))
83  else:
84  lw.setCurrentItem(lw.item(0))
85  return
86 
87  ##
88  #
89  # fonction de rappel quand la sélection change dans la liste;
90  # recopie l'élément sélectionné comme nouveau nom de baladeur
91  #
92  def selectionChanged(self):
93  l=self.ui.listWidget.selectedItems()
94  i=l[0]
95  t=i.data(Qt.DisplayRole).toString()
96  self.ui.lineEditNew.setText(t)
97  return
98 
99  ##
100  #
101  # fonction de rappel quand l'utilisateur valide le choix
102  #
103  def ok(self):
104  newName="%s" %self.ui.lineEditNew.text()
105  newName.encode("utf-8")
106  db.writeStudent(self.stickId, self.uuid, self.tattoo, newName)
107  self.parent().namesDialog.takeItem(newName)
108  self.parent().checkDisks(noLoop=True)
109  self.done(QDialog.Accepted)
110  return
111 
112  ##
113  #
114  # fonction de rappel quand l'utilisateur cherche à échapper au choix
115  #
116  def esc(self):
117  self.done(QDialog.Rejected)
118  return
119 
def __init__
Le constructeur.
Definition: nameAdrive.py:48
def ok
fonction de rappel quand l'utilisateur valide le choix
Definition: nameAdrive.py:103
un dialogue pour renommer un baladeur, compte tenu d'une liste de noms disponibles ...
Definition: nameAdrive.py:38
def makeSelection
Si l'ancien nom commence par un numéro, sélectionne le premier élément de la liste commençant par le ...
Definition: nameAdrive.py:72
def selectionChanged
fonction de rappel quand la sélection change dans la liste; recopie l'élément sélectionné comme nouve...
Definition: nameAdrive.py:92
def esc
fonction de rappel quand l'utilisateur cherche à échapper au choix
Definition: nameAdrive.py:116