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