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