本文整理汇总了Python中leap.bitmask.config.leapsettings.LeapSettings.set_selected_gateway方法的典型用法代码示例。如果您正苦于以下问题:Python LeapSettings.set_selected_gateway方法的具体用法?Python LeapSettings.set_selected_gateway怎么用?Python LeapSettings.set_selected_gateway使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类leap.bitmask.config.leapsettings.LeapSettings
的用法示例。
在下文中一共展示了LeapSettings.set_selected_gateway方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import set_selected_gateway [as 别名]
#.........这里部分代码省略.........
:param domain: the domain name of the provider.
:type domain: str
:rtype: ProviderConfig or None if there is a problem loading the config
"""
provider_config = ProviderConfig()
provider_config_path = os.path.join(
"leap", "providers", domain, "provider.json")
if not provider_config.load(provider_config_path):
provider_config = None
return provider_config
def _save_selected_gateway(self, provider):
"""
SLOT
TRIGGERS:
self.ui.pbSaveGateway.clicked
Saves the new gateway setting to the configuration file.
:param provider: the provider config that we need to save.
:type provider: str
"""
gateway = self.ui.cbGateways.currentText()
if gateway == self.AUTOMATIC_GATEWAY_LABEL:
gateway = self._settings.GATEWAY_AUTOMATIC
else:
idx = self.ui.cbGateways.currentIndex()
gateway = self.ui.cbGateways.itemData(idx)
self._settings.set_selected_gateway(provider, gateway)
msg = self.tr(
"Gateway settings for provider '{0}' saved.".format(provider))
logger.debug(msg)
self._set_providers_gateway_status(msg, success=True)
def _populate_gateways(self, domain):
"""
SLOT
TRIGGERS:
self.ui.cbProvidersGateway.currentIndexChanged[unicode]
Loads the gateways that the provider provides into the UI for
the user to select.
:param domain: the domain of the provider to load gateways from.
:type domain: str
"""
# We hide the maybe-visible status label after a change
self.ui.lblProvidersGatewayStatus.setVisible(False)
if not domain:
return
try:
# disconnect prevoiusly connected save method
self.ui.pbSaveGateway.clicked.disconnect()
except RuntimeError:
pass # Signal was not connected
# set the proper connection for the 'save' button
save_gateway = partial(self._save_selected_gateway, domain)
示例2: EIPPreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import set_selected_gateway [as 别名]
#.........这里部分代码省略.........
for provider, is_initialized in providers:
label = provider
if not is_initialized:
label += self.tr(" (uninitialized)")
self.ui.cbProvidersGateway.addItem(label, userData=provider)
self.ui.cbProvidersGateway.blockSignals(False)
# Select provider by name
domain = self._selected_domain
if domain is not None:
provider_index = self.ui.cbProvidersGateway.findText(
domain, QtCore.Qt.MatchStartsWith)
self.ui.cbProvidersGateway.setCurrentIndex(provider_index)
@QtCore.Slot(str)
def _save_selected_gateway(self, provider):
"""
TRIGGERS:
self.ui.pbSaveGateway.clicked
Saves the new gateway setting to the configuration file.
:param provider: the provider config that we need to save.
:type provider: str
"""
gateway = self.ui.cbGateways.currentText()
if gateway == self.AUTOMATIC_GATEWAY_LABEL:
gateway = self._settings.GATEWAY_AUTOMATIC
else:
idx = self.ui.cbGateways.currentIndex()
gateway = self.ui.cbGateways.itemData(idx)
self._settings.set_selected_gateway(provider, gateway)
self._backend.settings_set_selected_gateway(provider=provider,
gateway=gateway)
msg = self.tr(
"Gateway settings for provider '{0}' saved.").format(provider)
self._set_providers_gateway_status(msg, success=True)
@QtCore.Slot(int)
def _populate_gateways(self, domain_idx):
"""
TRIGGERS:
self.ui.cbProvidersGateway.currentIndexChanged[unicode]
Loads the gateways that the provider provides into the UI for
the user to select.
:param domain: the domain index of the provider to load gateways from.
:type domain: int
"""
# We hide the maybe-visible status label after a change
self.ui.lblProvidersGatewayStatus.setVisible(False)
if domain_idx == -1:
return
domain = self.ui.cbProvidersGateway.itemData(domain_idx)
self._selected_domain = domain
self._backend.eip_get_gateways_list(domain=domain)
@QtCore.Slot(list)
def _update_gateways_list(self, gateways):
示例3: EIPPreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import set_selected_gateway [as 别名]
#.........这里部分代码省略.........
"""
Add the client's configured providers to the providers combo boxes.
"""
self.ui.cbProvidersGateway.clear()
self.ui.cbProvidersEIP.clear()
providers = self._settings.get_configured_providers()
if not providers:
self.ui.gbAutomaticEIP.setEnabled(False)
self.ui.gbGatewaySelector.setEnabled(False)
return
for provider in providers:
self.ui.cbProvidersGateway.addItem(provider)
self.ui.cbProvidersEIP.addItem(provider)
def _save_selected_gateway(self, provider):
"""
SLOT
TRIGGERS:
self.ui.pbSaveGateway.clicked
Saves the new gateway setting to the configuration file.
:param provider: the provider config that we need to save.
:type provider: str
"""
gateway = self.ui.cbGateways.currentText()
if gateway == self.AUTOMATIC_GATEWAY_LABEL:
gateway = self._settings.GATEWAY_AUTOMATIC
else:
idx = self.ui.cbGateways.currentIndex()
gateway = self.ui.cbGateways.itemData(idx)
self._settings.set_selected_gateway(provider, gateway)
msg = self.tr(
"Gateway settings for provider '{0}' saved.").format(provider)
self._set_providers_gateway_status(msg, success=True)
def _populate_gateways(self, domain):
"""
SLOT
TRIGGERS:
self.ui.cbProvidersGateway.currentIndexChanged[unicode]
Loads the gateways that the provider provides into the UI for
the user to select.
:param domain: the domain of the provider to load gateways from.
:type domain: str
"""
# We hide the maybe-visible status label after a change
self.ui.lblProvidersGatewayStatus.setVisible(False)
if not domain:
return
try:
# disconnect previously connected save method
self.ui.pbSaveGateway.clicked.disconnect()
except RuntimeError:
pass # Signal was not connected
# set the proper connection for the 'save' button
save_gateway = partial(self._save_selected_gateway, domain)
self.ui.pbSaveGateway.clicked.connect(save_gateway)
eip_config = EIPConfig()
provider_config = ProviderConfig.get_provider_config(domain)
eip_config_path = os.path.join("leap", "providers",
domain, "eip-service.json")
api_version = provider_config.get_api_version()
eip_config.set_api_version(api_version)
eip_loaded = eip_config.load(eip_config_path)
if not eip_loaded or provider_config is None:
self._set_providers_gateway_status(
self.tr("There was a problem with configuration files."),
error=True)
return
gateways = VPNGatewaySelector(eip_config).get_gateways_list()
logger.debug(gateways)
self.ui.cbGateways.clear()
self.ui.cbGateways.addItem(self.AUTOMATIC_GATEWAY_LABEL)
# Add the available gateways and
# select the one stored in configuration file.
selected_gateway = self._settings.get_selected_gateway(domain)
index = 0
for idx, (gw_name, gw_ip) in enumerate(gateways):
gateway = "{0} ({1})".format(gw_name, gw_ip)
self.ui.cbGateways.addItem(gateway, gw_ip)
if gw_ip == selected_gateway:
index = idx + 1
self.ui.cbGateways.setCurrentIndex(index)
示例4: EIPPreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import set_selected_gateway [as 别名]
class EIPPreferencesWindow(QtGui.QDialog):
"""
Window that displays the EIP preferences.
"""
def __init__(self, parent, domain):
"""
:param parent: parent object of the EIPPreferencesWindow.
:type parent: QWidget
:param domain: the selected by default domain.
:type domain: unicode
"""
QtGui.QDialog.__init__(self, parent)
self.AUTOMATIC_GATEWAY_LABEL = self.tr("Automatic")
self._settings = LeapSettings()
# Load UI
self.ui = Ui_EIPPreferences()
self.ui.setupUi(self)
self.ui.lblProvidersGatewayStatus.setVisible(False)
# Connections
self.ui.cbProvidersGateway.currentIndexChanged[int].connect(
self._populate_gateways)
self.ui.cbGateways.currentIndexChanged[unicode].connect(
lambda x: self.ui.lblProvidersGatewayStatus.setVisible(False))
self._add_configured_providers(domain)
def _set_providers_gateway_status(self, status, success=False,
error=False):
"""
Sets the status label for the gateway change.
:param status: status message to display, can be HTML
:type status: str
:param success: is set to True if we should display the
message as green
:type success: bool
:param error: is set to True if we should display the
message as red
:type error: bool
"""
if success:
status = "<font color='green'><b>%s</b></font>" % (status,)
elif error:
status = "<font color='red'><b>%s</b></font>" % (status,)
self.ui.lblProvidersGatewayStatus.setVisible(True)
self.ui.lblProvidersGatewayStatus.setText(status)
def _add_configured_providers(self, domain=None):
"""
Add the client's configured providers to the providers combo boxes.
:param domain: the domain to be selected by default.
:type domain: unicode
"""
self.ui.cbProvidersGateway.clear()
providers = self._settings.get_configured_providers()
if not providers:
self.ui.gbGatewaySelector.setEnabled(False)
return
for provider in providers:
label = provider
eip_config_path = get_eipconfig_path(provider, relative=False)
if not os.path.isfile(eip_config_path):
label = provider + self.tr(" (uninitialized)")
self.ui.cbProvidersGateway.addItem(label, userData=provider)
# Select provider by name
if domain is not None:
provider_index = self.ui.cbProvidersGateway.findText(
domain, QtCore.Qt.MatchStartsWith)
self.ui.cbProvidersGateway.setCurrentIndex(provider_index)
def _save_selected_gateway(self, provider):
"""
SLOT
TRIGGERS:
self.ui.pbSaveGateway.clicked
Saves the new gateway setting to the configuration file.
:param provider: the provider config that we need to save.
:type provider: str
"""
gateway = self.ui.cbGateways.currentText()
if gateway == self.AUTOMATIC_GATEWAY_LABEL:
gateway = self._settings.GATEWAY_AUTOMATIC
else:
idx = self.ui.cbGateways.currentIndex()
gateway = self.ui.cbGateways.itemData(idx)
self._settings.set_selected_gateway(provider, gateway)
msg = self.tr(
#.........这里部分代码省略.........