src/eric7/Preferences/ConfigurationPages/IconsPage.py

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

eric ide

mercurial