src/eric7/Preferences/ConfigurationPages/PythonPage.py

Mon, 07 Nov 2022 17:19:58 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 07 Nov 2022 17:19:58 +0100
branch
eric7
changeset 9482
a2bc06a54d9d
parent 9473
3f23dbf37dbe
child 9653
e67609152c5e
permissions
-rw-r--r--

Corrected/acknowledged some bad import style and removed some obsolete code.

# -*- coding: utf-8 -*-

# Copyright (c) 2006 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the Python configuration page.
"""

from PyQt6.QtCore import pyqtSlot

from eric7 import Preferences
from eric7.Utilities import supportedCodecs

from .ConfigurationPageBase import ConfigurationPageBase
from .Ui_PythonPage import Ui_PythonPage


class PythonPage(ConfigurationPageBase, Ui_PythonPage):
    """
    Class implementing the Python configuration page.
    """

    def __init__(self):
        """
        Constructor
        """
        super().__init__()
        self.setupUi(self)
        self.setObjectName("PythonPage")

        self.stringEncodingComboBox.addItems(sorted(supportedCodecs))
        self.ioEncodingComboBox.addItems(sorted(supportedCodecs))

        # set initial values
        index = self.stringEncodingComboBox.findText(
            Preferences.getSystem("StringEncoding")
        )
        self.stringEncodingComboBox.setCurrentIndex(index)
        index = self.ioEncodingComboBox.findText(Preferences.getSystem("IOEncoding"))
        self.ioEncodingComboBox.setCurrentIndex(index)

        self.showCodeInfoDetailsCeckBox.setChecked(
            Preferences.getPython("DisViewerExpandCodeInfoDetails")
        )

        # these are the same as in the debugger pages
        self.py3ExtensionsEdit.setText(Preferences.getDebugger("Python3Extensions"))

        self.py3EnvironmentEdit.setText(Preferences.getDebugger("Python3VirtualEnv"))

        # colours
        self.initColour(
            "ASTViewerErrorColor", self.astErrorItemButton, Preferences.getPython
        )
        self.initColour(
            "DisViewerErrorColor", self.disErrorItemButton, Preferences.getPython
        )
        self.initColour(
            "DisViewerCurrentColor",
            self.disCurrentInstructionButton,
            Preferences.getPython,
        )
        self.initColour(
            "DisViewerLabeledColor",
            self.disLabeledInstructionButton,
            Preferences.getPython,
        )

    def save(self):
        """
        Public slot to save the Python configuration.
        """
        enc = self.stringEncodingComboBox.currentText()
        if not enc:
            enc = "utf-8"
        Preferences.setSystem("StringEncoding", enc)

        enc = self.ioEncodingComboBox.currentText()
        if not enc:
            enc = "utf-8"
        Preferences.setSystem("IOEncoding", enc)

        Preferences.setDebugger("Python3Extensions", self.py3ExtensionsEdit.text())

        Preferences.setPython(
            "DisViewerExpandCodeInfoDetails",
            self.showCodeInfoDetailsCeckBox.isChecked(),
        )

        # colours
        self.saveColours(Preferences.setPython)

    @pyqtSlot()
    def on_refreshButton_clicked(self):
        """
        Private slot handling a click of the refresh button.
        """
        self.py3EnvironmentEdit.setText(Preferences.getDebugger("Python3VirtualEnv"))


def create(dlg):
    """
    Module function to create the configuration page.

    @param dlg reference to the configuration dialog
    @return reference to the instantiated page (ConfigurationPageBase)
    """
    page = PythonPage()
    return page

eric ide

mercurial