16 import sys |
16 import sys |
17 import os |
17 import os |
18 import copy |
18 import copy |
19 |
19 |
20 from PyQt4.QtCore import pyqtSlot, QDir, QProcess |
20 from PyQt4.QtCore import pyqtSlot, QDir, QProcess |
21 from PyQt4.QtGui import QDialog |
21 from PyQt4.QtGui import QDialog, QListWidgetItem, QFileDialog, QPushButton, QTreeView, \ |
|
22 QItemSelection, QLineEdit |
22 |
23 |
23 from E5Gui import E5FileDialog |
24 from E5Gui import E5FileDialog |
24 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter |
25 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter |
25 |
26 |
26 from .Ui_CxfreezeConfigDialog import Ui_CxfreezeConfigDialog |
27 from .Ui_CxfreezeConfigDialog import Ui_CxfreezeConfigDialog |
27 |
28 |
28 import Utilities |
29 import Utilities |
|
30 |
|
31 |
|
32 class DirFileDialog(QFileDialog): |
|
33 """ |
|
34 Derived QFileDialog to select files and folders at once. |
|
35 For this purpose the none native filedialog is used. |
|
36 """ |
|
37 def __init__(self, parent=None, caption="", directory="", |
|
38 filter=""): |
|
39 """ |
|
40 Extend the normal none native filedialog to select files and folders at once. |
|
41 |
|
42 @param args same argument list like QFileDialog |
|
43 """ |
|
44 self.selectedFilesFolders = [] |
|
45 QFileDialog.__init__(self, parent, caption, directory, filter) |
|
46 self.setFileMode(QFileDialog.ExistingFiles) |
|
47 btns = self.findChildren(QPushButton) |
|
48 self.openBtn = [x for x in btns if 'open' in str(x.text()).lower()][0] |
|
49 self.openBtn.clicked.disconnect() |
|
50 self.openBtn.clicked.connect(self.on_openClicked) |
|
51 self.tree = self.findChild(QTreeView) |
|
52 self.fileNameEdit = self.findChild(QLineEdit) |
|
53 self.fileNameEdit.textChanged.disconnect() |
|
54 self.fileNameEdit.textChanged.connect(self.on_textChanged) |
|
55 self.directoryEntered.connect(self.on_directoryEntered) |
|
56 self.tree.selectionModel().selectionChanged.connect(self.on_selectionChanged) |
|
57 |
|
58 @pyqtSlot() |
|
59 def on_openClicked(self): |
|
60 """ |
|
61 Update the list with the selected files and folders. |
|
62 """ |
|
63 # Special case if a drive selected in Windows |
|
64 if self.directory().dirName() != '.': |
|
65 selectedItems = self.tree.selectionModel().selectedIndexes() |
|
66 path = os.path.normpath(self.directory().absolutePath()) |
|
67 self.selectedFilesFolders = [os.path.join(path, itm.data()) |
|
68 for itm in selectedItems if itm.column() == 0] |
|
69 # normalize path to slashes |
|
70 self.selectedFilesFolders = [x.replace(os.sep, '/') |
|
71 for x in self.selectedFilesFolders] |
|
72 self.hide() |
|
73 |
|
74 @pyqtSlot(str) |
|
75 def on_directoryEntered(self, dir): |
|
76 """ |
|
77 Reset selections if another directory was entered. |
|
78 |
|
79 @param dir name of the directory entered |
|
80 """ |
|
81 self.tree.selectionModel().clear() |
|
82 self.fileNameEdit.clear() |
|
83 |
|
84 @pyqtSlot(QItemSelection, QItemSelection) |
|
85 def on_selectionChanged(self, selected, deselected): |
|
86 """ |
|
87 Determine the selected files and folders and update the lineedit. |
|
88 |
|
89 @param selected newly selected entries |
|
90 @param deselected deselected entries |
|
91 """ |
|
92 selectedItems = self.tree.selectionModel().selectedIndexes() |
|
93 if self.tree.rootIndex() in selectedItems or selectedItems == []: |
|
94 self.fileNameEdit.setText('') |
|
95 else: |
|
96 selectedItems = [x.data() for x in selectedItems if x.column() == 0] |
|
97 selectedItems.sort() |
|
98 self.fileNameEdit.setText(';'.join(selectedItems)) |
|
99 |
|
100 @pyqtSlot(str) |
|
101 def on_textChanged(self, text): |
|
102 """ |
|
103 Set the state of the open button. |
|
104 |
|
105 @param text text written into the lineedit. |
|
106 """ |
|
107 self.openBtn.setEnabled(text!='') |
|
108 |
|
109 @staticmethod |
|
110 def getOpenFileNames(parent=None, caption="", directory="", |
|
111 filter="", options=QFileDialog.Options()): |
|
112 """ |
|
113 Module function to get the names of files and folders for opening it. |
|
114 |
|
115 @param parent parent widget of the dialog (QWidget) |
|
116 @param caption window title of the dialog (string) |
|
117 @param directory working directory of the dialog (string) |
|
118 @param filter filter string for the dialog (string) |
|
119 @param options various options for the dialog (QFileDialog.Options) |
|
120 @return names of the selected files and folders (list) |
|
121 """ |
|
122 options |= QFileDialog.DontUseNativeDialog |
|
123 dlg = DirFileDialog(parent, caption, directory, filter) |
|
124 dlg.exec_() |
|
125 return dlg.selectedFilesFolders |
|
126 |
29 |
127 |
30 class CxfreezeConfigDialog(QDialog, Ui_CxfreezeConfigDialog): |
128 class CxfreezeConfigDialog(QDialog, Ui_CxfreezeConfigDialog): |
31 """ |
129 """ |
32 Class implementing a dialog to enter the parameters for cxfreeze. |
130 Class implementing a dialog to enter the parameters for cxfreeze. |
33 """ |
131 """ |
87 self.includePathEdit.setText(os.pathsep.join(self.parameters['includePath'])) |
185 self.includePathEdit.setText(os.pathsep.join(self.parameters['includePath'])) |
88 self.replacePathsEdit.setText(os.pathsep.join(self.parameters['replacePaths'])) |
186 self.replacePathsEdit.setText(os.pathsep.join(self.parameters['replacePaths'])) |
89 self.includeModulesEdit.setText(','.join(self.parameters['includeModules'])) |
187 self.includeModulesEdit.setText(','.join(self.parameters['includeModules'])) |
90 self.excludeModulesEdit.setText(','.join(self.parameters['excludeModules'])) |
188 self.excludeModulesEdit.setText(','.join(self.parameters['excludeModules'])) |
91 self.extListFileEdit.setText(self.parameters['extListFile']) |
189 self.extListFileEdit.setText(self.parameters['extListFile']) |
|
190 |
|
191 # initialize additional files tab |
|
192 self.fileOrFolderList.addItems(self.parameters['additionalFiles']) |
92 |
193 |
93 def __initializeDefaults(self): |
194 def __initializeDefaults(self): |
94 """ |
195 """ |
95 Private method to set the default values. |
196 Private method to set the default values. |
96 |
197 |
338 currentText = self.initscriptCombo.currentText() |
446 currentText = self.initscriptCombo.currentText() |
339 self.initscriptCombo.clear() |
447 self.initscriptCombo.clear() |
340 self.initscriptCombo.addItems([os.path.splitext(i)[0] for i in initList]) |
448 self.initscriptCombo.addItems([os.path.splitext(i)[0] for i in initList]) |
341 self.initscriptCombo.setEditText(currentText) |
449 self.initscriptCombo.setEditText(currentText) |
342 |
450 |
|
451 def on_fileOrFolderList_currentRowChanged(self, row): |
|
452 """ |
|
453 Private slot to handle the currentRowChanged signal of the fileOrFolderList. |
|
454 |
|
455 @param row the current row (integer) |
|
456 """ |
|
457 self.deleteSelectedButton.setEnabled(row != -1) |
|
458 if row != -1: |
|
459 self.fileOrFolderList.setCurrentRow(row) |
|
460 |
|
461 @pyqtSlot(QListWidgetItem) |
|
462 def on_fileOrFolderList_itemDoubleClicked(self, itm): |
|
463 """ |
|
464 Private slot to handle the currentRowChanged signal of the fileOrFolderList. |
|
465 |
|
466 @param itm the selected row |
|
467 """ |
|
468 self.fileOrFolderEdit.setText(itm.text()) |
|
469 row = self.fileOrFolderList.currentRow() |
|
470 self.fileOrFolderList.takeItem(row) |
|
471 |
|
472 @pyqtSlot() |
|
473 def on_addFileOrFolderButton_clicked(self): |
|
474 """ |
|
475 Private slot to add the entered file or directory to the list view. |
|
476 """ |
|
477 txt = self.fileOrFolderEdit.text() |
|
478 if txt: |
|
479 self.fileOrFolderList.addItem(txt) |
|
480 self.fileOrFolderEdit.clear() |
|
481 row = self.fileOrFolderList.currentRow() |
|
482 self.on_fileOrFolderList_currentRowChanged(row) |
|
483 |
|
484 @pyqtSlot(str) |
|
485 def on_fileOrFolderEdit_textChanged(self, txt): |
|
486 """ |
|
487 Private slot to handle the textChanged signal of the directory edit. |
|
488 |
|
489 @param txt the text of the directory edit (string) |
|
490 """ |
|
491 self.addFileOrFolderButton.setEnabled(txt != "") |
|
492 |
|
493 @pyqtSlot() |
|
494 def on_deleteSelectedButton_clicked(self): |
|
495 """ |
|
496 Private slot to delete the selected entry from the list view. |
|
497 """ |
|
498 row = self.fileOrFolderList.currentRow() |
|
499 self.fileOrFolderList.takeItem(row) |
|
500 row = self.fileOrFolderList.currentRow() |
|
501 self.on_fileOrFolderList_currentRowChanged(row) |
|
502 |
|
503 @pyqtSlot() |
|
504 def on_selectFileOrFolderButton_clicked(self): |
|
505 """ |
|
506 Private slot to select files or folders. |
|
507 |
|
508 It displays a file and directory selection dialog to |
|
509 select the files and directorys which should copied into |
|
510 the distribution folder.. |
|
511 """ |
|
512 items = DirFileDialog.getOpenFileNames( |
|
513 None, |
|
514 self.trUtf8("Select files and folders")) |
|
515 |
|
516 ppath = self.project.ppath.replace(os.sep, '/') + '/' |
|
517 for itm in items: |
|
518 if itm.startswith(ppath): |
|
519 itm = itm.replace(ppath, '') |
|
520 self.fileOrFolderList.addItem(Utilities.toNativeSeparators(itm)) |
|
521 row = self.fileOrFolderList.currentRow() |
|
522 self.on_fileOrFolderList_currentRowChanged(row) |
|
523 |
343 def accept(self): |
524 def accept(self): |
344 """ |
525 """ |
345 Protected slot called by the Ok button. |
526 Protected slot called by the Ok button. |
346 |
527 |
347 It saves the values in the parameters dictionary. |
528 It saves the values in the parameters dictionary. |
373 self.__splitIt(self.includeModulesEdit.text(), ',') |
554 self.__splitIt(self.includeModulesEdit.text(), ',') |
374 self.parameters['excludeModules'] = \ |
555 self.parameters['excludeModules'] = \ |
375 self.__splitIt(self.excludeModulesEdit.text(), ',') |
556 self.__splitIt(self.excludeModulesEdit.text(), ',') |
376 self.parameters['extListFile'] = self.extListFileEdit.text() |
557 self.parameters['extListFile'] = self.extListFileEdit.text() |
377 |
558 |
|
559 # get data of the additional files tab |
|
560 additionalFiles = [self.fileOrFolderList.item(x).text() |
|
561 for x in range(self.fileOrFolderList.count())] |
|
562 self.parameters['additionalFiles'] = additionalFiles |
|
563 |
378 # call the accept slot of the base class |
564 # call the accept slot of the base class |
379 QDialog.accept(self) |
565 QDialog.accept(self) |
380 |
566 |
381 def __splitIt(self, s, sep): |
567 def __splitIt(self, s, sep): |
382 """ |
568 """ |