author | Edouard Tisserant |
Mon, 13 Aug 2018 15:00:51 +0200 | |
changeset 2265 | 2de61e2fbf14 |
parent 2182 | eeca1aff0691 |
child 2329 | e5703dc8848e |
permissions | -rw-r--r-- |
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
1 |
from __future__ import absolute_import |
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
2 |
|
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
3 |
import wx |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
4 |
from zope.interface import Interface, Attribute |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
5 |
from zope.interface.verify import verifyObject |
2007
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
2006
diff
changeset
|
6 |
from connectors import connectors_dialog, ConnectorDialog, GetConnectorFromURI |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
7 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
8 |
|
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
9 |
[ID_URIWIZARDDIALOG, ID_URITYPECHOICE] = [wx.NewId() for _init_ctrls in range(2)] |
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
10 |
|
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
11 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
12 |
class IConnectorPanel(Interface): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
13 |
"""This is interface for panel of seperate connector type""" |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
14 |
uri = Attribute("""uri of connections""") |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
15 |
type = Attribute("""type of connector""") |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
16 |
|
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
17 |
def SetURI(uri): # pylint: disable=no-self-argument |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
18 |
"""methode for set uri""" |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
19 |
|
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
20 |
def GetURI(): # pylint: disable=no-self-argument |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
21 |
"""metohde for get uri""" |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
22 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
23 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
24 |
class UriLocationEditor(wx.Dialog): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
25 |
def _init_ctrls(self, parent): |
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
26 |
self.UriTypeChoice = wx.Choice(parent=self, id=ID_URIWIZARDDIALOG, choices=self.URITYPES) |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
27 |
self.UriTypeChoice.SetSelection(0) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
28 |
self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.UriTypeChoice) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
29 |
self.PanelSizer = wx.BoxSizer(wx.HORIZONTAL) |
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
30 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL) |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
31 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
32 |
def _init_sizers(self): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
33 |
self.mainSizer = wx.BoxSizer(wx.VERTICAL) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
34 |
typeSizer = wx.BoxSizer(wx.HORIZONTAL) |
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
35 |
typeSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI type:")), border=5, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL) |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
36 |
typeSizer.Add(self.UriTypeChoice, border=5, flag=wx.ALL) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
37 |
self.mainSizer.Add(typeSizer) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
38 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
39 |
self.mainSizer.Add(self.PanelSizer, border=5, flag=wx.ALL) |
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
40 |
self.mainSizer.Add(self.ButtonSizer, border=5, flag=wx.BOTTOM | wx.ALIGN_CENTER_HORIZONTAL) |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
41 |
self.SetSizer(self.mainSizer) |
2176
748017ca4151
Autoresize UriLocationEditor dialog window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2007
diff
changeset
|
42 |
self.Layout() |
748017ca4151
Autoresize UriLocationEditor dialog window
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2007
diff
changeset
|
43 |
self.Fit() |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
44 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
45 |
def __init__(self, parent, uri): |
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
46 |
wx.Dialog.__init__(self, id=ID_URIWIZARDDIALOG, |
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
47 |
name='UriLocationEditor', parent=parent, |
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
48 |
title='Uri location') |
2179
84c4e56b38d6
Fix internatialization in UriLocationEditor, PYRO dialog and Modbus configurator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2176
diff
changeset
|
49 |
self.URITYPES = [_("- Select URI type -")] |
2005
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
50 |
for connector_type, connector_function in connectors_dialog.iteritems(): |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
51 |
try: |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
52 |
connector_function['function']() |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
53 |
self.URITYPES.append(connector_type) |
2182
eeca1aff0691
Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2179
diff
changeset
|
54 |
except Exception: |
2005
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
55 |
pass |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
56 |
|
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
57 |
self.selected = None |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
58 |
self.parrent = parent |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
59 |
self.logger = self.parrent.CTR.logger |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
60 |
self._init_ctrls(parent) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
61 |
self._init_sizers() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
62 |
self.SetURI(uri) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
63 |
self.CenterOnParent() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
64 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
65 |
def OnTypeChoice(self, event): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
66 |
self._removePanelType() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
67 |
index = event.GetSelection() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
68 |
if index > 0: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
69 |
self.selected = event.GetString() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
70 |
self.panelType = self._getConnectorDialog(self.selected) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
71 |
if self.panelType: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
72 |
self.PanelSizer.Add(self.panelType) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
73 |
self.mainSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
74 |
self.Fit() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
75 |
self.panelType.Refresh() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
76 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
77 |
def SetURI(self, uri): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
78 |
self._removePanelType() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
79 |
uri_list = uri.strip().split(":") |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
80 |
if uri_list: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
81 |
uri_type = uri_list[0].upper() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
82 |
type = GetConnectorFromURI(uri_type) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
83 |
if type: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
84 |
self.selected = type |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
85 |
self.UriTypeChoice.SetStringSelection(self.selected) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
86 |
self.panelType = self._getConnectorDialog(self.selected) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
87 |
if self.panelType: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
88 |
self.panelType.SetURI(uri) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
89 |
self.PanelSizer.Add(self.panelType) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
90 |
self.PanelSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
91 |
self.mainSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
92 |
self.Fit() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
93 |
self.panelType.Refresh() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
94 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
95 |
def GetURI(self): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
96 |
if not self.selected or not self.panelType: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
97 |
return "" |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
98 |
else: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
99 |
return self.panelType.GetURI() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
100 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
101 |
def _removePanelType(self): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
102 |
for i in range(self.PanelSizer.GetItemCount()): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
103 |
item = self.PanelSizer.GetItem(i) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
104 |
item.DeleteWindows() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
105 |
self.PanelSizer.Remove(i) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
106 |
self.Fit() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
107 |
self.PanelSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
108 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
109 |
def _getConnectorDialog(self, connectorType): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
110 |
connector = ConnectorDialog(connectorType, self) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
111 |
if connector and IConnectorPanel.providedBy(connector): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
112 |
if verifyObject(IConnectorPanel, connector): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
113 |
return connector |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
114 |
else: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
115 |
return None |