|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 """ |
|
4 Module implementing a dialog to enter the data for the repo conversion. |
|
5 """ |
|
6 |
|
7 from __future__ import unicode_literals |
|
8 |
|
9 import os |
|
10 |
|
11 from PyQt4.QtCore import pyqtSlot |
|
12 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
13 |
|
14 from E5Gui import E5FileDialog |
|
15 from E5Gui.E5Completers import E5DirCompleter |
|
16 |
|
17 from .Ui_LfConvertDataDialog import Ui_LfConvertDataDialog |
|
18 |
|
19 from . import getDefaults |
|
20 |
|
21 import Utilities |
|
22 import UI.PixmapCache |
|
23 |
|
24 |
|
25 class LfConvertDataDialog(QDialog, Ui_LfConvertDataDialog): |
|
26 """ |
|
27 Class implementing a dialog to enter the data for the repo conversion. |
|
28 """ |
|
29 def __init__(self, currentPath, mode, parent=None): |
|
30 """ |
|
31 Constructor |
|
32 |
|
33 @param currentPath directory name of the current project (string) |
|
34 @param mode dialog mode (string, one of 'largefiles' or 'normal') |
|
35 @param parent reference to the parent widget (QWidget) |
|
36 """ |
|
37 super(LfConvertDataDialog, self).__init__(parent) |
|
38 self.setupUi(self) |
|
39 |
|
40 self.newProjectButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
41 |
|
42 self.__newProjectCompleter = E5DirCompleter(self.newProjectEdit) |
|
43 |
|
44 self.__defaults = getDefaults() |
|
45 self.__currentPath = Utilities.toNativeSeparators(currentPath) |
|
46 |
|
47 self.currentProjectLabel.setPath(currentPath) |
|
48 self.newProjectEdit.setText(os.path.dirname(currentPath)) |
|
49 |
|
50 self.lfFileSizeSpinBox.setValue(self.__defaults["minsize"]) |
|
51 self.lfFilePatternsEdit.setText(" ".join(self.__defaults["pattern"])) |
|
52 |
|
53 if mode == 'normal': |
|
54 self.lfFileSizeSpinBox.setEnabled(False) |
|
55 self.lfFilePatternsEdit.setEnabled(False) |
|
56 |
|
57 msh = self.minimumSizeHint() |
|
58 self.resize(max(self.width(), msh.width()), msh.height()) |
|
59 |
|
60 @pyqtSlot(str) |
|
61 def on_newProjectEdit_textChanged(self, txt): |
|
62 """ |
|
63 Private slot to handle editing of the new project directory. |
|
64 |
|
65 @param txt new project directory name (string) |
|
66 """ |
|
67 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
68 txt and Utilities.toNativeSeparators(txt) != os.path.dirname( |
|
69 self.__currentPath)) |
|
70 |
|
71 @pyqtSlot() |
|
72 def on_newProjectButton_clicked(self): |
|
73 """ |
|
74 Private slot to select the new project directory name via a directory |
|
75 selection dialog. |
|
76 """ |
|
77 directory = Utilities.fromNativeSeparators(self.newProjectEdit.text()) |
|
78 directory = E5FileDialog.getExistingDirectory( |
|
79 self, |
|
80 self.tr("New Project Directory"), |
|
81 directory, |
|
82 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
83 if directory: |
|
84 self.newProjectEdit.setText( |
|
85 Utilities.toNativeSeparators(directory)) |
|
86 |
|
87 def getData(self): |
|
88 """ |
|
89 Public method to retrieve the entered data. |
|
90 |
|
91 @return tuple containing the new project directory name (string), |
|
92 minimum file size (integer) and file patterns (list of string) |
|
93 """ |
|
94 patterns = self.lfFilePatternsEdit.text().split() |
|
95 if set(patterns) == set(self.__defaults["pattern"]): |
|
96 patterns = [] |
|
97 |
|
98 return ( |
|
99 Utilities.toNativeSeparators(self.newProjectEdit.text()), |
|
100 self.lfFileSizeSpinBox.value(), |
|
101 patterns, |
|
102 ) |