5     this file is part of the project scolasync 
    7     Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org> 
    9     This program is free software: you can redistribute it and/or modify 
   10     it under the terms of the GNU General Public License as published by 
   11     the Free Software Foundation, either version3 of the License, or 
   12     (at your option) any later version. 
   14     This program is distributed in the hope that it will be useful, 
   15     but WITHOUT ANY WARRANTY; without even the implied warranty of 
   16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
   17     GNU General Public License for more details. 
   19     You should have received a copy of the GNU General Public License 
   20     along with this program.  If not, see <http://www.gnu.org/licenses/>. 
   28 import Ui_chooseInSticks
 
   42     def __init__(self,parent = None, title1="", title2="", okPrompt="OK"):
 
   43         QDialog.__init__(self,parent)
 
   45         self.
_ui=Ui_chooseInSticks.Ui_Dialog()
 
   46         self.
_ui.setupUi(self)
 
   48         self.setWindowTitle(title1)
 
   49         self.
_ui.groupBox.setTitle(title2)
 
   51         okButton=self.
_ui.buttonBox.button(QDialogButtonBox.Ok)
 
   52         self.
_ui.buttonBox.removeButton(okButton)
 
   55                                      QDialogButtonBox.AcceptRole)
 
   72         self.
_ui.minusButton.setEnabled(
False)
 
   74         self.
_ui.plusButton.clicked.connect(self.
plus)
 
   75         self.
_ui.chooseButton.clicked.connect(self.
choose)
 
   78         self.
_ui.minusButton.clicked.connect(self.
minus)
 
   88         self.
ok=self.
_ui.listView.model().rowCount()>0
 
   96         sel=self.
mainWindow.ui.tableView.selectedIndexes()
 
   97         for d 
in qApp.available:
 
   99             mountPath=d.ensureMounted()
 
  100             item=QStandardItem(o)
 
  102             for modelIndex 
in sel:
 
  103                 if o == 
"%s" %modelIndex.data(Qt.DisplayRole):
 
  119         selection=self.
_ui.listChoixCle.selectionModel().selection()
 
  121         selectedRows=map(
lambda x: x.row(), self.
_ui.listChoixCle.selectedIndexes())
 
  123         itemList.sort(key=
lambda i: i.data(Qt.DisplayRole))
 
  126         for item 
in itemList:
 
  128             o=
"%s" %item.data(Qt.DisplayRole)
 
  130             if os.path.isdir(testDir):
 
  133                 item.setSelectable(
True)
 
  134                 item.setEnabled(
True)
 
  136                 if firstSelectable == 
None:
 
  137                     firstSelectable=index
 
  139                 if index.row() 
in selectedRows:
 
  142                 item.setSelectable(
False)
 
  143                 item.setEnabled(
False)
 
  144         if okSelected == 
None and firstSelectable != 
None:
 
  145             selection=QItemSelection(firstSelectable,firstSelectable)
 
  147             self.
_ui.listChoixCle.selectionModel().select(selection, QItemSelectionModel.Select);
 
  158             return os.path.join(mp,self.
mainWindow.workdir)
 
  177         selection=self.
_ui.listChoixCle.selectionModel().selection()
 
  178         if len(selection)==0:
 
  181         return "%s" %selection.indexes()[0].data(Qt.DisplayRole)
 
  187         newDir=self.
_ui.travailEdit.text()
 
  200             func=QFileDialog.getOpenFileNames
 
  201             msg=QApplication.translate(
"Dialog",
 
  202                                        "Choissez un fichier (ou plus)")
 
  204             func=QFileDialog.getExistingDirectory
 
  205             msg=QApplication.translate(
"Dialog",
 
  206                                        "Choissez un répertoire")
 
  209             f = func (
None, msg, cd)
 
  211                 if isinstance(f, str):
 
  217                     self.
_ui.lineEdit.setText(path)
 
  220             titre=QApplication.translate(
"Dialog",
 
  221                                          "Aucune clé modèle sélectionnée")
 
  222             msg=QApplication.translate(
"Dialog",
 
  223                                        "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))
 
  224             msgBox=QMessageBox.warning(
None, titre, msg)
 
  239         self.
_ui.minusButton.setEnabled(
True)
 
  246         text=self.
_ui.lineEdit.text()
 
  255         sel=self.
_ui.listView.selectedIndexes()
 
  257         rows=map(
lambda x: x.row(), sel1)
 
  258         rows.sort(
"descending")
 
  261         sel=self.
_ui.listView.selectedIndexes()
 
  263             self.
_ui.minusButton.setEnabled(
False)
 
  272             item=QStandardItem(path)
 
  276             print (
"%s est déjà sélectionné" %path)
 
  286         result=[x.text() 
for x 
in itemList]
 
  287         otherText=self.
_ui.lineEdit.text()
 
  288         if len(otherText) > 0 
and otherText 
not in result :
 
  289             result.append(otherText)