MicroPython: made the chart widget color scheme aware and added a config option to configure a specific chart color theme.

Mon, 13 Apr 2020 16:26:46 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 13 Apr 2020 16:26:46 +0200
changeset 7535
dac9bc72a0f3
parent 7534
5441fa55cb0d
child 7536
861e46f99d65

MicroPython: made the chart widget color scheme aware and added a config option to configure a specific chart color theme.

eric6/MicroPython/MicroPythonGraphWidget.py file | annotate | diff | comparison | revisions
eric6/MicroPython/MicroPythonWidget.py file | annotate | diff | comparison | revisions
eric6/Preferences/ConfigurationPages/MicroPythonPage.py file | annotate | diff | comparison | revisions
eric6/Preferences/ConfigurationPages/MicroPythonPage.ui file | annotate | diff | comparison | revisions
eric6/Preferences/__init__.py file | annotate | diff | comparison | revisions
--- a/eric6/MicroPython/MicroPythonGraphWidget.py	Mon Apr 13 11:30:24 2020 +0200
+++ b/eric6/MicroPython/MicroPythonGraphWidget.py	Mon Apr 13 16:26:46 2020 +0200
@@ -23,6 +23,7 @@
 from PyQt5.QtChart import QChartView, QChart, QLineSeries, QValueAxis
 
 from E5Gui import E5MessageBox
+from E5Gui.E5Application import e5App
 
 import UI.PixmapCache
 import Preferences
@@ -113,9 +114,26 @@
         self.__chart.setAxisY(self.__axisY, self.__series[0])
         self.__chartView.setChart(self.__chart)
         self.__chartView.setRenderHint(QPainter.Antialiasing)
+        self.preferencesChanged()
         
         self.__maxXSpinBox.valueChanged.connect(self.__handleMaxXChanged)
     
+    @pyqtSlot()
+    def preferencesChanged(self):
+        """
+        Public slot to apply changed preferences.
+        """
+        chartColorTheme = Preferences.getMicroPython("ChartColorTheme")
+        if chartColorTheme == -1:
+            # automatic selection of light or dark depending on desktop
+            # color scheme
+            if e5App().usesDarkPalette():
+                self.__chart.setTheme(QChart.ChartThemeDark)
+            else:
+                self.__chart.setTheme(QChart.ChartThemeLight)
+        else:
+            self.__chart.setTheme(chartColorTheme)
+    
     @pyqtSlot(bytes)
     def processData(self, data):
         """
--- a/eric6/MicroPython/MicroPythonWidget.py	Mon Apr 13 11:30:24 2020 +0200
+++ b/eric6/MicroPython/MicroPythonWidget.py	Mon Apr 13 16:26:46 2020 +0200
@@ -136,6 +136,24 @@
         16: QBrush(QColor(0, 255, 255)),
         17: QBrush(QColor(255, 255, 255)),
     },
+    "Ubuntu (dark)": {
+        0: QBrush(QColor(96, 96, 96)),
+        1: QBrush(QColor(235, 58, 45)),
+        2: QBrush(QColor(57, 181, 74)),
+        3: QBrush(QColor(255, 199, 29)),
+        4: QBrush(QColor(25, 56, 230)),
+        5: QBrush(QColor(200, 64, 193)),
+        6: QBrush(QColor(48, 200, 255)),
+        7: QBrush(QColor(204, 204, 204)),
+        10: QBrush(QColor(128, 128, 128)),
+        11: QBrush(QColor(255, 0, 0)),
+        12: QBrush(QColor(0, 255, 0)),
+        13: QBrush(QColor(255, 255, 0)),
+        14: QBrush(QColor(0, 0, 255)),
+        15: QBrush(QColor(255, 0, 255)),
+        16: QBrush(QColor(0, 255, 255)),
+        17: QBrush(QColor(255, 255, 255)),
+    },
 }
 
 
@@ -213,6 +231,7 @@
         self.__currentZoom = 0
         
         self.__fileManagerWidget = None
+        self.__chartWidget = None
         
         if HAS_QTSERIALPORT:
             self.__interface = MicroPythonCommandsInterface(self)
@@ -303,6 +322,9 @@
             self.replEdit.setLineWrapMode(QTextEdit.WidgetWidth)
         else:
             self.replEdit.setLineWrapMode(QTextEdit.NoWrap)
+        
+        if self.__chartWidget is not None:
+            self.__chartWidget.preferencesChanged()
     
     def commandsInterface(self):
         """
