author | laurent |
Sun, 11 Mar 2012 21:53:35 +0100 | |
changeset 2039 | 3a218f6bd805 |
parent 2038 | 6f78c4ac22f9 |
child 2040 | d676082c1d2f |
permissions | -rw-r--r-- |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1 |
import wx |
2026
65ecbfe9a6f9
Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents:
2023
diff
changeset
|
2 |
import wx.grid |
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
3 |
import wx.gizmos |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
4 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
5 |
from controls import CustomGrid, CustomTable, EditorPanel |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
6 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
7 |
[ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE] = range(3) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
8 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
9 |
def AppendMenu(parent, help, id, kind, text): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
10 |
if wx.VERSION >= (2, 6, 0): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
11 |
parent.Append(help=help, id=id, kind=kind, text=text) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
12 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
13 |
parent.Append(helpString=help, id=id, kind=kind, item=text) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
14 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
15 |
[ID_SLAVETYPECHOICEDIALOG, ID_SLAVETYPECHOICEDIALOGSTATICTEXT1, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
16 |
ID_SLAVETYPECHOICEDIALOGSLAVETYPESLIBRARY |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
17 |
] = [wx.NewId() for _init_ctrls in range(3)] |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
18 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
19 |
class SlaveTypeChoiceDialog(wx.Dialog): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
20 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
21 |
if wx.VERSION < (2, 6, 0): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
22 |
def Bind(self, event, function, id = None): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
23 |
if id is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
24 |
event(self, id, function) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
25 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
26 |
event(self, function) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
27 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
28 |
def _init_coll_flexGridSizer1_Items(self, parent): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
29 |
parent.AddWindow(self.staticText1, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
30 |
parent.AddWindow(self.SlaveTypesLibrary, 0, border=20, flag=wx.GROW|wx.LEFT|wx.RIGHT) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
31 |
parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
32 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
33 |
def _init_coll_flexGridSizer1_Growables(self, parent): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
34 |
parent.AddGrowableCol(0) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
35 |
parent.AddGrowableRow(1) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
36 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
37 |
def _init_sizers(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
38 |
self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
39 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
40 |
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
41 |
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
42 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
43 |
self.SetSizer(self.flexGridSizer1) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
44 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
45 |
def _init_ctrls(self, prnt): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
46 |
wx.Dialog.__init__(self, id=ID_SLAVETYPECHOICEDIALOG, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
47 |
name='SlaveTypeChoiceDialog', parent=prnt, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
48 |
size=wx.Size(600, 400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
49 |
title=_('Browse slave types library')) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
50 |
self.SetClientSize(wx.Size(600, 400)) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
51 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
52 |
self.staticText1 = wx.StaticText(id=ID_SLAVETYPECHOICEDIALOGSTATICTEXT1, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
53 |
label=_('Choose a slave type:'), name='staticText1', parent=self, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
54 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
55 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
56 |
self.SlaveTypesLibrary = wx.TreeCtrl(id=ID_SLAVETYPECHOICEDIALOGSLAVETYPESLIBRARY, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
57 |
name='TypeTree', parent=self, pos=wx.Point(0, 0), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
58 |
size=wx.Size(0, 0), style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
59 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
60 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
61 |
if wx.VERSION >= (2, 5, 0): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
62 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
63 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
64 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
65 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
66 |
self._init_sizers() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
67 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
68 |
def __init__(self, parent, controler, default=None): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
69 |
self._init_ctrls(parent) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
70 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
71 |
slaves_types = controler.GetSlaveTypesLibrary() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
72 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
73 |
root = self.SlaveTypesLibrary.AddRoot("") |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
74 |
self.GenerateSlaveTypesLibraryTreeBranch(root, slaves_types, default) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
75 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
76 |
def GenerateSlaveTypesLibraryTreeBranch(self, root, children, default): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
77 |
for infos in children: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
78 |
item = self.SlaveTypesLibrary.AppendItem(root, infos["name"]) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
79 |
if infos["type"] == ETHERCAT_DEVICE: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
80 |
self.SlaveTypesLibrary.SetPyData(item, infos["infos"]) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
81 |
if infos["infos"] == default: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
82 |
self.SlaveTypesLibrary.SelectItem(item) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
83 |
self.SlaveTypesLibrary.EnsureVisible(item) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
84 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
85 |
self.GenerateSlaveTypesLibraryTreeBranch(item, infos["children"], default) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
86 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
87 |
def GetType(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
88 |
selected = self.SlaveTypesLibrary.GetSelection() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
89 |
return self.SlaveTypesLibrary.GetPyData(selected) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
90 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
91 |
def OnOK(self, event): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
92 |
selected = self.SlaveTypesLibrary.GetSelection() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
93 |
if not selected.IsOk() or self.SlaveTypesLibrary.GetPyData(selected) is None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
94 |
message = wx.MessageDialog(self, _("No valid slave type selected!"), _("Error"), wx.OK|wx.ICON_ERROR) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
95 |
message.ShowModal() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
96 |
message.Destroy() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
97 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
98 |
self.EndModal(wx.ID_OK) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
99 |
|
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
100 |
def GetSyncManagersTableColnames(): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
101 |
_ = lambda x : x |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
102 |
return ["#", _("Name"), _("Start Address"), _("Default Size"), _("Control Byte"), _("Enable")] |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
103 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
104 |
class SyncManagersTable(CustomTable): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
105 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
106 |
def GetValue(self, row, col): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
107 |
if row < self.GetNumberRows(): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
108 |
if col == 0: |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
109 |
return row |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
110 |
return self.data[row].get(self.GetColLabelValue(col, False), "") |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
111 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
112 |
def GetVariablesTableColnames(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
113 |
_ = lambda x : x |
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
114 |
return ["#", _("Name"), _("Index"), _("SubIndex"), _("Type"), _("PDO index"), _("PDO name"), _("PDO type")] |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
115 |
|
2034 | 116 |
[ID_SLAVEINFOSPANEL, ID_SLAVEINFOSPANELVENDORLABEL, |
117 |
ID_SLAVEINFOSPANELVENDOR, ID_SLAVEINFOSPANELPRODUCTCODELABEL, |
|
118 |
ID_SLAVEINFOSPANELPRODUCTCODE, ID_SLAVEINFOSPANELREVISIONNUMBERLABEL, |
|
119 |
ID_SLAVEINFOSPANELREVISIONNUMBER, ID_SLAVEINFOSPANELPHYSICSLABEL, |
|
120 |
ID_SLAVEINFOSPANELPHYSICS, ID_SLAVEINFOSPANELSYNCMANAGERSLABEL, |
|
121 |
ID_SLAVEINFOSPANELSYNCMANAGERSGRID, ID_SLAVEINFOSPANELVARIABLESLABEL, |
|
122 |
ID_SLAVEINFOSPANELVARIABLESGRID, |
|
123 |
] = [wx.NewId() for _init_ctrls in range(13)] |
|
124 |
||
125 |
class SlaveInfosPanel(wx.Panel): |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
126 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
127 |
if wx.VERSION < (2, 6, 0): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
128 |
def Bind(self, event, function, id = None): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
129 |
if id is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
130 |
event(self, id, function) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
131 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
132 |
event(self, function) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
133 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
134 |
def _init_coll_MainSizer_Items(self, parent): |
2034 | 135 |
parent.AddSizer(self.SlaveInfosDetailsSizer, 0, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW) |
136 |
parent.AddWindow(self.SyncManagersLabel, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW) |
|
137 |
parent.AddWindow(self.SyncManagersGrid, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW) |
|
138 |
parent.AddWindow(self.VariablesLabel, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.GROW) |
|
139 |
parent.AddWindow(self.VariablesGrid, 0, border=5, flag=wx.BOTTOM|wx.LEFT|wx.RIGHT|wx.GROW) |
|
140 |
||
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
141 |
def _init_coll_MainSizer_Growables(self, parent): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
142 |
parent.AddGrowableCol(0) |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
143 |
parent.AddGrowableRow(2, 1) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
144 |
parent.AddGrowableRow(4, 2) |
2023
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
145 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
146 |
def _init_coll_SlaveInfosDetailsSizer_Items(self, parent): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
147 |
parent.AddWindow(self.VendorLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
148 |
parent.AddWindow(self.Vendor, 0, border=0, flag=wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
149 |
parent.AddWindow(self.ProductCodeLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
150 |
parent.AddWindow(self.ProductCode, 0, border=0, flag=wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
151 |
parent.AddWindow(self.RevisionNumberLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
152 |
parent.AddWindow(self.RevisionNumber, 0, border=0, flag=wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
153 |
parent.AddWindow(self.PhysicsLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
154 |
parent.AddWindow(self.Physics, 0, border=0, flag=wx.GROW) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
155 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
156 |
def _init_coll_SlaveInfosDetailsSizer_Growables(self, parent): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
157 |
parent.AddGrowableCol(1) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
158 |
parent.AddGrowableCol(3) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
159 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
160 |
def _init_sizers(self): |
2034 | 161 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
162 |
self.SlaveInfosDetailsSizer = wx.FlexGridSizer(cols=4, hgap=5, rows=2, vgap=5) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
163 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
164 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
165 |
self._init_coll_MainSizer_Items(self.MainSizer) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
166 |
self._init_coll_SlaveInfosDetailsSizer_Growables(self.SlaveInfosDetailsSizer) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
167 |
self._init_coll_SlaveInfosDetailsSizer_Items(self.SlaveInfosDetailsSizer) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
168 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
169 |
self.SetSizer(self.MainSizer) |
2034 | 170 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
171 |
def _init_ctrls(self, prnt): |
2034 | 172 |
wx.Panel.__init__(self, id=ID_SLAVEINFOSPANEL, name='SlavePanel', parent=prnt, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
173 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
174 |
|
2034 | 175 |
self.VendorLabel = wx.StaticText(id=ID_SLAVEINFOSPANELVENDORLABEL, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
176 |
label=_('Vendor:'), name='VendorLabel', parent=self, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
177 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
178 |
|
2034 | 179 |
self.Vendor = wx.TextCtrl(id=ID_SLAVEINFOSPANELVENDOR, value='', |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
180 |
name='Vendor', parent=self, pos=wx.Point(0, 0), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
181 |
size=wx.Size(0, 24), style=wx.TE_READONLY) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
182 |
|
2034 | 183 |
self.ProductCodeLabel = wx.StaticText(id=ID_SLAVEINFOSPANELPRODUCTCODELABEL, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
184 |
label=_('Product code:'), name='ProductCodeLabel', parent=self, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
185 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
186 |
|
2034 | 187 |
self.ProductCode = wx.TextCtrl(id=ID_SLAVEINFOSPANELPRODUCTCODE, value='', |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
188 |
name='ProductCode', parent=self, pos=wx.Point(0, 0), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
189 |
size=wx.Size(0, 24), style=wx.TE_READONLY) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
190 |
|
2034 | 191 |
self.RevisionNumberLabel = wx.StaticText(id=ID_SLAVEINFOSPANELREVISIONNUMBERLABEL, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
192 |
label=_('Revision number:'), name='RevisionNumberLabel', parent=self, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
193 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
194 |
|
2034 | 195 |
self.RevisionNumber = wx.TextCtrl(id=ID_SLAVEINFOSPANELREVISIONNUMBER, value='', |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
196 |
name='RevisionNumber', parent=self, pos=wx.Point(0, 0), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
197 |
size=wx.Size(0, 24), style=wx.TE_READONLY) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
198 |
|
2034 | 199 |
self.PhysicsLabel = wx.StaticText(id=ID_SLAVEINFOSPANELPHYSICSLABEL, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
200 |
label=_('Physics:'), name='PhysicsLabel', parent=self, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
201 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
202 |
|
2034 | 203 |
self.Physics = wx.TextCtrl(id=ID_SLAVEINFOSPANELPHYSICS, value='', |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
204 |
name='Physics', parent=self, pos=wx.Point(0, 0), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
205 |
size=wx.Size(0, 24), style=wx.TE_READONLY) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
206 |
|
2034 | 207 |
self.SyncManagersLabel = wx.StaticText(id=ID_SLAVEINFOSPANELSYNCMANAGERSLABEL, |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
208 |
label=_('Sync managers:'), name='SyncManagersLabel', parent=self, |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
209 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
210 |
|
2034 | 211 |
self.SyncManagersGrid = CustomGrid(id=ID_SLAVEINFOSPANELSYNCMANAGERSGRID, |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
212 |
name='SyncManagersGrid', parent=self, pos=wx.Point(0, 0), |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
213 |
size=wx.Size(0, 0), style=wx.VSCROLL) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
214 |
|
2034 | 215 |
self.VariablesLabel = wx.StaticText(id=ID_SLAVEINFOSPANELVARIABLESLABEL, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
216 |
label=_('Variable entries:'), name='VariablesLabel', parent=self, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
217 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
218 |
|
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
219 |
self.VariablesGrid = wx.gizmos.TreeListCtrl(id=ID_SLAVEINFOSPANELVARIABLESGRID, |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
220 |
name='VariablesGrid', parent=self, pos=wx.Point(0, 0), |
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
221 |
size=wx.Size(0, 0), style=wx.TR_DEFAULT_STYLE | |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
222 |
wx.TR_ROW_LINES | |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
223 |
wx.TR_COLUMN_LINES | |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
224 |
wx.TR_HIDE_ROOT | |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
225 |
wx.TR_FULL_ROW_HIGHLIGHT) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
226 |
self.VariablesGrid.GetMainWindow().Bind(wx.EVT_LEFT_DOWN, self.OnVariablesGridLeftClick) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
227 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
228 |
self._init_sizers() |
2034 | 229 |
|
230 |
def __init__(self, parent, controler): |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
231 |
self._init_ctrls(parent) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
232 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
233 |
self.Controler = controler |
2037
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
234 |
self.Slave = None |
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
235 |
self.Type = None |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
236 |
|
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
237 |
self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames()) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
238 |
self.SyncManagersGrid.SetTable(self.SyncManagersTable) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
239 |
self.SyncManagersGridColAlignements = [wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
240 |
wx.ALIGN_RIGHT, wx.ALIGN_RIGHT, wx.ALIGN_RIGHT] |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
241 |
self.SyncManagersGridColSizes = [40, 150, 100, 100, 100, 100] |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
242 |
self.SyncManagersGrid.SetRowLabelSize(0) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
243 |
for col in range(self.SyncManagersTable.GetNumberCols()): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
244 |
attr = wx.grid.GridCellAttr() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
245 |
attr.SetAlignment(self.SyncManagersGridColAlignements[col], wx.ALIGN_CENTRE) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
246 |
self.SyncManagersGrid.SetColAttr(col, attr) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
247 |
self.SyncManagersGrid.SetColMinimalWidth(col, self.SyncManagersGridColSizes[col]) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
248 |
self.SyncManagersGrid.AutoSizeColumn(col, False) |
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
249 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
250 |
for colname, colsize, colalign in zip(GetVariablesTableColnames(), |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
251 |
[40, 150, 100, 100, 150, 100, 150, 100], |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
252 |
[wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
253 |
wx.ALIGN_RIGHT, wx.ALIGN_LEFT, wx.ALIGN_RIGHT, |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
254 |
wx.ALIGN_LEFT, wx.ALIGN_LEFT]): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
255 |
self.VariablesGrid.AddColumn(colname, colsize, colalign) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
256 |
self.VariablesGrid.SetMainColumn(1) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
257 |
|
2037
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
258 |
def SetSlaveInfos(self, slave_pos, slave_infos): |
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
259 |
self.Slave = slave_pos |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
260 |
if slave_infos is not None: |
2037
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
261 |
self.Type = slave_infos["device_type"] |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
262 |
self.Vendor.SetValue(slave_infos["vendor"]) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
263 |
self.ProductCode.SetValue(slave_infos["product_code"]) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
264 |
self.RevisionNumber.SetValue(slave_infos["revision_number"]) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
265 |
self.Physics.SetValue(slave_infos["physics"]) |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
266 |
self.SyncManagersTable.SetData(slave_infos["sync_managers"]) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
267 |
self.SyncManagersTable.ResetView(self.SyncManagersGrid) |
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
268 |
self.RefreshVariablesGrid(slave_infos["entries"]) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
269 |
else: |
2037
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
270 |
self.Type = None |
2034 | 271 |
self.Vendor.SetValue("") |
272 |
self.ProductCode.SetValue("") |
|
273 |
self.RevisionNumber.SetValue("") |
|
274 |
self.Physics.SetValue("") |
|
275 |
self.SyncManagersTable.SetData([]) |
|
276 |
self.SyncManagersTable.ResetView(self.SyncManagersGrid) |
|
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
277 |
self.RefreshVariablesGrid([]) |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
278 |
|
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
279 |
def RefreshVariablesGrid(self, entries): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
280 |
root = self.VariablesGrid.GetRootItem() |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
281 |
if not root.IsOk(): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
282 |
root = self.VariablesGrid.AddRoot("Slave entries") |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
283 |
self.GenerateVariablesGridBranch(root, entries, GetVariablesTableColnames()) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
284 |
self.VariablesGrid.Expand(root) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
285 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
286 |
def GenerateVariablesGridBranch(self, root, entries, colnames, idx=0): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
287 |
if wx.VERSION >= (2, 6, 0): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
288 |
item, root_cookie = self.VariablesGrid.GetFirstChild(root) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
289 |
else: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
290 |
item, root_cookie = self.VariablesGrid.GetFirstChild(root, 0) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
291 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
292 |
for entry in entries: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
293 |
idx += 1 |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
294 |
if not item.IsOk(): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
295 |
item = self.VariablesGrid.AppendItem(root, "") |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
296 |
for col, colname in enumerate(colnames): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
297 |
if col == 0: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
298 |
self.VariablesGrid.SetItemText(item, str(idx), 0) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
299 |
else: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
300 |
self.VariablesGrid.SetItemText(item, entry.get(colname, ""), col) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
301 |
if entry["PDOMapping"] == "": |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
302 |
self.VariablesGrid.SetItemBackgroundColour(item, wx.LIGHT_GREY) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
303 |
self.VariablesGrid.SetItemPyData(item, entry) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
304 |
idx = self.GenerateVariablesGridBranch(item, entry["children"], colnames, idx) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
305 |
if wx.Platform != '__WXMSW__': |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
306 |
item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
307 |
item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
308 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
309 |
to_delete = [] |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
310 |
while item.IsOk(): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
311 |
to_delete.append(item) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
312 |
item, root_cookie = self.VariablesGrid.GetNextChild(root, root_cookie) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
313 |
for item in to_delete: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
314 |
self.VariablesGrid.Delete(item) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
315 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
316 |
return idx |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
317 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
318 |
def OnVariablesGridLeftClick(self, event): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
319 |
item, flags, col = self.VariablesGrid.HitTest(event.GetPosition()) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
320 |
if item.IsOk(): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
321 |
entry = self.VariablesGrid.GetItemPyData(item) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
322 |
data_type = entry.get("Type", "") |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
323 |
pdo_mapping = entry.get("PDOMapping", "") |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
324 |
|
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
325 |
if (col == -1 and pdo_mapping != "" and |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
326 |
self.Controler.GetSizeOfType(data_type) is not None): |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
327 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
328 |
entry_index = self.Controler.ExtractHexDecValue(entry.get("Index", "0")) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
329 |
entry_subindex = self.Controler.ExtractHexDecValue(entry.get("SubIndex", "0")) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
330 |
var_name = "%s_%4.4x_%2.2x" % (self.Type, entry_index, entry_subindex) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
331 |
if pdo_mapping == "R": |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
332 |
dir = "%I" |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
333 |
else: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
334 |
dir = "%Q" |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
335 |
location = "%s%s" % (dir, self.Controler.GetSizeOfType(data_type)) + \ |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
336 |
".".join(map(lambda x:str(x), self.Controler.GetCurrentLocation() + self.Slave + (entry_index, entry_subindex))) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
337 |
|
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
338 |
data = wx.TextDataObject(str((location, "location", data_type, var_name, ""))) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
339 |
dragSource = wx.DropSource(self.VariablesGrid) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
340 |
dragSource.SetData(data) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
341 |
dragSource.DoDragDrop() |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
342 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
343 |
event.Skip() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
344 |
|
2034 | 345 |
[ID_SLAVEPANEL, ID_SLAVEPANELTYPELABEL, |
346 |
ID_SLAVEPANELTYPE, ID_SLAVEPANELTYPEBROWSE, |
|
347 |
ID_SLAVEPANELALIASLABEL, ID_SLAVEPANELALIAS, |
|
348 |
ID_SLAVEPANELPOSLABEL, ID_SLAVEPANELPOS, |
|
349 |
ID_SLAVEPANELSLAVEINFOSSTATICBOX, |
|
350 |
] = [wx.NewId() for _init_ctrls in range(9)] |
|
351 |
||
352 |
class SlavePanel(wx.Panel): |
|
353 |
||
354 |
if wx.VERSION < (2, 6, 0): |
|
355 |
def Bind(self, event, function, id = None): |
|
356 |
if id is not None: |
|
357 |
event(self, id, function) |
|
358 |
else: |
|
359 |
event(self, function) |
|
360 |
||
361 |
def _init_coll_MainSizer_Items(self, parent): |
|
362 |
parent.AddSizer(self.PositionSizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
363 |
parent.AddSizer(self.SlaveInfosBoxSizer, 0, border=5, flag=wx.GROW|wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT) |
|
364 |
||
365 |
def _init_coll_MainSizer_Growables(self, parent): |
|
366 |
parent.AddGrowableCol(0) |
|
367 |
parent.AddGrowableRow(1) |
|
368 |
||
369 |
def _init_coll_PositionSizer_Items(self, parent): |
|
370 |
parent.AddWindow(self.TypeLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
371 |
parent.AddSizer(self.TypeSizer, 0, border=0, flag=wx.GROW) |
|
372 |
parent.AddWindow(self.AliasLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
373 |
parent.AddWindow(self.Alias, 0, border=0, flag=wx.GROW) |
|
374 |
parent.AddWindow(self.PosLabel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
375 |
parent.AddWindow(self.Pos, 0, border=0, flag=wx.GROW) |
|
376 |
||
377 |
def _init_coll_PositionSizer_Growables(self, parent): |
|
378 |
parent.AddGrowableCol(1) |
|
379 |
parent.AddGrowableCol(3) |
|
380 |
parent.AddGrowableCol(5) |
|
381 |
parent.AddGrowableRow(0) |
|
382 |
||
383 |
def _init_coll_TypeSizer_Items(self, parent): |
|
384 |
parent.AddWindow(self.Type, 1, border=0, flag=0) |
|
385 |
parent.AddWindow(self.TypeBrowse, 0, border=0, flag=0) |
|
386 |
||
387 |
def _init_coll_SlaveInfosBoxSizer_Items(self, parent): |
|
388 |
parent.AddWindow(self.SlaveInfosPanel, 1, border=0, flag=wx.GROW) |
|
389 |
||
390 |
def _init_sizers(self): |
|
391 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
392 |
self.PositionSizer = wx.FlexGridSizer(cols=6, hgap=5, rows=1, vgap=0) |
|
393 |
self.TypeSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
394 |
self.SlaveInfosBoxSizer = wx.StaticBoxSizer(self.SlaveInfosStaticBox, wx.VERTICAL) |
|
395 |
||
396 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
|
397 |
self._init_coll_MainSizer_Items(self.MainSizer) |
|
398 |
self._init_coll_PositionSizer_Growables(self.PositionSizer) |
|
399 |
self._init_coll_PositionSizer_Items(self.PositionSizer) |
|
400 |
self._init_coll_TypeSizer_Items(self.TypeSizer) |
|
401 |
self._init_coll_SlaveInfosBoxSizer_Items(self.SlaveInfosBoxSizer) |
|
402 |
||
403 |
self.SetSizer(self.MainSizer) |
|
404 |
||
405 |
def _init_ctrls(self, prnt): |
|
406 |
wx.Panel.__init__(self, id=ID_SLAVEPANEL, name='SlavePanel', parent=prnt, |
|
407 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
408 |
||
409 |
self.TypeLabel = wx.StaticText(id=ID_SLAVEPANELTYPELABEL, |
|
410 |
label=_('Type:'), name='TypeLabel', parent=self, |
|
411 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
412 |
||
413 |
self.Type = wx.TextCtrl(id=ID_SLAVEPANELTYPE, value='', |
|
414 |
name='Type', parent=self, pos=wx.Point(0, 0), |
|
415 |
size=wx.Size(0, 24), style=wx.TE_READONLY) |
|
416 |
||
417 |
self.TypeBrowse = wx.Button(id=ID_SLAVEPANELTYPEBROWSE, label='...', |
|
418 |
name='TypeBrowse', parent=self, pos=wx.Point(0, 0), |
|
419 |
size=wx.Size(30, 24), style=0) |
|
420 |
self.Bind(wx.EVT_BUTTON, self.OnTypeBrowseClick, id=ID_SLAVEPANELTYPEBROWSE) |
|
421 |
||
422 |
self.AliasLabel = wx.StaticText(id=ID_SLAVEPANELALIASLABEL, |
|
423 |
label=_('Alias:'), name='AliasLabel', parent=self, |
|
424 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
425 |
||
426 |
self.Alias = wx.SpinCtrl(id=ID_SLAVEPANELALIAS, |
|
427 |
name='Alias', parent=self, pos=wx.Point(0, 0), |
|
428 |
size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0, max=0xffff) |
|
429 |
self.Bind(wx.EVT_SPINCTRL, self.OnAliasChanged, id=ID_SLAVEPANELALIAS) |
|
430 |
||
431 |
self.PosLabel = wx.StaticText(id=ID_SLAVEPANELPOSLABEL, |
|
432 |
label=_('Position:'), name='PositionLabel', parent=self, |
|
433 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
434 |
||
435 |
self.Pos = wx.SpinCtrl(id=ID_SLAVEPANELPOS, |
|
436 |
name='Pos', parent=self, pos=wx.Point(0, 0), |
|
437 |
size=wx.Size(0, 24), style=wx.SP_ARROW_KEYS, min=0, max=0xffff) |
|
438 |
self.Bind(wx.EVT_SPINCTRL, self.OnPositionChanged, id=ID_SLAVEPANELPOS) |
|
439 |
||
440 |
self.SlaveInfosStaticBox = wx.StaticBox(id=ID_SLAVEPANELSLAVEINFOSSTATICBOX, |
|
441 |
label=_('Slave infos:'), name='SlaveInfosStaticBox', parent=self, |
|
442 |
pos=wx.Point(0, 0), size=wx.Size(0, 0), style=0) |
|
443 |
||
444 |
self.SlaveInfosPanel = SlaveInfosPanel(self, self.Controler) |
|
445 |
||
446 |
self._init_sizers() |
|
447 |
||
448 |
def __init__(self, parent, controler, window, slave): |
|
449 |
self.Controler = controler |
|
450 |
self.ParentWindow = window |
|
451 |
self.Slave = slave |
|
452 |
||
453 |
self._init_ctrls(parent) |
|
454 |
||
455 |
self.RefreshView() |
|
456 |
||
457 |
def GetSlaveTitle(self): |
|
458 |
type_infos = self.Controler.GetSlaveType(self.Slave) |
|
459 |
return "%s (%d:%d)" % (type_infos["device_type"], self.Slave[0], self.Slave[1]) |
|
460 |
||
461 |
def GetSlave(self): |
|
462 |
return self.Slave |
|
463 |
||
464 |
def SetSlave(self, slave): |
|
465 |
if self.Slave != slave: |
|
466 |
self.Slave = slave |
|
467 |
self.RefreshView() |
|
468 |
||
469 |
def RefreshView(self): |
|
470 |
self.Alias.SetValue(self.Slave[0]) |
|
471 |
self.Pos.SetValue(self.Slave[1]) |
|
472 |
slave_infos = self.Controler.GetSlaveInfos(self.Slave) |
|
473 |
if slave_infos is not None: |
|
474 |
self.Type.SetValue(slave_infos["device_type"]) |
|
475 |
else: |
|
476 |
type_infos = self.Controler.GetSlaveType(self.Slave) |
|
477 |
self.Type.SetValue(type_infos["device_type"]) |
|
2037
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
478 |
self.SlaveInfosPanel.SetSlaveInfos(self.Slave, slave_infos) |
2034 | 479 |
|
480 |
def OnAliasChanged(self, event): |
|
481 |
alias = self.Alias.GetValue() |
|
482 |
if alias != self.Slave[0]: |
|
483 |
result = self.Controler.SetSlavePos(self.Slave[:2], alias = alias) |
|
484 |
if result is not None: |
|
485 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
|
486 |
message.ShowModal() |
|
487 |
message.Destroy() |
|
488 |
else: |
|
489 |
wx.CallAfter(self.ParentWindow.RefreshView, (alias, self.Slave[1])) |
|
490 |
wx.CallAfter(self.ParentWindow.RefreshParentWindow) |
|
491 |
event.Skip() |
|
492 |
||
493 |
def OnPositionChanged(self, event): |
|
494 |
position = self.Pos.GetValue() |
|
495 |
if position != self.Slave[1]: |
|
496 |
result = self.Controler.SetSlavePos(self.Slave, position = position) |
|
497 |
if result is not None: |
|
498 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
|
499 |
message.ShowModal() |
|
500 |
message.Destroy() |
|
501 |
else: |
|
502 |
wx.CallAfter(self.ParentWindow.RefreshView, (self.Slave[0], position)) |
|
503 |
wx.CallAfter(self.ParentWindow.RefreshParentWindow) |
|
504 |
event.Skip() |
|
505 |
||
506 |
def OnTypeBrowseClick(self, event): |
|
507 |
dialog = SlaveTypeChoiceDialog(self, self.Controler, self.Controler.GetSlaveType(self.Slave)) |
|
508 |
if dialog.ShowModal() == wx.ID_OK: |
|
509 |
result = self.Controler.SetSlaveType(self.Slave, dialog.GetType()) |
|
510 |
if result is not None: |
|
511 |
message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR) |
|
512 |
message.ShowModal() |
|
513 |
message.Destroy() |
|
514 |
else: |
|
515 |
wx.CallAfter(self.RefreshView) |
|
516 |
wx.CallAfter(self.ParentWindow.RefreshSlaveNodesTitles) |
|
517 |
wx.CallAfter(self.ParentWindow.RefreshParentWindow) |
|
518 |
dialog.Destroy() |
|
519 |
event.Skip() |
|
520 |
||
521 |
[ID_CONFIGEDITOR, ID_CONFIGEDITORSLAVENODES, |
|
522 |
] = [wx.NewId() for _init_ctrls in range(2)] |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
523 |
|
2030 | 524 |
[ID_CONFIGEDITORPLUGINMENUADDSLAVE, ID_CONFIGEDITORPLUGINMENUDELETESLAVE, |
525 |
] = [wx.NewId() for _init_coll_PluginMenu_Items in range(2)] |
|
526 |
||
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
527 |
class ConfigEditor(EditorPanel): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
528 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
529 |
ID = ID_CONFIGEDITOR |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
530 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
531 |
def _init_coll_MainSizer_Items(self, parent): |
2030 | 532 |
parent.AddWindow(self.SlaveNodes, 0, border=5, flag=wx.GROW|wx.ALL) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
533 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
534 |
def _init_coll_MainSizer_Growables(self, parent): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
535 |
parent.AddGrowableCol(0) |
2030 | 536 |
parent.AddGrowableRow(0) |
537 |
||
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
538 |
def _init_sizers(self): |
2030 | 539 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=0) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
540 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
541 |
self._init_coll_MainSizer_Items(self.MainSizer) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
542 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
543 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
544 |
self.Editor.SetSizer(self.MainSizer) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
545 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
546 |
def _init_Editor(self, prnt): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
547 |
self.Editor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
548 |
size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
549 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
550 |
self.SlaveNodes = wx.Notebook(id=ID_CONFIGEDITORSLAVENODES, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
551 |
name='SlaveNodes', parent=self.Editor, pos=wx.Point(0, 0), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
552 |
size=wx.Size(0, 0), style=wx.NB_LEFT) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
553 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
554 |
self._init_sizers() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
555 |
|
2030 | 556 |
def _init_MenuItems(self): |
557 |
self.MenuItems = [ |
|
558 |
(wx.ITEM_NORMAL, (_("Add slave"), ID_CONFIGEDITORPLUGINMENUADDSLAVE, '', self.OnAddSlaveMenu)), |
|
559 |
(wx.ITEM_NORMAL, (_("Delete slave"), ID_CONFIGEDITORPLUGINMENUDELETESLAVE, '', self.OnDeleteSlaveMenu)), |
|
560 |
] |
|
561 |
||
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
562 |
def __init__(self, parent, controler, window): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
563 |
EditorPanel.__init__(self, parent, "", window, controler) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
564 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
565 |
img = wx.Bitmap(self.Controler.GetIconPath("Cfile.png"), wx.BITMAP_TYPE_PNG).ConvertToImage() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
566 |
self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16))) |
2026
65ecbfe9a6f9
Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents:
2023
diff
changeset
|
567 |
|
65ecbfe9a6f9
Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents:
2023
diff
changeset
|
568 |
def __del__(self): |
2030 | 569 |
self.Controler.OnCloseEditor(self) |
2026
65ecbfe9a6f9
Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents:
2023
diff
changeset
|
570 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
571 |
def GetTitle(self): |
2023
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
572 |
fullname = self.Controler.PlugFullName() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
573 |
if not self.Controler.ConfigIsSaved(): |
2023
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
574 |
return "~%s~" % fullname |
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
575 |
return fullname |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
576 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
577 |
def GetBufferState(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
578 |
return self.Controler.GetBufferState() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
579 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
580 |
def Undo(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
581 |
self.Controler.LoadPrevious() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
582 |
self.RefreshView() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
583 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
584 |
def Redo(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
585 |
self.Controler.LoadNext() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
586 |
self.RefreshView() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
587 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
588 |
def RefreshView(self, slave_pos=None): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
589 |
slaves = self.Controler.GetSlaves() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
590 |
for i, slave in enumerate(slaves): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
591 |
if i < self.SlaveNodes.GetPageCount(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
592 |
panel = self.SlaveNodes.GetPage(i) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
593 |
panel.SetSlave(slave) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
594 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
595 |
panel = SlavePanel(self.SlaveNodes, self.Controler, self, slave) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
596 |
self.SlaveNodes.AddPage(panel, "") |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
597 |
while self.SlaveNodes.GetPageCount() > len(slaves): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
598 |
self.SlaveNodes.RemovePage(len(slaves)) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
599 |
self.RefreshSlaveNodesTitles() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
600 |
if slave_pos is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
601 |
self.SelectSlave(slave_pos) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
602 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
603 |
def RefreshParentWindow(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
604 |
self.ParentWindow.RefreshTitle() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
605 |
self.ParentWindow.RefreshFileMenu() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
606 |
self.ParentWindow.RefreshEditMenu() |
2030 | 607 |
self.ParentWindow.RefreshPluginMenu() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
608 |
self.ParentWindow.RefreshPageTitles() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
609 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
610 |
def RefreshSlaveNodesTitles(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
611 |
for idx in xrange(self.SlaveNodes.GetPageCount()): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
612 |
panel = self.SlaveNodes.GetPage(idx) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
613 |
self.SlaveNodes.SetPageText(idx, panel.GetSlaveTitle()) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
614 |
|
2030 | 615 |
def RefreshPluginMenu(self, plugin_menu): |
616 |
plugin_menu.Enable(ID_CONFIGEDITORPLUGINMENUDELETESLAVE, |
|
617 |
self.SlaveNodes.GetPageCount() > 0) |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
618 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
619 |
def SelectSlave(self, slave): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
620 |
for idx in xrange(self.SlaveNodes.GetPageCount()): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
621 |
panel = self.SlaveNodes.GetPage(idx) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
622 |
if panel.GetSlave() == slave: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
623 |
self.SlaveNodes.SetSelection(idx) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
624 |
return |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
625 |
|
2030 | 626 |
def OnAddSlaveMenu(self, event): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
627 |
slave = self.Controler.AddSlave() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
628 |
self.RefreshParentWindow() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
629 |
wx.CallAfter(self.RefreshView, slave) |
2030 | 630 |
|
631 |
def OnDeleteSlaveMenu(self, event): |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
632 |
selected = self.SlaveNodes.GetSelection() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
633 |
if selected != -1: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
634 |
panel = self.SlaveNodes.GetPage(selected) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
635 |
if self.Controler.RemoveSlave(panel.GetSlave()[:2]): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
636 |
self.RefreshParentWindow() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
637 |
wx.CallAfter(self.RefreshView) |
2034 | 638 |
|
639 |
||
640 |
[ID_DS402NODEEDITOR, |
|
641 |
] = [wx.NewId() for _init_ctrls in range(1)] |
|
642 |
||
643 |
class DS402NodeEditor(EditorPanel): |
|
644 |
||
645 |
ID = ID_DS402NODEEDITOR |
|
646 |
||
647 |
def _init_Editor(self, prnt): |
|
648 |
self.Editor = SlaveInfosPanel(prnt, self.Controler) |
|
649 |
||
650 |
def __init__(self, parent, controler, window): |
|
651 |
EditorPanel.__init__(self, parent, "", window, controler) |
|
652 |
||
653 |
img = wx.Bitmap(self.Controler.GetIconPath("Cfile.png"), wx.BITMAP_TYPE_PNG).ConvertToImage() |
|
654 |
self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16))) |
|
655 |
||
656 |
def __del__(self): |
|
657 |
self.Controler.OnCloseEditor(self) |
|
658 |
||
659 |
def GetTitle(self): |
|
660 |
return self.Controler.PlugFullName() |
|
661 |
||
662 |
def GetBufferState(self): |
|
663 |
return False, False |
|
664 |
||
665 |
def RefreshView(self): |
|
2037
d54036f70390
Fix bug when trying to drag'n drop variable from slave variables grid
laurent
parents:
2034
diff
changeset
|
666 |
self.Editor.SetSlaveInfos(self.Controler.GetSlavePos(), self.Controler.GetSlaveInfos()) |
2034 | 667 |