connectors/PYRO_dialog.py
author Edouard Tisserant
Tue, 20 Nov 2018 11:32:42 +0100
changeset 2339 48b4eba13064
parent 2334 d1470c052662
child 2492 7dd551ac2fa0
permissions -rw-r--r--
IDManager : refactored a bit, moved some code into PSKManagement.py. Now captures URI and PSK on new PYRO(S) and propose them when editing URI. Import/export still to be implemented.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.

from __future__ import absolute_import

from itertools import repeat, islice, chain
import wx

from connectors.SchemeEditor import SchemeEditor


model = [('host',_("Host:")),
         ('port',_("Port:"))]

# (scheme, model, secure)
models = [("LOCAL", [], False), ("PYRO", model, False), ("PYROS", model, True)]

Schemes = list(zip(*models)[0])

_PerSchemeConf = {sch : (mod,sec) for sch,mod,sec in models}

class PYRO_dialog(SchemeEditor):
    def __init__(self, scheme, *args, **kwargs):
       
        # ID selector is enabled only on PYROS (secure)
        self.model, self.EnableIDSelector = _PerSchemeConf[scheme]

        SchemeEditor.__init__(self, scheme, *args, **kwargs)

    def SetLoc(self, loc):
        hostport, ID = list(islice(chain(loc.split("#"), repeat("")),2))
        host, port = list(islice(chain(hostport.split(":"), repeat("")),2))
        self.SetFields(locals())

    def GetLoc(self):
        if self.model:
            fields = self.GetFields()
            template = "{host}"
            if fields['port']:
                template += ":{port}" 
            if fields['ID']:
                template += "#{ID}" 

            return template.format(**fields)
        return ''