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