6 this file is part of the project scolasync
8 Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
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.
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.
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/>.
30 import Ui_chooseInSticks
46 def __init__(self,parent = None, title1="", title2="", okPrompt="OK"):
47 QDialog.__init__(self,parent)
49 self.
_ui=Ui_chooseInSticks.Ui_Dialog()
50 self._ui.setupUi(self)
52 self.setWindowTitle(title1)
53 self._ui.groupBox.setTitle(title2)
55 okButton=self._ui.buttonBox.button(QDialogButtonBox.Ok)
56 self._ui.buttonBox.removeButton(okButton)
58 self._ui.buttonBox.addButton(self.
okButton,
59 QDialogButtonBox.AcceptRole)
65 self._fileListProxyModel.setDynamicSortFilter(
True)
71 self._storListProxyModel.setDynamicSortFilter(
True)
76 self._ui.minusButton.setEnabled(
False)
77 self._ui.travailEdit.setText(self.mainWindow.workdir)
78 QObject.connect(self._ui.plusButton, SIGNAL(
"clicked()"), self.
plus)
79 QObject.connect(self._ui.chooseButton, SIGNAL(
"clicked()"), self.
choose)
80 QObject.connect(self._ui.chooseButton_dir, SIGNAL(
"clicked()"), self.
choose_dir)
82 QObject.connect(self._ui.minusButton, SIGNAL(
"clicked()"), self.
minus)
83 QObject.connect(self._ui.listView, SIGNAL(
"clicked(QModelIndex)"), self.
activate)
84 QObject.connect(self._ui.travailEdit, SIGNAL(
"editingFinished()"), self.
changeWd)
93 self.
ok=self._ui.listView.model().rowCount()>0
102 sel=self.mainWindow.ui.tableView.selectedIndexes()
103 for d
in qApp.diskData:
105 mountPath=d.ensureMounted()
106 item=QStandardItem(o)
108 for modelIndex
in sel:
109 if o ==
"%s" %modelIndex.data(Qt.DisplayRole).toString():
111 self._storListModel.appendRow(item)
113 self._storListProxyModel.sort(0)
126 selection=self._ui.listChoixCle.selectionModel().selection()
127 selection = self._storListProxyModel.mapSelectionToSource(selection)
128 selectedRows=map(
lambda x: x.row(), self._ui.listChoixCle.selectedIndexes())
129 itemList=self._storListModel.findItems (
"*",Qt.MatchWildcard)
130 itemList.sort(key=
lambda i: i.data(Qt.DisplayRole).toString())
133 for item
in itemList:
134 index=self._storListModel.indexFromItem(item)
135 o=
"%s" %item.data(Qt.DisplayRole).toString()
137 if os.path.isdir(testDir):
140 item.setSelectable(
True)
141 item.setEnabled(
True)
143 if firstSelectable ==
None:
144 firstSelectable=index
146 if index.row()
in selectedRows:
149 item.setSelectable(
False)
150 item.setEnabled(
False)
151 if okSelected ==
None and firstSelectable !=
None:
152 selection=QItemSelection(firstSelectable,firstSelectable)
153 selection=self._storListProxyModel.mapSelectionFromSource(selection)
154 self._ui.listChoixCle.selectionModel().select(selection, QItemSelectionModel.Select);
166 return os.path.join(mp,self.mainWindow.workdir)
187 selection=self._ui.listChoixCle.selectionModel().selection()
188 if len(selection)==0:
190 selection = self._storListProxyModel.mapSelectionToSource(selection)
191 return "%s" %selection.indexes()[0].data(Qt.DisplayRole).toString()
198 newDir=self._ui.travailEdit.text()
199 self.mainWindow.changeWd(newDir)
212 func=QFileDialog.getOpenFileNames
213 msg=QApplication.translate(
"Dialog",
214 "Choissez un fichier (ou plus)",
215 encoding=QApplication.UnicodeUTF8)
217 func=QFileDialog.getExistingDirectory
218 msg=QApplication.translate(
"Dialog",
219 "Choissez un répertoire",
220 encoding=QApplication.UnicodeUTF8)
223 f = func (
None, msg, cd)
225 if isinstance(f, str):
231 self._ui.lineEdit.setText(path)
234 titre=QApplication.translate(
"Dialog",
235 "Aucune clé modèle sélectionnée",
236 encoding=QApplication.UnicodeUTF8)
237 msg=QApplication.translate(
"Dialog",
238 "Veuillez choisir une clé modèle<br>parmi les clés connectées en cliquant<br>sur une ligne du tableau, pour<br>bénéficier de l'aide au choix de fichiers.<br><br>Cette clé doit contenir au moins<br>un répertoire « {workdir} ».".format(workdir=self.mainWindow.workdir),
239 encoding=QApplication.UnicodeUTF8)
240 msgBox=QMessageBox.warning(
None, titre, msg)
257 self._ui.minusButton.setEnabled(
True)
265 text=self._ui.lineEdit.text()
275 sel=self._ui.listView.selectedIndexes()
276 sel1=map(self._fileListProxyModel.mapToSource,sel)
277 rows=map(
lambda x: x.row(), sel1)
278 rows.sort(
"descending")
280 self._fileListModel.removeRow(r)
281 sel=self._ui.listView.selectedIndexes()
283 self._ui.minusButton.setEnabled(
False)
291 f=self._fileListModel.findItems(path)
293 item=QStandardItem(path)
294 self._fileListModel.appendRow(item)
295 self._fileListProxyModel.sort(0)
297 print (
"%s est déjà sélectionné" %path)
307 itemList=self._fileListModel.findItems(
"*",Qt.MatchWildcard)
308 result=[x.text()
for x
in itemList]
309 otherText=self._ui.lineEdit.text()
310 if len(otherText) > 0
and otherText
not in result :
311 result.append(otherText)
def checkWorkDirs
met à jour la possibilité de sélectionner les baladeurs dans la liste selon qu'ils ont ou pas un répe...
def plus
Permet de choisir et d'ajouter un nouveau fichier ou répertoire à supprimer.
def selectedDiskMountPoint
def append
Ajoute un chemin avec ou sans jokers à la liste des chemins à supprimer.
_fileListModel
création de la structure de liste pour les fichiers
ownedUsbDictionary
peuplement de la zone des noms de baladeurs
def checkValues
fonction de rappel liée au bouton de validation, vérifie s'il y a bien au moins un fichier ou un répe...
def choose
Facilite le choix de motifs de fichiers en recherchant dans les clés USB, modifie l'éditeur de ligne ...
def __init__
Le constructeur.
def pathList
renvoie la liste des chemins sélectionnés; dans le cas de chemins sans jokers (caractères * ou ...
def choose_dir
Facilite le choix de motifs de répertoires en recherchant dans les clés USB, modifie l'éditeur de lig...
def activate
Fonction de rappel quand un item de la liste est activé
_storListModel
création de la structure de liste pour les noms de baladeurs
def changeWd
changement du répertoire de travail
def listStorages
Met en place la liste des noms de baladeurs connectés en tenant compte du nom de répertoire de travai...
def minus
Permet de retirer de la liste des fichiers à supprimer ceux qu'on a sélectionnés. ...
okButton
mise en place des titres personnalisés
Un dialogue pour choisir un ensemble de fichiers à copier depuis une clé USB.