author | Edouard Tisserant |
Fri, 06 Jul 2018 15:09:44 +0200 | |
branch | nevow_service_rework |
changeset 2218 | 7a4deed94eb2 |
parent 2007 | ef2d479f564f |
child 2176 | 748017ca4151 |
permissions | -rw-r--r-- |
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
1 |
import wx |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
2 |
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
|
3 |
from zope.interface.verify import verifyObject |
2007
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
2006
diff
changeset
|
4 |
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
|
5 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
6 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
7 |
[ID_URIWIZARDDIALOG,ID_URITYPECHOICE] = [wx.NewId() for _init_ctrls in range(2)] |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
8 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
9 |
class IConnectorPanel(Interface): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
10 |
"""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
|
11 |
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
|
12 |
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
|
13 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
14 |
def SetURI(uri): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
15 |
"""methode for set uri""" |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
16 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
17 |
def GetURI(): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
18 |
"""metohde for get uri""" |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
19 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
20 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
21 |
class UriLocationEditor(wx.Dialog): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
22 |
def _init_ctrls(self, parent): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
23 |
wx.Dialog.__init__(self, id=ID_URIWIZARDDIALOG, |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
24 |
name='UriLocationEditor', parent=parent, |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
25 |
title='Uri location') |
2005
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
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) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
30 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL) |
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) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
35 |
typeSizer.Add(wx.StaticText(self,wx.ID_ANY,"URI type:"), border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL) |
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) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
40 |
self.mainSizer.Add(self.ButtonSizer, border=5, flag=wx.BOTTOM|wx.ALIGN_CENTER_HORIZONTAL) |
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) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
42 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
43 |
def __init__(self, parent, uri): |
2005
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
44 |
self.URITYPES = ["- Select URI type -"] |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
45 |
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
|
46 |
try: |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
47 |
connector_function['function']() |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
48 |
self.URITYPES.append(connector_type) |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
49 |
except Exception as e: |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
50 |
pass |
0d32b17f15b9
#2476 Additional check added if we can import wx.
dporopat <denis.poropat@smarteh.si>
parents:
2001
diff
changeset
|
51 |
|
2001
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
52 |
self.selected = None |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
53 |
self.parrent = parent |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
54 |
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
|
55 |
self._init_ctrls(parent) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
56 |
self._init_sizers() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
57 |
self.SetURI(uri) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
58 |
self.CenterOnParent() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
59 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
60 |
def OnTypeChoice(self, event): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
61 |
self._removePanelType() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
62 |
index = event.GetSelection() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
63 |
if index > 0: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
64 |
self.selected = event.GetString() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
65 |
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
|
66 |
if self.panelType: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
67 |
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
|
68 |
self.mainSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
69 |
self.Fit() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
70 |
self.panelType.Refresh() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
71 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
72 |
def SetURI(self, uri): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
73 |
self._removePanelType() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
74 |
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
|
75 |
if uri_list: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
76 |
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
|
77 |
type = GetConnectorFromURI(uri_type) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
78 |
if type: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
79 |
self.selected = type |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
if self.panelType: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
83 |
self.panelType.SetURI(uri) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
84 |
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
|
85 |
self.PanelSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
86 |
self.mainSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
87 |
self.Fit() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
88 |
self.panelType.Refresh() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
89 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
90 |
def GetURI(self): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
91 |
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
|
92 |
return "" |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
93 |
else: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
94 |
return self.panelType.GetURI() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
95 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
96 |
def _removePanelType(self): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
item.DeleteWindows() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
100 |
self.PanelSizer.Remove(i) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
101 |
self.Fit() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
102 |
self.PanelSizer.Layout() |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
103 |
|
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
104 |
def _getConnectorDialog(self, connectorType): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
105 |
connector = ConnectorDialog(connectorType, self) |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
106 |
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
|
107 |
if verifyObject(IConnectorPanel, connector): |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
108 |
return connector |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
109 |
else: |
bcbd41efd846
#2476 Added uri location editor, getting connectors from list in Beremiz.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
110 |
return None |