src/eric7/Preferences/ConfigurationPages/IconsPreviewDialog.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) 2004 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to preview the contents of an icon directory.
8 """
9
10 import os.path
11
12 from PyQt6.QtCore import pyqtSlot, QDir
13 from PyQt6.QtGui import QIcon, QPalette
14 from PyQt6.QtWidgets import QListWidgetItem, QDialog
15
16 from .Ui_IconsPreviewDialog import Ui_IconsPreviewDialog
17
18
19 class IconsPreviewDialog(QDialog, Ui_IconsPreviewDialog):
20 """
21 Class implementing a dialog to preview the contents of an icon directory.
22 """
23 def __init__(self, directories, parent=None):
24 """
25 Constructor
26
27 @param directories list of directories to be shown
28 @type list of str
29 @param parent parent widget
30 @type QWidget
31 """
32 super().__init__(parent)
33 self.setupUi(self)
34
35 palette = self.iconView.palette()
36 self.__backgroundColor = palette.color(QPalette.ColorRole.Window)
37 self.__foregroundColor = palette.color(QPalette.ColorRole.WindowText)
38 self.__inverted = False
39
40 self.directoryCombo.addItems(sorted(directories))
41
42 @pyqtSlot(str)
43 def on_directoryCombo_currentTextChanged(self, dirName):
44 """
45 Private slot to show the icons of the selected icon directory.
46
47 @param dirName selected icon directory
48 @type str
49 """
50 self.iconView.clear()
51 directory = QDir(dirName)
52 for icon in directory.entryList(["*.svg", "*.svgz", "*.png"]):
53 itm = QListWidgetItem(
54 QIcon(os.path.join(dirName, icon)),
55 icon, self.iconView)
56 if self.__inverted:
57 itm.setForeground(self.__backgroundColor)
58 else:
59 itm.setForeground(self.__foregroundColor)
60
61 @pyqtSlot(bool)
62 def on_invertButton_toggled(self, checked):
63 """
64 Private slot to show the icons on an inverted background.
65
66 @param checked state of the button
67 @type bool
68 """
69 self.__inverted = checked
70
71 styleSheet = (
72 f"color: {self.__backgroundColor.name()};"
73 f"background-color: {self.__foregroundColor.name()}"
74 if self.__inverted else
75 f"color: {self.__foregroundColor.name()};"
76 f"background-color: {self.__backgroundColor.name()}"
77 )
78 self.iconView.viewport().setStyleSheet(styleSheet)
79
80 self.on_refreshButton_clicked()
81
82 @pyqtSlot()
83 def on_refreshButton_clicked(self):
84 """
85 Private slot to refresh the view.
86 """
87 currentDirectory = self.directoryCombo.currentText()
88 self.on_directoryCombo_currentTextChanged(currentDirectory)

eric ide

mercurial