ScolaSync: Fichier source de src/nameAdrive.py

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