Enhanced style sheet previewer and style sheet handling. eric7

Mon, 20 Dec 2021 14:51:29 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 20 Dec 2021 14:51:29 +0100
branch
eric7
changeset 8843
586ee2c4553a
parent 8842
80ce644a6067
child 8844
cae9a0840828

Enhanced style sheet previewer and style sheet handling.

eric7/EricWidgets/EricApplication.py file | annotate | diff | comparison | revisions
eric7/EricWidgets/EricMainWindow.py file | annotate | diff | comparison | revisions
eric7/Preferences/__init__.py file | annotate | diff | comparison | revisions
eric7/UI/Previewers/PreviewerQSS.py file | annotate | diff | comparison | revisions
eric7/UI/Previewers/PreviewerQSS.ui file | annotate | diff | comparison | revisions
--- a/eric7/EricWidgets/EricApplication.py	Sun Dec 19 19:38:18 2021 +0100
+++ b/eric7/EricWidgets/EricApplication.py	Mon Dec 20 14:51:29 2021 +0100
@@ -7,6 +7,8 @@
 Class implementing a specialized application class.
 """
 
+import os
+
 from PyQt6.QtCore import Qt, QCoreApplication
 from PyQt6.QtGui import QColor, QPalette
 from PyQt6.QtWidgets import QApplication
@@ -186,6 +188,9 @@
         @param filename name of the QSS style sheet file
         @type str
         """
+        import Preferences
+        from eric7config import getConfig
+        
         if filename:
             try:
                 with open(filename, "r", encoding="utf-8") as f:
@@ -204,6 +209,17 @@
         else:
             styleSheet = ""
         
+        if styleSheet:
+            # preprocess the style sheet to replace the placeholder for the
+            # path to the icons
+            styleIconsPath = Preferences.getUI("StyleIconsPath")
+            if not styleIconsPath:
+                # default ist the 'StyleIcons' subdirectory of the icons
+                # directory
+                styleIconsPath = os.path.join(
+                    getConfig('ericIconDir'), "StyleIcons")
+            styleSheet = styleSheet.replace("${path}", styleIconsPath)
+        
         if "QPalette {" in styleSheet:
             self.__setPaletteFromStyleSheet(styleSheet)
         
--- a/eric7/EricWidgets/EricMainWindow.py	Sun Dec 19 19:38:18 2021 +0100
+++ b/eric7/EricWidgets/EricMainWindow.py	Mon Dec 20 14:51:29 2021 +0100
@@ -7,11 +7,9 @@
 Module implementing a main window class with styling support.
 """
 
-from PyQt6.QtCore import QCoreApplication
 from PyQt6.QtWidgets import QMainWindow, QStyleFactory, QApplication
 
 from .EricApplication import ericApp
-from . import EricMessageBox
 
 
 class EricMainWindow(QMainWindow):
@@ -22,7 +20,8 @@
         """
         Constructor
         
-        @param parent reference to the parent widget (QWidget)
+        @param parent reference to the parent widget
+        @type QWidget
         """
         super().__init__(parent)
         
@@ -32,9 +31,11 @@
         """
         Public method to set the style of the interface.
         
-        @param styleName name of the style to set (string)
+        @param styleName name of the style to set
+        @type str
         @param styleSheetFile name of a style sheet file to read to overwrite
