|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a previewer widget for Qt style sheet files. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt6.QtCore import pyqtSlot, Qt |
|
13 from PyQt6.QtWidgets import ( |
|
14 QWidget, QMenu, QLabel, QHeaderView, QListWidgetItem |
|
15 ) |
|
16 |
|
17 from EricWidgets.EricPathPicker import EricPathPickerModes |
|
18 from EricWidgets.EricApplication import ericApp |
|
19 |
|
20 from .Ui_PreviewerQSS import Ui_PreviewerQSS |
|
21 |
|
22 import Preferences |
|
23 import Utilities |
|
24 import UI.PixmapCache |
|
25 |
|
26 from eric7config import getConfig |
|
27 |
|
28 |
|
29 class PreviewerQSS(QWidget, Ui_PreviewerQSS): |
|
30 """ |
|
31 Class implementing a previewer widget for Qt style sheet files. |
|
32 """ |
|
33 def __init__(self, parent=None): |
|
34 """ |
|
35 Constructor |
|
36 |
|
37 @param parent reference to the parent widget (QWidget) |
|
38 """ |
|
39 super().__init__(parent) |
|
40 self.setupUi(self) |
|
41 |
|
42 styleIconsPath = ericApp().getStyleIconsPath() |
|
43 self.styleIconsPathPicker.setMode( |
|
44 EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE) |
|
45 self.styleIconsPathPicker.setDefaultDirectory(styleIconsPath) |
|
46 |
|
47 self.__lastEditor = None |
|
48 |
|
49 # menu for the tool buttons |
|
50 self.__toolButtonMenu_1 = QMenu(self) |
|
51 self.__toolButtonMenu_1.addAction(self.tr("Action 1.1")) |
|
52 self.__toolButtonMenu_1.addSeparator() |
|
53 self.__toolButtonMenu_1.addAction(self.tr("Action 2.1")) |
|
54 self.toolButton_1.setMenu(self.__toolButtonMenu_1) |
|
55 |
|
56 self.__toolButtonMenu_2 = QMenu(self) |
|
57 self.__toolButtonMenu_2.addAction(self.tr("Action 1.2")) |
|
58 self.__toolButtonMenu_2.addSeparator() |
|
59 self.__toolButtonMenu_2.addAction(self.tr("Action 2.2")) |
|
60 self.toolButton_2.setMenu(self.__toolButtonMenu_2) |
|
61 |
|
62 self.__toolButtonMenu_3 = QMenu(self) |
|
63 self.__toolButtonMenu_3.addAction(self.tr("Action 1.3")) |
|
64 self.__toolButtonMenu_3.addSeparator() |
|
65 self.__toolButtonMenu_3.addAction(self.tr("Action 2.3")) |
|
66 self.toolButton_3.setMenu(self.__toolButtonMenu_3) |
|
67 |
|
68 # a MDI window |
|
69 self.__mdi = self.mdiArea.addSubWindow(QLabel(self.tr("MDI"))) |
|
70 self.__mdi.resize(160, 80) |
|
71 |
|
72 # tree and table widgets |
|
73 self.tree.header().setSectionResizeMode( |
|
74 QHeaderView.ResizeMode.ResizeToContents) |
|
75 self.table.horizontalHeader().setSectionResizeMode( |
|
76 QHeaderView.ResizeMode.ResizeToContents) |
|
77 self.tree.topLevelItem(0).setExpanded(True) |
|
78 |
|
79 # icon list widget |
|
80 for iconName, labelText in ( |
|
81 ("filePython", self.tr("Python")), |
|
82 ("fileRuby", self.tr("Ruby")), |
|
83 ("fileJavascript", self.tr("JavaScript")), |
|
84 ): |
|
85 self.iconsListWidget.addItem(QListWidgetItem( |
|
86 UI.PixmapCache.getIcon(iconName), labelText)) |
|
87 |
|
88 @pyqtSlot(str) |
|
89 def on_styleIconsPathPicker_textChanged(self, txt): |
|
90 """ |
|
91 Private slot handling a change of the style icons path. |
|
92 |
|
93 @param txt name of the style icons directory |
|
94 @type str |
|
95 """ |
|
96 self.processEditor(self.__lastEditor) |
|
97 |
|
98 def processEditor(self, editor=None): |
|
99 """ |
|
100 Public slot to process an editor's text. |
|
101 |
|
102 @param editor editor to be processed (Editor) |
|
103 """ |
|
104 self.__lastEditor = editor |
|
105 |
|
106 if editor is not None: |
|
107 fn = editor.getFileName() |
|
108 |
|
109 if fn: |
|
110 extension = os.path.normcase(os.path.splitext(fn)[1][1:]) |
|
111 else: |
|
112 extension = "" |
|
113 if ( |
|
114 extension in Preferences.getEditor( |
|
115 "PreviewQssFileNameExtensions") |
|
116 ): |
|
117 styleSheet = editor.text() |
|
118 if styleSheet: |
|
119 styleIconsPath = self.styleIconsPathPicker.text() |
|
120 if not styleIconsPath: |
|
121 styleIconsPath = Preferences.getUI("StyleIconsPath") |
|
122 if not styleIconsPath: |
|
123 # default ist the 'StyleIcons' subdirectory of the |
|
124 # icons directory |
|
125 styleIconsPath = os.path.join( |
|
126 getConfig('ericIconDir'), "StyleIcons") |
|
127 |
|
128 styleIconsPath = Utilities.fromNativeSeparators( |
|
129 styleIconsPath) |
|
130 styleSheet = styleSheet.replace("${path}", styleIconsPath) |
|
131 self.scrollAreaWidgetContents.setStyleSheet(styleSheet) |
|
132 else: |
|
133 self.scrollAreaWidgetContents.setStyleSheet("") |
|
134 self.toolButton_1.menu().setStyleSheet( |
|
135 self.scrollAreaWidgetContents.styleSheet()) |
|
136 self.toolButton_2.menu().setStyleSheet( |
|
137 self.scrollAreaWidgetContents.styleSheet()) |
|
138 self.toolButton_3.menu().setStyleSheet( |
|
139 self.scrollAreaWidgetContents.styleSheet()) |
|
140 |
|
141 @pyqtSlot(int) |
|
142 def on_checkBox_stateChanged(self, state): |
|
143 """ |
|
144 Private slot to synchronize the checkbox state. |
|
145 |
|
146 @param state state of the enabled check box |
|
147 @type int |
|
148 """ |
|
149 self.disabledCheckBox.setCheckState(Qt.CheckState(state)) |