|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2017 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the protobuf configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 |
|
12 from eric7.EricGui import EricPixmapCache |
|
13 from eric7.EricWidgets.EricApplication import ericApp |
|
14 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
|
15 from eric7.Preferences.ConfigurationPages.ConfigurationPageBase import ( |
|
16 ConfigurationPageBase, |
|
17 ) |
|
18 |
|
19 from .Ui_ProtobufPage import Ui_ProtobufPage |
|
20 |
|
21 |
|
22 class ProtobufPage(ConfigurationPageBase, Ui_ProtobufPage): |
|
23 """ |
|
24 Class implementing the protobuf configuration page. |
|
25 """ |
|
26 |
|
27 def __init__(self, plugin): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param plugin reference to the plugin object |
|
32 @type ProtobufExtensionPlugin |
|
33 """ |
|
34 super().__init__() |
|
35 self.setupUi(self) |
|
36 self.setObjectName("ProtobufPage") |
|
37 |
|
38 self.__plugin = plugin |
|
39 |
|
40 self.protocPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
|
41 self.protocPicker.setToolTip( |
|
42 self.tr( |
|
43 "Press to select the Protobuf compiler via a file selection dialog." |
|
44 ) |
|
45 ) |
|
46 |
|
47 self.venvRefreshButton.setIcon(EricPixmapCache.getIcon("reload")) |
|
48 |
|
49 # set initial values |
|
50 self.protocPicker.setText(self.__plugin.getPreferences("protoc")) |
|
51 self.__populateAndSetVenvComboBox() |
|
52 |
|
53 def save(self): |
|
54 """ |
|
55 Public slot to save the protobuf configuration. |
|
56 """ |
|
57 self.__plugin.setPreferences("protoc", self.protocPicker.text()) |
|
58 self.__plugin.setPreferences("grpcPythonEnv", self.venvComboBox.currentText()) |
|
59 |
|
60 def __populateAndSetVenvComboBox(self): |
|
61 """ |
|
62 Private method to populate and set the virtual environment combo box. |
|
63 """ |
|
64 self.venvComboBox.clear() |
|
65 self.venvComboBox.addItems( |
|
66 [""] + sorted(ericApp().getObject("VirtualEnvManager").getVirtualenvNames()) |
|
67 ) |
|
68 |
|
69 # set initial value |
|
70 venvName = self.__plugin.getPreferences("grpcPythonEnv") |
|
71 self.venvComboBox.setCurrentText(venvName) |
|
72 |
|
73 @pyqtSlot() |
|
74 def on_venvRefreshButton_clicked(self): |
|
75 """ |
|
76 Private slot to reload the list of virtual environments. |
|
77 """ |
|
78 self.__populateAndSetVenvComboBox() |