-            defaults of the given style (string)
+            defaults of the given style
+        @type str
         """
         # step 1: set the style
         style = None
@@ -47,22 +48,4 @@
             QApplication.setStyle(style)
         
         # step 2: set a style sheet
-        if styleSheetFile:
-            try:
-                with open(styleSheetFile, "r", encoding="utf-8") as f:
-                    styleSheet = f.read()
-            except OSError as msg:
-                EricMessageBox.warning(
-                    self,
-                    QCoreApplication.translate(
-                        "EricMainWindow", "Loading Style Sheet"),
-                    QCoreApplication.translate(
-                        "EricMainWindow",
-                        """<p>The Qt Style Sheet file <b>{0}</b> could"""
-                        """ not be read.<br>Reason: {1}</p>""")
-                    .format(styleSheetFile, str(msg)))
-                return
-        else:
-            styleSheet = ""
-        
-        ericApp().setStyleSheet(styleSheet)
+        ericApp().setStyleSheetFile(styleSheetFile)
--- a/eric7/Preferences/__init__.py	Sun Dec 19 19:38:18 2021 +0100
+++ b/eric7/Preferences/__init__.py	Mon Dec 20 14:51:29 2021 +0100
@@ -114,6 +114,7 @@
         "Language": "System",
         "Style": "System",
         "StyleSheet": "",
+        "StyleIconsPath": "",               # TODO: add config entry
         "ViewManager": "tabview",
         "LayoutType": "Sidebars",           # "Toolboxes" or "Sidebars"
         "CombinedLeftRightSidebar": False,  # place all tools into the
--- a/eric7/UI/Previewers/PreviewerQSS.py	Sun Dec 19 19:38:18 2021 +0100
+++ b/eric7/UI/Previewers/PreviewerQSS.py	Mon Dec 20 14:51:29 2021 +0100
@@ -14,11 +14,14 @@
     QWidget, QMenu, QLabel, QHeaderView, QListWidgetItem
 )
 
+from EricWidgets.EricPathPicker import EricPathPickerModes
+
 from .Ui_PreviewerQSS import Ui_PreviewerQSS
 
 import Preferences
 import UI.PixmapCache
 
+from eric7config import getConfig
 
 class PreviewerQSS(QWidget, Ui_PreviewerQSS):
     """
@@ -33,6 +36,11 @@
         super().__init__(parent)
         self.setupUi(self)
         
+        self.styleIconsPathPicker.setMode(
+            EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE)
+        
+        self.__lastEditor = None
+        
         # menu for the tool button
         self.__toolButtonMenu = QMenu(self)
         self.__toolButtonMenu.addAction(self.tr("Action 1"))
@@ -60,12 +68,24 @@
             self.iconsListWidget.addItem(QListWidgetItem(
                 UI.PixmapCache.getIcon(iconName), labelText))
     
+    @pyqtSlot(str)
+    def on_styleIconsPathPicker_textChanged(self, txt):
+        """
+        Private slot handling a change of the style icons path.
+        
+        @param txt name of the style icons directory
+        @type str
+        """
+        self.processEditor(self.__lastEditor)
+    
     def processEditor(self, editor=None):
         """
         Public slot to process an editor's text.
         
         @param editor editor to be processed (Editor)
         """
+        self.__lastEditor = editor
+        
         if editor is not None:
             fn = editor.getFileName()
             
@@ -79,6 +99,16 @@
             ):
                 styleSheet = editor.text()
                 if styleSheet:
+                    styleIconsPath = self.styleIconsPathPicker.text()
+                    if not styleIconsPath:
+                        styleIconsPath = Preferences.getUI("StyleIconsPath")
+                        if not styleIconsPath:
+                            # default ist the 'StyleIcons' subdirectory of the
+                            # icons directory
+                            styleIconsPath = os.path.join(
+                                getConfig('ericIconDir'), "StyleIcons")
+                        
+                    styleSheet = styleSheet.replace("${path}", styleIconsPath)
                     self.scrollAreaWidgetContents.setStyleSheet(styleSheet)
                 else:
                     self.scrollAreaWidgetContents.setStyleSheet("")
--- a/eric7/UI/Previewers/PreviewerQSS.ui	Sun Dec 19 19:38:18 2021 +0100
+++ b/eric7/UI/Previewers/PreviewerQSS.ui	Mon Dec 20 14:51:29 2021 +0100
@@ -31,6 +31,33 @@
     </widget>
    </item>
    <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_7">
