diff -r f6cff7759b24 -r 7157a39d4a0f ExtensionProtobuf/ConfigurationPage/ProtobufPage.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ExtensionProtobuf/ConfigurationPage/ProtobufPage.py Sun Dec 04 14:32:07 2022 +0100 @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2017 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the protobuf configuration page. +""" + +from PyQt6.QtCore import pyqtSlot + +from eric7.EricGui import EricPixmapCache +from eric7.EricWidgets.EricApplication import ericApp +from eric7.EricWidgets.EricPathPicker import EricPathPickerModes +from eric7.Preferences.ConfigurationPages.ConfigurationPageBase import ( + ConfigurationPageBase, +) + +from .Ui_ProtobufPage import Ui_ProtobufPage + + +class ProtobufPage(ConfigurationPageBase, Ui_ProtobufPage): + """ + Class implementing the protobuf configuration page. + """ + + def __init__(self, plugin): + """ + Constructor + + @param plugin reference to the plugin object + @type ProtobufExtensionPlugin + """ + super().__init__() + self.setupUi(self) + self.setObjectName("ProtobufPage") + + self.__plugin = plugin + + self.protocPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) + self.protocPicker.setToolTip( + self.tr( + "Press to select the Protobuf compiler via a file selection dialog." + ) + ) + + self.venvRefreshButton.setIcon(EricPixmapCache.getIcon("reload")) + + # set initial values + self.protocPicker.setText(self.__plugin.getPreferences("protoc")) + self.__populateAndSetVenvComboBox() + + def save(self): + """ + Public slot to save the protobuf configuration. + """ + self.__plugin.setPreferences("protoc", self.protocPicker.text()) + self.__plugin.setPreferences("grpcPythonEnv", self.venvComboBox.currentText()) + + def __populateAndSetVenvComboBox(self): + """ + Private method to populate and set the virtual environment combo box. + """ + self.venvComboBox.clear() + self.venvComboBox.addItems( + [""] + sorted(ericApp().getObject("VirtualEnvManager").getVirtualenvNames()) + ) + + # set initial value + venvName = self.__plugin.getPreferences("grpcPythonEnv") + self.venvComboBox.setCurrentText(venvName) + + @pyqtSlot() + def on_venvRefreshButton_clicked(self): + """ + Private slot to reload the list of virtual environments. + """ + self.__populateAndSetVenvComboBox()