2 |
2 |
3 # Copyright (c) 2015 - 2018 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2015 - 2018 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Package implementing the configuration page. |
7 Package implementing the pip configuration page. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtCore import pyqtSlot, Qt, QSortFilterProxyModel, QStringListModel |
|
15 |
|
16 from E5Gui import E5FileDialog |
|
17 |
11 |
18 from Preferences.ConfigurationPages.ConfigurationPageBase import \ |
12 from Preferences.ConfigurationPages.ConfigurationPageBase import \ |
19 ConfigurationPageBase |
13 ConfigurationPageBase |
20 from .Ui_PipPage import Ui_PipPage |
14 from .Ui_PipPage import Ui_PipPage |
21 |
15 |
22 from .. import DefaultPyPiUrl |
16 from .. import DefaultPyPiUrl |
23 |
17 |
24 import Utilities |
|
25 |
|
26 |
18 |
27 class PipPage(ConfigurationPageBase, Ui_PipPage): |
19 class PipPage(ConfigurationPageBase, Ui_PipPage): |
28 """ |
20 """ |
29 Class implementing the configuration page. |
21 Class implementing the pip configuration page. |
30 """ |
22 """ |
31 def __init__(self, plugin): |
23 def __init__(self, plugin): |
32 """ |
24 """ |
33 Constructor |
25 Constructor |
34 |
26 |
35 @param plugin reference to the plugin object |
27 @param plugin reference to the plugin object |
|
28 @type PipInterfacePlugin |
36 """ |
29 """ |
37 super(PipPage, self).__init__() |
30 super(PipPage, self).__init__() |
38 self.setupUi(self) |
31 self.setupUi(self) |
39 self.setObjectName("PipPage") |
32 self.setObjectName("PipPage") |
40 |
33 |
41 self.__plugin = plugin |
34 self.__plugin = plugin |
42 |
35 |
43 self.__model = QStringListModel(self) |
|
44 self.__proxyModel = QSortFilterProxyModel(self) |
|
45 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive) |
|
46 self.__proxyModel.setSourceModel(self.__model) |
|
47 self.stringList.setModel(self.__proxyModel) |
|
48 |
|
49 self.removeButton.clicked.connect(self.stringList.removeSelected) |
|
50 self.removeAllButton.clicked.connect(self.stringList.removeAll) |
|
51 |
|
52 self.indexLabel.setText(self.tr( |
36 self.indexLabel.setText(self.tr( |
53 '<b>Note:</b> Leave empty to use the default index URL (' |
37 '<b>Note:</b> Leave empty to use the default index URL (' |
54 '<a href="{0}">{0}</a>).') |
38 '<a href="{0}">{0}</a>).') |
55 .format(DefaultPyPiUrl)) |
39 .format(DefaultPyPiUrl)) |
56 |
40 |
57 # set initial values |
41 # set initial values |
58 self.__model.setStringList( |
|
59 self.__plugin.getPreferences("PipExecutables")) |
|
60 self.__model.sort(0) |
|
61 self.indexEdit.setText(self.__plugin.getPreferences("PipSearchIndex")) |
42 self.indexEdit.setText(self.__plugin.getPreferences("PipSearchIndex")) |
62 |
|
63 @pyqtSlot() |
|
64 def on_addButton_clicked(self): |
|
65 """ |
|
66 Private slot used to add an executable to the list. |
|
67 """ |
|
68 executable = E5FileDialog.getOpenFileName( |
|
69 self, |
|
70 self.tr("Add pip executable"), |
|
71 os.path.expanduser("~"), |
|
72 "") |
|
73 executable = Utilities.toNativeSeparators(executable) |
|
74 if executable != "" and executable not in self.__model.stringList(): |
|
75 self.__model.insertRow(self.__model.rowCount()) |
|
76 self.__model.setData( |
|
77 self.__model.index(self.__model.rowCount() - 1), executable) |
|
78 self.__model.sort(0) |
|
79 |
|
80 @pyqtSlot() |
|
81 def on_defaultListButton_clicked(self): |
|
82 """ |
|
83 Private slot to load the default list of pip executables. |
|
84 """ |
|
85 self.stringList.removeAll() |
|
86 defaults = self.__plugin.getDefaultPipExecutables() |
|
87 for executable in defaults: |
|
88 self.__model.insertRow(self.__model.rowCount()) |
|
89 self.__model.setData( |
|
90 self.__model.index(self.__model.rowCount() - 1), executable) |
|
91 self.__model.sort(0) |
|
92 |
43 |
93 def save(self): |
44 def save(self): |
94 """ |
45 """ |
95 Public slot to save the pip configuration. |
46 Public slot to save the pip configuration. |
96 """ |
47 """ |
97 executables = self.__model.stringList()[:] |
|
98 self.__plugin.setPreferences( |
|
99 "PipExecutables", executables) |
|
100 self.__plugin.setPreferences( |
48 self.__plugin.setPreferences( |
101 "PipSearchIndex", self.indexEdit.text().strip()) |
49 "PipSearchIndex", self.indexEdit.text().strip()) |
102 if executables: |
|
103 if self.__plugin.getPreferences("CurrentPipExecutable") \ |
|
104 not in executables: |
|
105 self.__plugin.setPreferences( |
|
106 "CurrentPipExecutable", "") |
|
107 else: |
|
108 # reset the current executable if none have been configured |
|
109 self.__plugin.setPreferences( |
|
110 "CurrentPipExecutable", "") |
|