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