connectors/WAMP_dialog.py
author Edouard Tisserant
Wed, 20 Mar 2019 11:34:41 +0100
branchsearch_in_CTN
changeset 2524 c80b0d864475
parent 2521 48ebcbe7f19b
child 2610 7e31997b2799
permissions -rw-r--r--
WIP adding searching capabilities in python files. was done :
- fixed stub CTN search results so that they can be accepted by search result panel
- worked on search result panel so that it can display those CTN results
- made search result panel display correctly stub search result, for variables and body matches
- EditProjectElement now opens CTN node as well as PlcOpen project nodes
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.

from __future__ import absolute_import

from itertools import repeat, islice, chain

from connectors.SchemeEditor import SchemeEditor

Schemes = ["WAMP", "WAMPS"]

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


class WAMP_dialog(SchemeEditor):
    def __init__(self, *args, **kwargs):
        self.model = model
        self.EnableIDSelector = True
        SchemeEditor.__init__(self, *args, **kwargs)

    # pylint: disable=unused-variable
    def SetLoc(self, loc):
        hostport, realm, ID = list(islice(chain(loc.split("#"), repeat("")), 3))
        host, port = list(islice(chain(hostport.split(":"), repeat("")), 2))
        self.SetFields(locals())

    def GetLoc(self):
        fields = self.GetFields()

        # TODO : input validation test

        template = "{host}" + \
                   (":{port}" if fields['port'] else '') +\
                   "#{realm}#{ID}"

        return template.format(**fields)