|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Python configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 |
|
12 from .ConfigurationPageBase import ConfigurationPageBase |
|
13 from .Ui_PythonPage import Ui_PythonPage |
|
14 |
|
15 import Preferences |
|
16 from Utilities import supportedCodecs |
|
17 |
|
18 |
|
19 class PythonPage(ConfigurationPageBase, Ui_PythonPage): |
|
20 """ |
|
21 Class implementing the Python configuration page. |
|
22 """ |
|
23 def __init__(self): |
|
24 """ |
|
25 Constructor |
|
26 """ |
|
27 super().__init__() |
|
28 self.setupUi(self) |
|
29 self.setObjectName("PythonPage") |
|
30 |
|
31 self.stringEncodingComboBox.addItems(sorted(supportedCodecs)) |
|
32 self.ioEncodingComboBox.addItems(sorted(supportedCodecs)) |
|
33 |
|
34 # set initial values |
|
35 index = self.stringEncodingComboBox.findText( |
|
36 Preferences.getSystem("StringEncoding")) |
|
37 self.stringEncodingComboBox.setCurrentIndex(index) |
|
38 index = self.ioEncodingComboBox.findText( |
|
39 Preferences.getSystem("IOEncoding")) |
|
40 self.ioEncodingComboBox.setCurrentIndex(index) |
|
41 |
|
42 self.showCodeInfoDetailsCeckBox.setChecked( |
|
43 Preferences.getPython("DisViewerExpandCodeInfoDetails")) |
|
44 |
|
45 # these are the same as in the debugger pages |
|
46 self.py3ExtensionsEdit.setText( |
|
47 Preferences.getDebugger("Python3Extensions")) |
|
48 |
|
49 self.py3EnvironmentEdit.setText( |
|
50 Preferences.getDebugger("Python3VirtualEnv")) |
|
51 |
|
52 # colours |
|
53 self.initColour("ASTViewerErrorColor", |
|
54 self.astErrorItemButton, |
|
55 Preferences.getPython) |
|
56 self.initColour("DisViewerErrorColor", |
|
57 self.disErrorItemButton, |
|
58 Preferences.getPython) |
|
59 self.initColour("DisViewerCurrentColor", |
|
60 self.disCurrentInstructionButton, |
|
61 Preferences.getPython) |
|
62 self.initColour("DisViewerLabeledColor", |
|
63 self.disLabeledInstructionButton, |
|
64 Preferences.getPython) |
|
65 |
|
66 def save(self): |
|
67 """ |
|
68 Public slot to save the Python configuration. |
|
69 """ |
|
70 enc = self.stringEncodingComboBox.currentText() |
|
71 if not enc: |
|
72 enc = "utf-8" |
|
73 Preferences.setSystem("StringEncoding", enc) |
|
74 |
|
75 enc = self.ioEncodingComboBox.currentText() |
|
76 if not enc: |
|
77 enc = "utf-8" |
|
78 Preferences.setSystem("IOEncoding", enc) |
|
79 |
|
80 Preferences.setDebugger( |
|
81 "Python3Extensions", |
|
82 self.py3ExtensionsEdit.text()) |
|
83 |
|
84 Preferences.setPython( |
|
85 "DisViewerExpandCodeInfoDetails", |
|
86 self.showCodeInfoDetailsCeckBox.isChecked()) |
|
87 |
|
88 # colours |
|
89 self.saveColours(Preferences.setPython) |
|
90 |
|
91 @pyqtSlot() |
|
92 def on_refreshButton_clicked(self): |
|
93 """ |
|
94 Private slot handling a click of the refresh button. |
|
95 """ |
|
96 self.py3EnvironmentEdit.setText( |
|
97 Preferences.getDebugger("Python3VirtualEnv")) |
|
98 |
|
99 |
|
100 def create(dlg): |
|
101 """ |
|
102 Module function to create the configuration page. |
|
103 |
|
104 @param dlg reference to the configuration dialog |
|
105 @return reference to the instantiated page (ConfigurationPageBase) |
|
106 """ |
|
107 page = PythonPage() |
|
108 return page |