Aller à la documentation de ce fichier.00001
00002
00003
00004 licenceEn="""
00005 file copyToDialog1.py
00006 this file is part of the project scolasync
00007
00008 Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
00009
00010 This program is free software: you can redistribute it and/or modify
00011 it under the terms of the GNU General Public License as published by
00012 the Free Software Foundation, either version3 of the License, or
00013 (at your option) any later version.
00014
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 GNU General Public License for more details.
00019
00020 You should have received a copy of the GNU General Public License
00021 along with this program. If not, see <http://www.gnu.org/licenses/>.
00022 """
00023
00024 from PyQt4.QtCore import *
00025 from PyQt4.QtGui import *
00026 import os.path, subprocess
00027
00028 import Ui_copyToDialog1
00029
00030
00031
00032
00033
00034
00035
00036
00037 class copyToDialog1(QDialog):
00038
00039
00040
00041
00042
00043 def __init__(self,parent = None, workdir=""):
00044 QDialog.__init__(self,parent)
00045 self.mainWindow=parent
00046 self._ui=Ui_copyToDialog1.Ui_Dialog()
00047 self._ui.setupUi(self)
00048 self._ui.travailEdit.setText(workdir)
00049 self.setupFromListe()
00050 self._fromDir=QDir.home()
00051 self.setFromListeDir(self._fromDir)
00052 self.setupToListe()
00053
00054
00055 self.ok="False"
00056 QObject.connect(self._ui.selectButton, SIGNAL("clicked()"), self.select)
00057 QObject.connect(self._ui.removeButton, SIGNAL("clicked()"), self.remove)
00058 QObject.connect(self._ui.cancelButton, SIGNAL("clicked()"), self.cancel)
00059 QObject.connect(self._ui.continueButton, SIGNAL("clicked()"), self.cont)
00060 QObject.connect(self._ui.travailEdit, SIGNAL("editingFinished()"), self.changeWd)
00061
00062
00063
00064
00065
00066 def changeWd(self):
00067 newDir=u"%s" %self._ui.travailEdit.text().toUtf8()
00068 self.mainWindow.changeWd(newDir)
00069
00070
00071
00072
00073
00074 def cancel(self):
00075 self.close()
00076
00077
00078
00079
00080
00081
00082 def cont(self):
00083 self.ok=True
00084 self.close()
00085
00086
00087
00088
00089
00090 def setupFromListe(self):
00091 self._model1 = QDirModel()
00092 self._model1.setFilter(QDir.AllEntries)
00093 self._ui.listViewFrom.setModel(self._model1)
00094 QObject.connect(self._ui.listViewFrom, SIGNAL("doubleClicked(QModelIndex)"), self.cd)
00095
00096
00097
00098
00099
00100
00101 def setFromListeDir(self,directory):
00102 path=directory.path()
00103 cwdIndex = self._model1.index(path)
00104 self._ui.listViewFrom.setRootIndex(cwdIndex)
00105 self._ui.lineEdit.setText(path)
00106
00107
00108
00109
00110
00111
00112 def cd(self,index):
00113 d= "%s" %index.data().toString()
00114 p= "%s" %self._fromDir.path()
00115 j=os.path.abspath(os.path.join(p,d))
00116 if os.path.isdir(j):
00117 self._fromDir=QDir(j)
00118 self.setFromListeDir(self._fromDir)
00119
00120
00121
00122
00123
00124 def setupToListe(self):
00125 self._model2 = QStandardItemModel()
00126
00127
00128 self._proxyModel = QSortFilterProxyModel()
00129 self._proxyModel.setSourceModel(self._model2)
00130 self._ui.listViewTo.setModel(self._proxyModel)
00131 self._proxyModel.setDynamicSortFilter(True)
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 def select(self):
00144 sel=self._ui.listViewFrom.selectedIndexes()
00145 if len(sel)>0:
00146 index=sel[0]
00147 d= u"%s" %index.data().toString()
00148 p= u"%s" %self._fromDir.path()
00149 j=os.path.abspath(os.path.join(p,d))
00150 f=self._model2.findItems(j)
00151 if len(f)==0:
00152 self._model2.appendRow(QStandardItem(j))
00153 self._proxyModel.sort(0)
00154
00155 self.displaySize()
00156 else:
00157 print j, "est déjà sélectionné"
00158
00159
00160
00161
00162
00163 def displaySize(self):
00164 total=0
00165 for path in self.selectedList():
00166 p=subprocess.Popen(u"du -s '%s' | awk '{print $1}'" %path,
00167 shell=True, stdout=subprocess.PIPE)
00168 size=p.communicate()[0]
00169 try:
00170 total+= int(size)
00171 except:
00172 pass
00173 unit=u"%s" %QApplication.translate("Dialog","%s kilo-octets",None, QApplication.UnicodeUTF8)
00174 if total>1024:
00175 total= 0.1*int(10*total/1024)
00176 unit=u"%s" %QApplication.translate("Dialog","%s méga-octets",None, QApplication.UnicodeUTF8)
00177 if total>1024:
00178 total= 0.1*int(10*total/1024)
00179 unit=u"%s" %QApplication.translate("Dialog","%s giga-octets",None, QApplication.UnicodeUTF8)
00180 self._ui.lineEdit_size.setText(unit %total)
00181
00182
00183
00184
00185
00186
00187 def remove(self):
00188 sel=self._ui.listViewTo.selectedIndexes()
00189 if len(sel)>0:
00190 index=sel[0]
00191 sourceIndex=self._proxyModel.mapToSource(index)
00192 self._model2.removeRow(sourceIndex.row())
00193 self._proxyModel.sort(0)
00194
00195 self.displaySize()
00196
00197
00198
00199
00200
00201
00202
00203 def selectedList(self):
00204 sl=self._model2.findItems("*",Qt.MatchWildcard)
00205 return map(lambda x: ("%s" %x.text()), sl)
00206
00207 if __name__=="__main__":
00208 import sys
00209 app = QApplication(sys.argv)
00210 windows = copyToDialog1()
00211 windows.show()
00212 sys.exit(app.exec_())
00213