+     <item>
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>Style Icons Path:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="EricPathPicker" name="styleIconsPathPicker" native="true">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="focusPolicy">
+        <enum>Qt::StrongFocus</enum>
+       </property>
+       <property name="toolTip">
+        <string>Enter the path to the icons used within the style sheet</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
     <widget class="QScrollArea" name="scrollArea">
      <property name="verticalScrollBarPolicy">
       <enum>Qt::ScrollBarAlwaysOn</enum>
@@ -47,7 +74,7 @@
         <x>0</x>
         <y>0</y>
         <width>566</width>
-        <height>738</height>
+        <height>712</height>
        </rect>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout_2">
@@ -1112,7 +1139,7 @@
                     <x>0</x>
                     <y>0</y>
                     <width>500</width>
-                    <height>426</height>
+                    <height>408</height>
                    </rect>
                   </property>
                   <layout class="QGridLayout" name="gridLayout_9">
@@ -1165,7 +1192,7 @@
                         <x>0</x>
                         <y>0</y>
                         <width>68</width>
-                        <height>344</height>
+                        <height>326</height>
                        </rect>
                       </property>
                       <attribute name="label">
@@ -1229,6 +1256,62 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>EricPathPicker</class>
+   <extends>QWidget</extends>
+   <header>EricWidgets/EricPathPicker.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <tabstops>
+  <tabstop>styleIconsPathPicker</tabstop>
+  <tabstop>scrollArea</tabstop>
+  <tabstop>tabWidget</tabstop>
+  <tabstop>groupBox_2</tabstop>
+  <tabstop>radioButton</tabstop>
+  <tabstop>checkBox</tabstop>
+  <tabstop>pushButton</tabstop>
+  <tabstop>toolButton</tabstop>
+  <tabstop>spinBox</tabstop>
+  <tabstop>doubleSpinBox</tabstop>
+  <tabstop>timeEdit</tabstop>
+  <tabstop>dateEdit</tabstop>
+  <tabstop>commandLinkButton</tabstop>
+  <tabstop>readOnlyComboBox</tabstop>
+  <tabstop>editableComboBox</tabstop>
+  <tabstop>lineEdit</tabstop>
+  <tabstop>passwordEdit</tabstop>
+  <tabstop>dateTimeEdit</tabstop>
+  <tabstop>horizontalSlider</tabstop>
+  <tabstop>verticalSlider</tabstop>
+  <tabstop>dial</tabstop>
+  <tabstop>disabledRadioButton</tabstop>
+  <tabstop>disabledCheckBox</tabstop>
+  <tabstop>disabledPushButton</tabstop>
+  <tabstop>disabledToolButton</tabstop>
+  <tabstop>disabledSpinBox</tabstop>
+  <tabstop>disabledDoubleSpinBox</tabstop>
+  <tabstop>disabledTimeEdit</tabstop>
+  <tabstop>disabledDateEdit</tabstop>
+  <tabstop>disabledCommandLinkButton</tabstop>
+  <tabstop>disabledReadOnlyComboBox</tabstop>
+  <tabstop>disabledEditableComboBox</tabstop>
+  <tabstop>disabledLineEdit</tabstop>
+  <tabstop>disabledPasswordEdit</tabstop>
+  <tabstop>disabledDateTimeEdit</tabstop>
+  <tabstop>disabledHorizontalSlider</tabstop>
+  <tabstop>disabledVerticalSlider</tabstop>
+  <tabstop>disabledDial</tabstop>
+  <tabstop>listWidget</tabstop>
+  <tabstop>iconsListWidget</tabstop>
+  <tabstop>table</tabstop>
+  <tabstop>tree</tabstop>
+  <tabstop>textBrowser</tabstop>
+  <tabstop>textEdit</tabstop>
+  <tabstop>calendarWidget</tabstop>
+  <tabstop>scrollArea_2</tabstop>
+ </tabstops>
  <resources/>
  <connections>
   <connection>

eric ide

mercurial