src/eric7/Preferences/ConfigurationPages/IconsPreviewDialog.py

Fri, 04 Nov 2022 13:52:26 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Nov 2022 13:52:26 +0100
branch
eric7
changeset 9473
3f23dbf37dbe
parent 9221
bf71ee032bb4
child 9653
e67609152c5e
permissions
-rw-r--r--

Resorted the import statements using isort.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8879
diff changeset
3 # Copyright (c) 2004 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to preview the contents of an icon directory.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os.path
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
12 from PyQt6.QtCore import QDir, pyqtSlot
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
13 from PyQt6.QtGui import QIcon, QPalette
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
14 from PyQt6.QtWidgets import QDialog, QListWidgetItem
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
16 from .Ui_IconsPreviewDialog import Ui_IconsPreviewDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class IconsPreviewDialog(QDialog, Ui_IconsPreviewDialog):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Class implementing a dialog to preview the contents of an icon directory.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
23
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
24 def __init__(self, directories, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
27
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
28 @param directories list of directories to be shown
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
29 @type list of str
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
30 @param parent parent widget
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
31 @type QWidget
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
33 super().__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
36 palette = self.iconView.palette()
8871
772712033639 Corrected the color usage of the icons preview dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8857
diff changeset
37 self.__backgroundColor = palette.color(QPalette.ColorRole.Window)
772712033639 Corrected the color usage of the icons preview dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8857
diff changeset
38 self.__foregroundColor = palette.color(QPalette.ColorRole.WindowText)
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
39 self.__inverted = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
40
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
41 self.directoryCombo.addItems(sorted(directories))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
43 @pyqtSlot(str)
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
44 def on_directoryCombo_currentTextChanged(self, dirName):
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
45 """
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
46 Private slot to show the icons of the selected icon directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
48 @param dirName selected icon directory
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
49 @type str
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
50 """
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
51 self.iconView.clear()
5599
033967644b1f Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
52 directory = QDir(dirName)
7006
c29932589c9c IconsPreviewDialog: fixed the display of the *.svg icons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
53 for icon in directory.entryList(["*.svg", "*.svgz", "*.png"]):
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
54 itm = QListWidgetItem(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
55 QIcon(os.path.join(dirName, icon)), icon, self.iconView
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56 )
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
57 if self.__inverted:
8871
772712033639 Corrected the color usage of the icons preview dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8857
diff changeset
58 itm.setForeground(self.__backgroundColor)
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
59 else:
8871
772712033639 Corrected the color usage of the icons preview dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8857
diff changeset
60 itm.setForeground(self.__foregroundColor)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
61
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
62 @pyqtSlot(bool)
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
63 def on_invertButton_toggled(self, checked):
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
64 """
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
65 Private slot to show the icons on an inverted background.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
66
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
67 @param checked state of the button
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
68 @type bool
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
69 """
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
70 self.__inverted = checked
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
71
8879
159a4d6bab47 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8871
diff changeset
72 styleSheet = (
159a4d6bab47 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8871
diff changeset
73 f"color: {self.__backgroundColor.name()};"
159a4d6bab47 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8871
diff changeset
74 f"background-color: {self.__foregroundColor.name()}"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
75 if self.__inverted
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
76 else f"color: {self.__foregroundColor.name()};"
8879
159a4d6bab47 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8871
diff changeset
77 f"background-color: {self.__backgroundColor.name()}"
159a4d6bab47 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8871
diff changeset
78 )
8871
772712033639 Corrected the color usage of the icons preview dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8857
diff changeset
79 self.iconView.viewport().setStyleSheet(styleSheet)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
80
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
81 self.on_refreshButton_clicked()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82
7521
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
83 @pyqtSlot()
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
84 def on_refreshButton_clicked(self):
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
85 """
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
86 Private slot to refresh the view.
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
87 """
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
88 currentDirectory = self.directoryCombo.currentText()
17974c348101 Icons page, Icons preview dialog: added option to select the default icons and extended preview functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
89 self.on_directoryCombo_currentTextChanged(currentDirectory)

eric ide

mercurial