@@ -370,7 +392,7 @@
         if "files" in kwargs:
             self.filesButton.setEnabled(kwargs["files"])
         if "chart" in kwargs:
-            self.chartButton.setEnabled(kwargs["chart"])
+            self.chartButton.setEnabled(kwargs["chart"] and HAS_QTCHART)
     
     @pyqtSlot(QPoint)
     def __showContextMenu(self, pos):
--- a/eric6/Preferences/ConfigurationPages/MicroPythonPage.py	Mon Apr 13 11:30:24 2020 +0200
+++ b/eric6/Preferences/ConfigurationPages/MicroPythonPage.py	Mon Apr 13 16:26:46 2020 +0200
@@ -35,6 +35,31 @@
         
         self.colorSchemeComboBox.addItems(sorted(AnsiColorSchemes.keys()))
         
+        # populate the chart theme combobox
+        try:
+            from PyQt5.QtChart import QChart
+            
+            self.chartThemeComboBox.addItem(self.tr("Automatic"),
+                                            -1)
+            self.chartThemeComboBox.addItem(self.tr("Light"),
+                                            QChart.ChartThemeLight);
+            self.chartThemeComboBox.addItem(self.tr("Dark"),
+                                            QChart.ChartThemeDark);
+            self.chartThemeComboBox.addItem(self.tr("Blue Cerulean"),
+                                            QChart.ChartThemeBlueCerulean);
+            self.chartThemeComboBox.addItem(self.tr("Brown Sand"),
+                                            QChart.ChartThemeBrownSand);
+            self.chartThemeComboBox.addItem(self.tr("Blue NCS"),
+                                            QChart.ChartThemeBlueNcs);
+            self.chartThemeComboBox.addItem(self.tr("High Contrast"),
+                                            QChart.ChartThemeHighContrast);
+            self.chartThemeComboBox.addItem(self.tr("Blue Icy"),
+                                            QChart.ChartThemeBlueIcy);
+            self.chartThemeComboBox.addItem(self.tr("Qt"),
+                                            QChart.ChartThemeQt);
+        except ImportError:
+            self.chartThemeComboBox.setEnabled(False)
+        
         self.mpyCrossPicker.setMode(E5PathPickerModes.OpenFileMode)
         self.mpyCrossPicker.setFilters(self.tr("All Files (*)"))
         
@@ -42,26 +67,44 @@
         self.dfuUtilPathPicker.setFilters(self.tr("All Files (*)"))
         
         # set initial values
+        # serial link parameters
         self.timeoutSpinBox.setValue(
             Preferences.getMicroPython("SerialTimeout") / 1000)
         # converted to seconds
         self.syncTimeCheckBox.setChecked(
             Preferences.getMicroPython("SyncTimeAfterConnect"))
+        
+        # REPL Pane
         self.colorSchemeComboBox.setCurrentIndex(
             self.colorSchemeComboBox.findText(
                 Preferences.getMicroPython("ColorScheme")))
         self.replWrapCheckBox.setChecked(
             Preferences.getMicroPython("ReplLineWrap"))
+        
+        # Chart Pane
+        index = self.chartThemeComboBox.findData(
+            Preferences.getMicroPython("ChartColorTheme"))
+        if index < 0:
+            index = 0
+        self.chartThemeComboBox.setCurrentIndex(index)
+        
+        # MPY Cross Compiler
         self.mpyCrossPicker.setText(
             Preferences.getMicroPython("MpyCrossCompiler"))
+        
+        # PyBoard specifics
         self.dfuUtilPathPicker.setText(
             Preferences.getMicroPython("DfuUtilPath"))
