eric6/Preferences/ConfigurationPages/IconsPage.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Icons configuration page.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QListWidgetItem
14
15 from E5Gui.E5PathPicker import E5PathPickerModes
16
17 from .ConfigurationPageBase import ConfigurationPageBase
18 from .Ui_IconsPage import Ui_IconsPage
19
20 import Preferences
21
22
23 class IconsPage(ConfigurationPageBase, Ui_IconsPage):
24 """
25 Class implementing the Icons configuration page.
26 """
27 def __init__(self):
28 """
29 Constructor
30 """
31 super(IconsPage, self).__init__()
32 self.setupUi(self)
33 self.setObjectName("IconsPage")
34
35 self.iconDirectoryPicker.setMode(E5PathPickerModes.DirectoryMode)
36
37 # set initial values
38 dirList = Preferences.getIcons("Path")[:]
39 for directory in dirList:
40 if directory:
41 QListWidgetItem(directory, self.iconDirectoryList)
42
43 def save(self):
44 """
45 Public slot to save the Icons configuration.
46 """
47 dirList = []
48 for i in range(self.iconDirectoryList.count()):
49 dirList.append(self.iconDirectoryList.item(i).text())
50 Preferences.setIcons("Path", dirList)
51
52 def on_iconDirectoryList_currentRowChanged(self, row):
53 """
54 Private slot to handle the currentRowChanged signal of the icons
55 directory list.
56
57 @param row the current row (integer)
58 """
59 if row == -1:
60 self.deleteIconDirectoryButton.setEnabled(False)
61 self.upButton.setEnabled(False)
62 self.downButton.setEnabled(False)
63 self.showIconsButton.setEnabled(
64 self.iconDirectoryPicker.text() != "")
65 else:
66 maxIndex = self.iconDirectoryList.count() - 1
67 self.upButton.setEnabled(row != 0)
68 self.downButton.setEnabled(row != maxIndex)
69 self.deleteIconDirectoryButton.setEnabled(True)
70 self.showIconsButton.setEnabled(True)
71
72 def on_iconDirectoryPicker_textChanged(self, txt):
73 """
74 Private slot to handle the textChanged signal of the directory picker.
75
76 @param txt the text of the directory picker (string)
77 """
78 self.addIconDirectoryButton.setEnabled(txt != "")
79 self.showIconsButton.setEnabled(
80 txt != "" or
81 self.iconDirectoryList.currentRow() != -1)
82
83 @pyqtSlot()
84 def on_upButton_clicked(self):
85 """
86 Private slot called to move the selected item up in the list.
87 """
88 row = self.iconDirectoryList.currentRow()
89 if row == 0:
90 # we're already at the top
91 return
92
93 itm = self.iconDirectoryList.takeItem(row)
94 self.iconDirectoryList.insertItem(row - 1, itm)
95 self.iconDirectoryList.setCurrentItem(itm)
96 if row == 1:
97 self.upButton.setEnabled(False)
98 else:
99 self.upButton.setEnabled(True)
100 self.downButton.setEnabled(True)
101
102 @pyqtSlot()
103 def on_downButton_clicked(self):
104 """
105 Private slot called to move the selected item down in the list.
106 """
107 rows = self.iconDirectoryList.count()
108 row = self.iconDirectoryList.currentRow()
109 if row == rows - 1:
110 # we're already at the end
111 return
112
113 itm = self.iconDirectoryList.takeItem(row)
114 self.iconDirectoryList.insertItem(row + 1, itm)
115 self.iconDirectoryList.setCurrentItem(itm)
116 self.upButton.setEnabled(True)
117 if row == rows - 2:
118 self.downButton.setEnabled(False)
119 else:
120 self.downButton.setEnabled(True)
121
122 @pyqtSlot()
123 def on_addIconDirectoryButton_clicked(self):
124 """
125 Private slot to add the icon directory displayed to the listbox.
126 """
127 directory = self.iconDirectoryPicker.text()
128 if directory:
129 QListWidgetItem(directory, self.iconDirectoryList)
130 self.iconDirectoryPicker.clear()
131 row = self.iconDirectoryList.currentRow()
132 self.on_iconDirectoryList_currentRowChanged(row)
133
134 @pyqtSlot()
135 def on_deleteIconDirectoryButton_clicked(self):
136 """
137 Private slot to delete the currently selected directory of the listbox.
138 """
139 row = self.iconDirectoryList.currentRow()
140 itm = self.iconDirectoryList.takeItem(row)
141 del itm
142 row = self.iconDirectoryList.currentRow()
143 self.on_iconDirectoryList_currentRowChanged(row)
144
145 @pyqtSlot()
146 def on_showIconsButton_clicked(self):
147 """
148 Private slot to display a preview of an icons directory.
149 """
150 directory = self.iconDirectoryPicker.text()
151 if not directory:
152 itm = self.iconDirectoryList.currentItem()
153 if itm is not None:
154 directory = itm.text()
155 if directory:
156 from .IconsPreviewDialog import IconsPreviewDialog
157 dlg = IconsPreviewDialog(self, directory)
158 dlg.exec_()
159
160
161 def create(dlg):
162 """
163 Module function to create the configuration page.
164
165 @param dlg reference to the configuration dialog
166 @return reference to the instantiated page (ConfigurationPageBase)
167 """
168 page = IconsPage()
169 return page

eric ide

mercurial