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/>.
28 import Ui_chooseInSticks
44 def __init__(self,parent = None, title1="", title2="", ok="OK"):
45 QDialog.__init__(self,parent)
47 self.
_ui=Ui_chooseInSticks.Ui_Dialog()
48 self._ui.setupUi(self)
50 self.setWindowTitle(title1)
51 self._ui.groupBox.setTitle(title2)
53 okButton=self._ui.buttonBox.button(QDialogButtonBox.Ok)
54 self._ui.buttonBox.removeButton(okButton)
55 self._ui.buttonBox.addButton(QPushButton(ok),
56 QDialogButtonBox.AcceptRole)
62 self._fileListProxyModel.setDynamicSortFilter(
True)
68 self._storListProxyModel.setDynamicSortFilter(
True)
73 self._ui.minusButton.setEnabled(
False)
74 self._ui.travailEdit.setText(self.mainWindow.workdir)
75 QObject.connect(self._ui.plusButton, SIGNAL(
"clicked()"), self.
plus)
76 QObject.connect(self._ui.chooseButton, SIGNAL(
"clicked()"), self.
choose)
77 QObject.connect(self._ui.chooseButton_dir, SIGNAL(
"clicked()"), self.
choose_dir)
78 QObject.connect(self._ui.minusButton, SIGNAL(
"clicked()"), self.
minus)
79 QObject.connect(self._ui.listView, SIGNAL(
"clicked(QModelIndex)"), self.
activate)
80 QObject.connect(self._ui.travailEdit, SIGNAL(
"editingFinished()"), self.
changeWd)
90 sel=self.mainWindow.ui.tableView.selectedIndexes()
91 for d
in qApp.diskData:
93 mountPath=d.ensureMounted()
96 for modelIndex
in sel:
97 if o ==
u"%s" %modelIndex.data(Qt.DisplayRole).toString():
99 self._storListModel.appendRow(item)
101 self._storListProxyModel.sort(0)
114 selection=self._ui.listChoixCle.selectionModel().selection()
115 selection = self._storListProxyModel.mapSelectionToSource(selection)
116 selectedRows=map(
lambda x: x.row(), self._ui.listChoixCle.selectedIndexes())
117 itemList=self._storListModel.findItems (
"*",Qt.MatchWildcard)
118 itemList.sort(key=
lambda i: i.data(Qt.DisplayRole).toString())
121 for item
in itemList:
122 index=self._storListModel.indexFromItem(item)
123 o=
u"%s" %item.data(Qt.DisplayRole).toString()
125 if os.path.isdir(testDir):
128 item.setSelectable(
True)
129 item.setEnabled(
True)
131 if firstSelectable ==
None:
132 firstSelectable=index
134 if index.row()
in selectedRows:
137 item.setSelectable(
False)
138 item.setEnabled(
False)
139 if okSelected ==
None and firstSelectable !=
None:
140 selection=QItemSelection(firstSelectable,firstSelectable)
141 selection=self._storListProxyModel.mapSelectionFromSource(selection)
142 self._ui.listChoixCle.selectionModel().select(selection, QItemSelectionModel.Select);
154 return os.path.join(mp,self.mainWindow.workdir)
175 selection=self._ui.listChoixCle.selectionModel().selection()
176 if len(selection)==0:
178 selection = self._storListProxyModel.mapSelectionToSource(selection)
179 return u"%s" %selection.indexes()[0].data(Qt.DisplayRole).toString()
186 newDir=
u"%s" %self._ui.travailEdit.text().toUtf8()
187 self.mainWindow.changeWd(newDir)
200 func=QFileDialog.getOpenFileNames
201 msg=QApplication.translate(
"Dialog",
202 "Choissez un fichier (ou plus)",
203 encoding=QApplication.UnicodeUTF8)
205 func=QFileDialog.getExistingDirectory
206 msg=QApplication.translate(
"Dialog",
207 "Choissez un répertoire",
208 encoding=QApplication.UnicodeUTF8)
211 f = func (
None, msg, cd)
213 if type(f)==type(QStringList()):
219 self._ui.lineEdit.setText(path)
222 titre=QApplication.translate(
"Dialog",
223 "Aucune clé modèle sélectionnée",
224 encoding=QApplication.UnicodeUTF8)
225 msg=QApplication.translate(
"Dialog",
226 "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),
227 encoding=QApplication.UnicodeUTF8)
228 msgBox=QMessageBox.warning(
None, titre, msg)
245 self._ui.minusButton.setEnabled(
True)
253 text=self._ui.lineEdit.text()
263 sel=self._ui.listView.selectedIndexes()
264 sel1=map(self._fileListProxyModel.mapToSource,sel)
265 rows=map(
lambda x: x.row(), sel1)
266 rows.sort(
"descending")
268 self._fileListModel.removeRow(r)
269 sel=self._ui.listView.selectedIndexes()
271 self._ui.minusButton.setEnabled(
False)
279 f=self._fileListModel.findItems(path)
281 item=QStandardItem(path)
282 self._fileListModel.appendRow(item)
283 self._fileListProxyModel.sort(0)
285 print path,
"est déjà sélectionné"
295 itemList=self._fileListModel.findItems(
"*",Qt.MatchWildcard)
296 result=map(
lambda x: x.text(), itemList)
297 otherText=self._ui.lineEdit.text()
298 if len(otherText) > 0
and otherText
not in result :
299 result.append(otherText)