8 """ |
8 """ |
9 |
9 |
10 |
10 |
11 import os.path |
11 import os.path |
12 |
12 |
13 from PyQt5.QtGui import QIcon |
13 from PyQt5.QtCore import pyqtSlot, QDir |
|
14 from PyQt5.QtGui import QIcon, QPalette |
14 from PyQt5.QtWidgets import QListWidgetItem, QDialog |
15 from PyQt5.QtWidgets import QListWidgetItem, QDialog |
15 from PyQt5.QtCore import QDir |
|
16 |
16 |
17 from .Ui_IconsPreviewDialog import Ui_IconsPreviewDialog |
17 from .Ui_IconsPreviewDialog import Ui_IconsPreviewDialog |
18 |
18 |
19 |
19 |
20 class IconsPreviewDialog(QDialog, Ui_IconsPreviewDialog): |
20 class IconsPreviewDialog(QDialog, Ui_IconsPreviewDialog): |
21 """ |
21 """ |
22 Class implementing a dialog to preview the contents of an icon directory. |
22 Class implementing a dialog to preview the contents of an icon directory. |
23 """ |
23 """ |
24 def __init__(self, parent, dirName): |
24 def __init__(self, directories, parent=None): |
25 """ |
25 """ |
26 Constructor |
26 Constructor |
27 |
27 |
28 @param parent parent widget (QWidget) |
28 @param directories list of directories to be shown |
29 @param dirName name of directory to show (string) |
29 @type list of str |
|
30 @param parent parent widget |
|
31 @type QWidget |
30 """ |
32 """ |
31 super(IconsPreviewDialog, self).__init__(parent) |
33 super(IconsPreviewDialog, self).__init__(parent) |
32 self.setupUi(self) |
34 self.setupUi(self) |
33 |
35 |
|
36 palette = self.iconView.palette() |
|
37 self.__baseBrush = palette.brush(QPalette.Base) |
|
38 self.__textBrush = palette.brush(QPalette.Text) |
|
39 self.__inverted = False |
|
40 |
|
41 self.directoryCombo.addItems(sorted(directories)) |
|
42 |
|
43 @pyqtSlot(str) |
|
44 def on_directoryCombo_currentTextChanged(self, dirName): |
|
45 """ |
|
46 Private slot to show the icons of the selected icon directory. |
|
47 |
|
48 @param dirName selected icon directory |
|
49 @type str |
|
50 """ |
|
51 self.iconView.clear() |
34 directory = QDir(dirName) |
52 directory = QDir(dirName) |
35 for icon in directory.entryList(["*.svg", "*.svgz", "*.png"]): |
53 for icon in directory.entryList(["*.svg", "*.svgz", "*.png"]): |
36 QListWidgetItem( |
54 itm = QListWidgetItem( |
37 QIcon(os.path.join(dirName, icon)), |
55 QIcon(os.path.join(dirName, icon)), |
38 icon, self.iconView) |
56 icon, self.iconView) |
|
57 if self.__inverted: |
|
58 itm.setForeground(self.__baseBrush) |
|
59 else: |
|
60 itm.setForeground(self.__textBrush) |
|
61 |
|
62 @pyqtSlot(bool) |
|
63 def on_invertButton_toggled(self, checked): |
|
64 """ |
|
65 Private slot to show the icons on an inverted background. |
|
66 |
|
67 @param checked state of the button |
|
68 @type bool |
|
69 """ |
|
70 self.__inverted = checked |
|
71 |
|
72 palette = self.iconView.palette() |
|
73 if self.__inverted: |
|
74 palette.setBrush(QPalette.Base, self.__textBrush) |
|
75 palette.setBrush(QPalette.Text, self.__baseBrush) |
|
76 else: |
|
77 palette.setBrush(QPalette.Base, self.__baseBrush) |
|
78 palette.setBrush(QPalette.Text, self.__textBrush) |
|
79 self.iconView.viewport().setPalette(palette) |
|
80 |
|
81 self.on_refreshButton_clicked() |
|
82 |
|
83 @pyqtSlot() |
|
84 def on_refreshButton_clicked(self): |
|
85 """ |
|
86 Private slot to refresh the view. |
|
87 """ |
|
88 currentDirectory = self.directoryCombo.currentText() |
|
89 self.on_directoryCombo_currentTextChanged(currentDirectory) |