#2476 Added uri location editor, getting connectors from list in Beremiz.
--- a/connectors/PYRO/__init__.py Thu Apr 19 09:50:00 2018 +0200
+++ b/connectors/PYRO/__init__.py Fri Apr 20 11:21:20 2018 +0200
@@ -36,6 +36,9 @@
import Pyro.util
from Pyro.errors import PyroError
+import wx
+from controls.UriLocationEditor import IConnectorPanel
+from zope.interface import implementer
service_type = '_PYRO._tcp.local.'
# this module attribute contains a list of DNS-SD (Zeroconf) service types
@@ -44,6 +47,8 @@
# for connectors that do not support DNS-SD, this attribute can be omitted
# or set to an empty list.
+URITypes = ["LOCAL", "PYRO", "PYROS"]
+
def PYRO_connector_factory(uri, confnodesroot):
"""
@@ -204,3 +209,56 @@
return member
return PyroProxyProxy()
+
+
+def PYRO_connector_dialog(confnodesroot):
+ [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
+
+
+ @implementer(IConnectorPanel)
+ class PYROConnectorPanel(wx.Panel):
+ def __init__(self, typeConnector, parrent, *args, **kwargs):
+ self.type = typeConnector
+ self.parrent = parrent
+ wx.Panel.__init__(self, parrent, *args, **kwargs)
+ self._init_ctrls()
+ self._init_sizers()
+ self.uri = None
+
+ def _init_ctrls(self):
+ self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
+ self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
+
+ def _init_sizers(self):
+ self.mainSizer = wx.BoxSizer(wx.VERTICAL)
+ self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
+ self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
+
+ self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI host:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
+ self.uriSizer.AddSpacer((0,0))
+ self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
+ self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
+
+ self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI port:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
+ self.portSizer.AddSpacer((0,0))
+ self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
+ self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
+
+ self.SetSizer(self.mainSizer)
+
+ def SetURI(self, uri):
+ self.uri = uri
+ uri_list = uri.strip().split(":")
+ length = len(uri_list)
+ if length == 3:
+ self.IpText.SetValue(uri_list[1].strip("/"))
+ self.PortText.SetValue(uri_list[2])
+ elif length == 2:
+ self.IpText.SetValue(uri_list[1].strip("/"))
+
+
+ def GetURI(self):
+ self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
+ return self.uri
+
+ return PYROConnectorPanel("PYRO", confnodesroot)
--- a/connectors/WAMP/__init__.py Thu Apr 19 09:50:00 2018 +0200
+++ b/connectors/WAMP/__init__.py Fri Apr 20 11:21:20 2018 +0200
@@ -25,7 +25,10 @@
from __future__ import absolute_import
from __future__ import print_function
-import sys
+import wx
+from controls.UriLocationEditor import IConnectorPanel
+from zope.interface import implementer
+
import traceback
from threading import Thread, Event
@@ -40,6 +43,7 @@
_WampSession = None
_WampConnection = None
_WampSessionEvent = Event()
+URITypes = ["WAMP", "WAMPS"]
class WampSession(wamp.ApplicationSession):
@@ -158,3 +162,86 @@
confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n") % location)
confnodesroot.logger.write_error(traceback.format_exc())
return None
+
+
+def WAMP_connector_dialog(confnodesroot):
+ [ID_IPTEXT, ID_PORTTEXT, ID_REALMTEXT, ID_WAMPIDTEXT, ID_SECURECHECKBOX] = [wx.NewId() for _init_ctrls in range(5)]
+
+
+ @implementer(IConnectorPanel)
+ class WAMPConnectorPanel(wx.Panel):
+ def __init__(self, typeConnector, parrent, *args, **kwargs):
+ self.type = typeConnector
+ self.parrent = parrent
+ wx.Panel.__init__(self, parrent, *args, **kwargs)
+ self._init_ctrls()
+ self._init_sizers()
+ self.uri = None
+
+ def _init_ctrls(self):
+ self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
+ self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
+ self.RealmText = wx.TextCtrl(parent=self, id=ID_REALMTEXT, size = wx.Size(200, -1))
+ self.WAMPIDText = wx.TextCtrl(parent=self, id=ID_WAMPIDTEXT, size = wx.Size(200, -1))
+ self.SecureCheckbox = wx.CheckBox(self, ID_SECURECHECKBOX, _("Is connection secure?"))
+
+ def _init_sizers(self):
+ self.mainSizer = wx.BoxSizer(wx.VERTICAL)
+ self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
+ self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
+ self.realmSizer = wx.BoxSizer(wx.HORIZONTAL)
+ self.wampIDSizer = wx.BoxSizer(wx.HORIZONTAL)
+
+ self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI host:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
+ self.uriSizer.AddSpacer((0,0))
+ self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
+ self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
+
+ self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI port:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
+ self.portSizer.AddSpacer((0,0))
+ self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
+ self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
+
+ self.realmSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Realm:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
+ self.realmSizer.AddSpacer((0, 0))
+ self.realmSizer.Add(self.RealmText, proportion=1, flag=wx.ALIGN_RIGHT)
+ self.mainSizer.Add(self.realmSizer, border=2, flag=wx.ALL)
+
+ self.wampIDSizer.Add(wx.StaticText(self, wx.ID_ANY, _("WAMP ID:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
+ self.wampIDSizer.AddSpacer((0, 0))
+ self.wampIDSizer.Add(self.WAMPIDText, proportion=1, flag=wx.ALIGN_RIGHT)
+ self.mainSizer.Add(self.wampIDSizer, border=2, flag=wx.ALL)
+
+ self.mainSizer.Add(self.SecureCheckbox, proportion=1, flag=wx.ALIGN_LEFT)
+
+ self.SetSizer(self.mainSizer)
+
+ def SetURI(self, uri):
+ self.uri = uri
+ uri_list = uri.strip().split(":")
+ length = len(uri_list)
+
+ if length > 0:
+ if uri_list[0] == URITypes[1]:
+ self.SecureCheckbox.SetValue(True)
+
+ if length > 2:
+ self.IpText.SetValue(uri_list[1].strip("/"))
+ wampSett = uri_list[2].split("#")
+ length2 = len(wampSett)
+ if length2 > 0:
+ self.PortText.SetValue(wampSett[0])
+ if length2 > 1:
+ self.RealmText.SetValue(wampSett[1])
+ if length2 > 2:
+ self.WAMPIDText.SetValue(wampSett[2])
+
+ def GetURI(self):
+ if self.IpText.Validate():
+ typeForURI = self.type + "S" if self.SecureCheckbox.GetValue() else self.type
+ self.uri = typeForURI + "://" + self.IpText.GetValue() + ":" + self.PortText.GetValue() + "#" + self.RealmText.GetValue() + "#" + self.WAMPIDText.GetValue()
+ return self.uri
+ else:
+ return ""
+
+ return WAMPConnectorPanel("WAMP", confnodesroot)
--- a/connectors/__init__.py Thu Apr 19 09:50:00 2018 +0200
+++ b/connectors/__init__.py Fri Apr 20 11:21:20 2018 +0200
@@ -36,6 +36,12 @@
def _GetLocalConnectorClassFactory(name):
return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_factory")
+def _GetLocalConnectorClassDialog(name):
+ return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_dialog")
+
+def _GetLocalConnectorURITypes(name):
+ return lambda: getattr(__import__(name, globals(), locals()), "URITypes", None)
+
connectors = {name:
_GetLocalConnectorClassFactory(name)
@@ -43,6 +49,12 @@
if (path.isdir(path.join(_base_path, name)) and
not name.startswith("__"))}
+connectors_dialog = {name:
+ {"function":_GetLocalConnectorClassDialog(name), "URITypes": _GetLocalConnectorURITypes(name)}
+ for name in listdir(_base_path)
+ if (path.isdir(path.join(_base_path, name)) and
+ not name.startswith("__"))}
+
def ConnectorFactory(uri, confnodesroot):
"""
@@ -68,3 +80,22 @@
# import module according to uri type
connectorclass = connectors[servicetype]()
return connectorclass(uri, confnodesroot)
+
+
+def ConnectorDialog(type, confnodesroot):
+ if type not in connectors_dialog:
+ return None
+
+ connectorclass = connectors_dialog[type]["function"]()
+ return connectorclass(confnodesroot)
+
+def GetConnectorFromURI(uri):
+ typeOfConnector = None
+ for t in connectors_dialog:
+ connectorTypes = connectors_dialog[t]["URITypes"]()
+ if connectorTypes and uri in connectorTypes:
+ typeOfConnector = t
+ break
+
+ return typeOfConnector
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/controls/UriLocationEditor.py Fri Apr 20 11:21:20 2018 +0200
@@ -0,0 +1,110 @@
+import wx
+from zope.interface import Interface, Attribute
+from zope.interface.verify import verifyObject
+from connectors import connectors_dialog, ConnectorDialog, GetConnectorFromURI
+
+
+[ID_URIWIZARDDIALOG,ID_URITYPECHOICE] = [wx.NewId() for _init_ctrls in range(2)]
+URITYPES = ["- Select URI type -"]
+URITYPES.extend([key for key, value in connectors_dialog.iteritems()])
+
+
+class IConnectorPanel(Interface):
+ """This is interface for panel of seperate connector type"""
+ uri = Attribute("""uri of connections""")
+ type = Attribute("""type of connector""")
+
+ def SetURI(uri):
+ """methode for set uri"""
+
+ def GetURI():
+ """metohde for get uri"""
+
+
+class UriLocationEditor(wx.Dialog):
+ def _init_ctrls(self, parent):
+ wx.Dialog.__init__(self, id=ID_URIWIZARDDIALOG,
+ name='UriLocationEditor', parent=parent,
+ title='Uri location')
+ self.UriTypeChoice = wx.Choice(parent=self, id=ID_URIWIZARDDIALOG,
+ choices = URITYPES)
+ self.UriTypeChoice.SetSelection(0)
+ self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.UriTypeChoice)
+ self.PanelSizer = wx.BoxSizer(wx.HORIZONTAL)
+ self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
+
+ def _init_sizers(self):
+ self.mainSizer = wx.BoxSizer(wx.VERTICAL)
+ # self.mainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=0)
+ # self.mainSizer.AddGrowableCol(0)
+ # self.mainSizer.AddGrowableRow(0)
+
+ typeSizer = wx.BoxSizer(wx.HORIZONTAL)
+ typeSizer.Add(wx.StaticText(self,wx.ID_ANY,"URI type:"), border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
+ typeSizer.Add(self.UriTypeChoice, border=5, flag=wx.ALL)
+ self.mainSizer.Add(typeSizer)
+
+ self.mainSizer.Add(self.PanelSizer, border=5, flag=wx.ALL)
+ self.mainSizer.Add(self.ButtonSizer, border=5, flag=wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL)
+ self.SetSizer(self.mainSizer)
+
+ def __init__(self, parent, uri):
+ self.selected = None
+ self.parrent = parent
+ self.logger = self.parrent.CTR.logger
+ self._init_ctrls(parent)
+ self._init_sizers()
+ self.SetURI(uri)
+ self.CenterOnParent()
+
+ def OnTypeChoice(self, event):
+ self._removePanelType()
+ index = event.GetSelection()
+ if index > 0:
+ self.selected = event.GetString()
+ self.panelType = self._getConnectorDialog(self.selected)
+ if self.panelType:
+ self.PanelSizer.Add(self.panelType)
+ self.mainSizer.Layout()
+ self.Fit()
+ self.panelType.Refresh()
+
+ def SetURI(self, uri):
+ self._removePanelType()
+ uri_list = uri.strip().split(":")
+ if uri_list:
+ uri_type = uri_list[0].upper()
+ type = GetConnectorFromURI(uri_type)
+ if type:
+ self.selected = type
+ self.UriTypeChoice.SetStringSelection(self.selected)
+ self.panelType = self._getConnectorDialog(self.selected)
+ if self.panelType:
+ self.panelType.SetURI(uri)
+ self.PanelSizer.Add(self.panelType)
+ self.PanelSizer.Layout()
+ self.mainSizer.Layout()
+ self.Fit()
+ self.panelType.Refresh()
+
+ def GetURI(self):
+ if not self.selected or not self.panelType:
+ return ""
+ else:
+ return self.panelType.GetURI()
+
+ def _removePanelType(self):
+ for i in range(self.PanelSizer.GetItemCount()):
+ item = self.PanelSizer.GetItem(i)
+ item.DeleteWindows()
+ self.PanelSizer.Remove(i)
+ self.Fit()
+ self.PanelSizer.Layout()
+
+ def _getConnectorDialog(self, connectorType):
+ connector = ConnectorDialog(connectorType, self)
+ if connector and IConnectorPanel.providedBy(connector):
+ if verifyObject(IConnectorPanel, connector):
+ return connector
+ else:
+ return None
--- a/editors/ConfTreeNodeEditor.py Thu Apr 19 09:50:00 2018 +0200
+++ b/editors/ConfTreeNodeEditor.py Fri Apr 20 11:21:20 2018 +0200
@@ -33,7 +33,7 @@
from IDEFrame import TITLE, FILEMENU, PROJECTTREE, PAGETITLES
-from controls import TextCtrlAutoComplete
+from controls import TextCtrlAutoComplete, UriLocationEditor
from dialogs import BrowseValuesLibraryDialog
from util.BitmapLibrary import GetBitmap
@@ -338,6 +338,28 @@
msizer.AddWindow(button, flag=wx.ALIGN_CENTER)
return msizer
+ def UriOptions(self, event):
+ CTR = self.ParentWindow.CTR
+ CTR_BeremizRoot = CTR.BeremizRoot
+ CTR_AppFrame = CTR.AppFrame
+
+ # Get connector uri
+ uri = CTR_BeremizRoot.getURI_location().strip()
+ dialog = UriLocationEditor.UriLocationEditor(CTR_AppFrame, uri)
+
+ if dialog.ShowModal() == wx.ID_OK:
+ CTR_BeremizRoot.setURI_location(dialog.GetURI())
+ if CTR._View is not None:
+ CTR._View.RefreshView()
+ if CTR_AppFrame is not None:
+ CTR_AppFrame.RefreshTitle()
+ CTR_AppFrame.RefreshFileMenu()
+ CTR_AppFrame.RefreshEditMenu()
+ CTR_AppFrame.RefreshPageTitles()
+
+ dialog.Destroy()
+
+
def GenerateSizerElements(self, sizer, elements, path, clean=True):
if clean:
sizer.Clear(True)
@@ -484,7 +506,21 @@
element_path=element_path,
size=wx.Size(300, -1))
- boxsizer.AddWindow(textctrl)
+ if element_infos["name"] == "URI_location":
+ uriSizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
+ uriSizer.AddGrowableCol(0)
+ uriSizer.AddGrowableRow(0)
+
+ self.EditButton = wx.Button(self.ParamsEditor, label='...', size=wx.Size(30, -1))
+ self.Bind(wx.EVT_BUTTON, self.UriOptions, self.EditButton)
+
+ uriSizer.AddWindow(textctrl, flag=wx.GROW)
+ uriSizer.AddWindow(self.EditButton, flag=wx.GROW)
+
+ boxsizer.AddWindow(uriSizer)
+ else:
+ boxsizer.AddWindow(textctrl)
+
if element_infos["value"] is not None:
textctrl.ChangeValue(str(element_infos["value"]))
callback = self.GetTextCtrlCallBackFunction(textctrl, element_path)