+        
+        # firmware URL
         self.micropythonFirmwareUrlLineEdit.setText(
             Preferences.getMicroPython("MicroPythonFirmwareUrl"))
         self.circuitpythonFirmwareUrlLineEdit.setText(
             Preferences.getMicroPython("CircuitPythonFirmwareUrl"))
         self.microbitFirmwareUrlLineEdit.setText(
             Preferences.getMicroPython("MicrobitFirmwareUrl"))
+        
+        # documentation URL
         self.micropythonDocuUrlLineEdit.setText(
             Preferences.getMicroPython("MicroPythonDocuUrl"))
         self.circuitpythonDocuUrlLineEdit.setText(
@@ -73,6 +116,7 @@
         """
         Public slot to save the MicroPython configuration.
         """
+        # serial link parameters
         Preferences.setMicroPython(
             "SerialTimeout",
             self.timeoutSpinBox.value() * 1000)
@@ -80,18 +124,31 @@
         Preferences.setMicroPython(
             "SyncTimeAfterConnect",
             self.syncTimeCheckBox.isChecked())
+        
+        # REPL Pane
         Preferences.setMicroPython(
             "ColorScheme",
             self.colorSchemeComboBox.currentText())
         Preferences.setMicroPython(
             "ReplLineWrap",
             self.replWrapCheckBox.isChecked())
+        
+        # Chart Pane
+        Preferences.setMicroPython(
+            "ChartColorTheme",
+            self.chartThemeComboBox.currentData())
+        
+        # MPY Cross Compiler
         Preferences.setMicroPython(
             "MpyCrossCompiler",
             self.mpyCrossPicker.text())
+        
+        # PyBoard specifics
         Preferences.setMicroPython(
             "DfuUtilPath",
             self.dfuUtilPathPicker.text())
+        
+        # firmware URL
         Preferences.setMicroPython(
             "MicroPythonFirmwareUrl",
             self.micropythonFirmwareUrlLineEdit.text())
@@ -101,6 +158,8 @@
         Preferences.setMicroPython(
             "MicrobitFirmwareUrl",
             self.microbitFirmwareUrlLineEdit.text())
+        
+        # documentation URL
         Preferences.setMicroPython(
             "MicroPythonDocuUrl",
             self.micropythonDocuUrlLineEdit.text())
--- a/eric6/Preferences/ConfigurationPages/MicroPythonPage.ui	Mon Apr 13 11:30:24 2020 +0200
+++ b/eric6/Preferences/ConfigurationPages/MicroPythonPage.ui	Mon Apr 13 16:26:46 2020 +0200
@@ -135,6 +135,35 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="groupBox_7">
+     <property name="title">
+      <string>Chart Pane</string>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_3">
+      <item>
+       <widget class="QLabel" name="label_11">
+        <property name="text">
+         <string>Color Theme:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QComboBox" name="chartThemeComboBox">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="toolTip">
+         <string>Select the color scheme of the chart</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <widget class="QGroupBox" name="groupBox_3">
      <property name="title">
       <string>MPY Cross Compiler</string>
@@ -333,6 +362,7 @@
   <tabstop>syncTimeCheckBox</tabstop>
   <tabstop>colorSchemeComboBox</tabstop>
   <tabstop>replWrapCheckBox</tabstop>
+  <tabstop>chartThemeComboBox</tabstop>
   <tabstop>mpyCrossPicker</tabstop>
   <tabstop>dfuUtilPathPicker</tabstop>
   <tabstop>micropythonFirmwareUrlLineEdit</tabstop>
--- a/eric6/Preferences/__init__.py	Mon Apr 13 11:30:24 2020 +0200
+++ b/eric6/Preferences/__init__.py	Mon Apr 13 16:26:46 2020 +0200
@@ -1468,6 +1468,8 @@
         "SyncTimeAfterConnect": True,
         "ShowHiddenLocal": True,
         "ShowHiddenDevice": True,
+        "ChartColorTheme": -1,          # -1 = automatic,
+                                        # QChart.ChartTheme otherwise
         "MpyCrossCompiler": "",         # path of the mpy-cross compiler
         "DfuUtilPath": "",              # path of the dfu-util flashing tool
         "MicroPythonDocuUrl":

eric ide

mercurial