25 |
25 |
26 class IconsPage(ConfigurationPageBase, Ui_IconsPage): |
26 class IconsPage(ConfigurationPageBase, Ui_IconsPage): |
27 """ |
27 """ |
28 Class implementing the Icons configuration page. |
28 Class implementing the Icons configuration page. |
29 """ |
29 """ |
|
30 |
30 def __init__(self): |
31 def __init__(self): |
31 """ |
32 """ |
32 Constructor |
33 Constructor |
33 """ |
34 """ |
34 super().__init__() |
35 super().__init__() |
35 self.setupUi(self) |
36 self.setupUi(self) |
36 self.setObjectName("IconsPage") |
37 self.setObjectName("IconsPage") |
37 |
38 |
38 self.iconDirectoryPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
39 self.iconDirectoryPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
39 |
40 |
40 # set initial values |
41 # set initial values |
41 defaultIconsPath = Preferences.getIcons("DefaultIconsPath") |
42 defaultIconsPath = Preferences.getIcons("DefaultIconsPath") |
42 if defaultIconsPath == "automatic": |
43 if defaultIconsPath == "automatic": |
43 self.defaultAutomaticButton.setChecked(True) |
44 self.defaultAutomaticButton.setChecked(True) |
44 elif defaultIconsPath == "breeze-light": |
45 elif defaultIconsPath == "breeze-light": |
45 self.defaultBreezeLightButton.setChecked(True) |
46 self.defaultBreezeLightButton.setChecked(True) |
46 elif defaultIconsPath == "breeze-dark": |
47 elif defaultIconsPath == "breeze-dark": |
47 self.defaultBreezeDarkButton.setChecked(True) |
48 self.defaultBreezeDarkButton.setChecked(True) |
48 else: |
49 else: |
49 self.defaultOxygenButton.setChecked(True) |
50 self.defaultOxygenButton.setChecked(True) |
50 |
51 |
51 dirList = Preferences.getIcons("Path")[:] |
52 dirList = Preferences.getIcons("Path")[:] |
52 for directory in dirList: |
53 for directory in dirList: |
53 if directory: |
54 if directory: |
54 QListWidgetItem(directory, self.iconDirectoryList) |
55 QListWidgetItem(directory, self.iconDirectoryList) |
55 |
56 |
56 def save(self): |
57 def save(self): |
57 """ |
58 """ |
58 Public slot to save the Icons configuration. |
59 Public slot to save the Icons configuration. |
59 """ |
60 """ |
60 Preferences.setIcons("DefaultIconsPath", |
61 Preferences.setIcons("DefaultIconsPath", self.__getSelectedDefaultIconsPath()) |
61 self.__getSelectedDefaultIconsPath()) |
62 |
62 |
|
63 dirList = [] |
63 dirList = [] |
64 for i in range(self.iconDirectoryList.count()): |
64 for i in range(self.iconDirectoryList.count()): |
65 dirList.append(self.iconDirectoryList.item(i).text()) |
65 dirList.append(self.iconDirectoryList.item(i).text()) |
66 Preferences.setIcons("Path", dirList) |
66 Preferences.setIcons("Path", dirList) |
67 |
67 |
68 def __getSelectedDefaultIconsPath(self): |
68 def __getSelectedDefaultIconsPath(self): |
69 """ |
69 """ |
70 Private method to determine the selected default icons path. |
70 Private method to determine the selected default icons path. |
71 |
71 |
72 @return selected default icons path |
72 @return selected default icons path |
73 @rtype str |
73 @rtype str |
74 """ |
74 """ |
75 if self.defaultAutomaticButton.isChecked(): |
75 if self.defaultAutomaticButton.isChecked(): |
76 return "automatic" |
76 return "automatic" |
78 return "breeze-light" |
78 return "breeze-light" |
79 elif self.defaultBreezeDarkButton.isChecked(): |
79 elif self.defaultBreezeDarkButton.isChecked(): |
80 return "breeze-dark" |
80 return "breeze-dark" |
81 else: |
81 else: |
82 return "oxygen" |
82 return "oxygen" |
83 |
83 |
84 def on_iconDirectoryList_currentRowChanged(self, row): |
84 def on_iconDirectoryList_currentRowChanged(self, row): |
85 """ |
85 """ |
86 Private slot to handle the currentRowChanged signal of the icons |
86 Private slot to handle the currentRowChanged signal of the icons |
87 directory list. |
87 directory list. |
88 |
88 |
89 @param row the current row (integer) |
89 @param row the current row (integer) |
90 """ |
90 """ |
91 if row == -1: |
91 if row == -1: |
92 self.deleteIconDirectoryButton.setEnabled(False) |
92 self.deleteIconDirectoryButton.setEnabled(False) |
93 self.upButton.setEnabled(False) |
93 self.upButton.setEnabled(False) |
94 self.downButton.setEnabled(False) |
94 self.downButton.setEnabled(False) |
95 self.showIconsButton.setEnabled( |
95 self.showIconsButton.setEnabled(self.iconDirectoryPicker.text() != "") |
96 self.iconDirectoryPicker.text() != "") |
|
97 else: |
96 else: |
98 maxIndex = self.iconDirectoryList.count() - 1 |
97 maxIndex = self.iconDirectoryList.count() - 1 |
99 self.upButton.setEnabled(row != 0) |
98 self.upButton.setEnabled(row != 0) |
100 self.downButton.setEnabled(row != maxIndex) |
99 self.downButton.setEnabled(row != maxIndex) |
101 self.deleteIconDirectoryButton.setEnabled(True) |
100 self.deleteIconDirectoryButton.setEnabled(True) |
102 self.showIconsButton.setEnabled(True) |
101 self.showIconsButton.setEnabled(True) |
103 |
102 |
104 def on_iconDirectoryPicker_textChanged(self, txt): |
103 def on_iconDirectoryPicker_textChanged(self, txt): |
105 """ |
104 """ |
106 Private slot to handle the textChanged signal of the directory picker. |
105 Private slot to handle the textChanged signal of the directory picker. |
107 |
106 |
108 @param txt the text of the directory picker (string) |
107 @param txt the text of the directory picker (string) |
109 """ |
108 """ |
110 self.addIconDirectoryButton.setEnabled(txt != "") |
109 self.addIconDirectoryButton.setEnabled(txt != "") |
111 self.showIconsButton.setEnabled( |
110 self.showIconsButton.setEnabled( |
112 txt != "" or |
111 txt != "" or self.iconDirectoryList.currentRow() != -1 |
113 self.iconDirectoryList.currentRow() != -1) |
112 ) |
114 |
113 |
115 @pyqtSlot() |
114 @pyqtSlot() |
116 def on_upButton_clicked(self): |
115 def on_upButton_clicked(self): |
117 """ |
116 """ |
118 Private slot called to move the selected item up in the list. |
117 Private slot called to move the selected item up in the list. |
119 """ |
118 """ |
120 row = self.iconDirectoryList.currentRow() |
119 row = self.iconDirectoryList.currentRow() |
121 if row == 0: |
120 if row == 0: |
122 # we're already at the top |
121 # we're already at the top |
123 return |
122 return |
124 |
123 |
125 itm = self.iconDirectoryList.takeItem(row) |
124 itm = self.iconDirectoryList.takeItem(row) |
126 self.iconDirectoryList.insertItem(row - 1, itm) |
125 self.iconDirectoryList.insertItem(row - 1, itm) |
127 self.iconDirectoryList.setCurrentItem(itm) |
126 self.iconDirectoryList.setCurrentItem(itm) |
128 if row == 1: |
127 if row == 1: |
129 self.upButton.setEnabled(False) |
128 self.upButton.setEnabled(False) |
130 else: |
129 else: |
131 self.upButton.setEnabled(True) |
130 self.upButton.setEnabled(True) |
132 self.downButton.setEnabled(True) |
131 self.downButton.setEnabled(True) |
133 |
132 |
134 @pyqtSlot() |
133 @pyqtSlot() |
135 def on_downButton_clicked(self): |
134 def on_downButton_clicked(self): |
136 """ |
135 """ |
137 Private slot called to move the selected item down in the list. |
136 Private slot called to move the selected item down in the list. |
138 """ |
137 """ |
139 rows = self.iconDirectoryList.count() |
138 rows = self.iconDirectoryList.count() |
140 row = self.iconDirectoryList.currentRow() |
139 row = self.iconDirectoryList.currentRow() |
141 if row == rows - 1: |
140 if row == rows - 1: |
142 # we're already at the end |
141 # we're already at the end |
143 return |
142 return |
144 |
143 |
145 itm = self.iconDirectoryList.takeItem(row) |
144 itm = self.iconDirectoryList.takeItem(row) |
146 self.iconDirectoryList.insertItem(row + 1, itm) |
145 self.iconDirectoryList.insertItem(row + 1, itm) |
147 self.iconDirectoryList.setCurrentItem(itm) |
146 self.iconDirectoryList.setCurrentItem(itm) |
148 self.upButton.setEnabled(True) |
147 self.upButton.setEnabled(True) |
149 if row == rows - 2: |
148 if row == rows - 2: |
150 self.downButton.setEnabled(False) |
149 self.downButton.setEnabled(False) |
151 else: |
150 else: |
152 self.downButton.setEnabled(True) |
151 self.downButton.setEnabled(True) |
153 |
152 |
154 @pyqtSlot() |
153 @pyqtSlot() |
155 def on_addIconDirectoryButton_clicked(self): |
154 def on_addIconDirectoryButton_clicked(self): |
156 """ |
155 """ |
157 Private slot to add the icon directory displayed to the listbox. |
156 Private slot to add the icon directory displayed to the listbox. |
158 """ |
157 """ |
160 if directory: |
159 if directory: |
161 QListWidgetItem(directory, self.iconDirectoryList) |
160 QListWidgetItem(directory, self.iconDirectoryList) |
162 self.iconDirectoryPicker.clear() |
161 self.iconDirectoryPicker.clear() |
163 row = self.iconDirectoryList.currentRow() |
162 row = self.iconDirectoryList.currentRow() |
164 self.on_iconDirectoryList_currentRowChanged(row) |
163 self.on_iconDirectoryList_currentRowChanged(row) |
165 |
164 |
166 @pyqtSlot() |
165 @pyqtSlot() |
167 def on_deleteIconDirectoryButton_clicked(self): |
166 def on_deleteIconDirectoryButton_clicked(self): |
168 """ |
167 """ |
169 Private slot to delete the currently selected directory of the listbox. |
168 Private slot to delete the currently selected directory of the listbox. |
170 """ |
169 """ |
171 row = self.iconDirectoryList.currentRow() |
170 row = self.iconDirectoryList.currentRow() |
172 itm = self.iconDirectoryList.takeItem(row) |
171 itm = self.iconDirectoryList.takeItem(row) |
173 del itm |
172 del itm |
174 row = self.iconDirectoryList.currentRow() |
173 row = self.iconDirectoryList.currentRow() |
175 self.on_iconDirectoryList_currentRowChanged(row) |
174 self.on_iconDirectoryList_currentRowChanged(row) |
176 |
175 |
177 @pyqtSlot() |
176 @pyqtSlot() |
178 def on_showIconsButton_clicked(self): |
177 def on_showIconsButton_clicked(self): |
179 """ |
178 """ |
180 Private slot to display a preview of an icons directory. |
179 Private slot to display a preview of an icons directory. |
181 """ |
180 """ |
200 if defaultIconsPath == "automatic": |
200 if defaultIconsPath == "automatic": |
201 if ericApp().usesDarkPalette(): |
201 if ericApp().usesDarkPalette(): |
202 defaultIconsPath = "breeze-dark" |
202 defaultIconsPath = "breeze-dark" |
203 else: |
203 else: |
204 defaultIconsPath = "breeze-light" |
204 defaultIconsPath = "breeze-light" |
205 |
205 |
206 from .IconsPreviewDialog import IconsPreviewDialog |
206 from .IconsPreviewDialog import IconsPreviewDialog |
207 dlg = IconsPreviewDialog([ |
207 |
208 os.path.join(getConfig('ericIconDir'), defaultIconsPath), |
208 dlg = IconsPreviewDialog( |
209 os.path.join(getConfig('ericIconDir'), defaultIconsPath, |
209 [ |
210 "languages"), |
210 os.path.join(getConfig("ericIconDir"), defaultIconsPath), |
211 ], self) |
211 os.path.join(getConfig("ericIconDir"), defaultIconsPath, "languages"), |
|
212 ], |
|
213 self, |
|
214 ) |
212 dlg.exec() |
215 dlg.exec() |
213 |
216 |
214 |
217 |
215 def create(dlg): |
218 def create(dlg): |
216 """ |
219 """ |
217 Module function to create the configuration page. |
220 Module function to create the configuration page. |
218 |
221 |
219 @param dlg reference to the configuration dialog |
222 @param dlg reference to the configuration dialog |
220 @return reference to the instantiated page (ConfigurationPageBase) |
223 @return reference to the instantiated page (ConfigurationPageBase) |
221 """ |
224 """ |
222 page = IconsPage() |
225 page = IconsPage() |
223 return page |
226 return page |