author | dporopat <denis.poropat@smarteh.si> |
Mon, 09 Apr 2018 14:38:38 +0200 | |
branch | #2486 |
changeset 2195 | 2cef75d036c2 |
parent 1881 | 091005ec69c4 |
child 2573 | 071d10c7ab8f |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
814 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
814 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
814 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
19 |
# GNU General Public License for more details. |
814 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1550
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1836
diff
changeset
|
25 |
|
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1836
diff
changeset
|
26 |
from __future__ import absolute_import |
814 | 27 |
import wx |
28 |
||
29 |
from dialogs.BrowseLocationsDialog import BrowseLocationsDialog |
|
30 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
31 |
|
814 | 32 |
class LocationCellControl(wx.PyControl): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
33 |
|
814 | 34 |
''' |
35 |
Custom cell editor control with a text box and a button that launches |
|
36 |
the BrowseLocationsDialog. |
|
37 |
''' |
|
38 |
def __init__(self, parent): |
|
1836
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
39 |
wx.PyControl.__init__(self, parent) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
40 |
|
814 | 41 |
main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) |
42 |
main_sizer.AddGrowableCol(0) |
|
43 |
main_sizer.AddGrowableRow(0) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
44 |
|
814 | 45 |
# create location text control |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
46 |
self.Location = wx.TextCtrl(self, size=wx.Size(0, -1), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
47 |
style=wx.TE_PROCESS_ENTER) |
814 | 48 |
self.Location.Bind(wx.EVT_KEY_DOWN, self.OnLocationChar) |
49 |
main_sizer.AddWindow(self.Location, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
50 |
|
814 | 51 |
# create browse button |
52 |
self.BrowseButton = wx.Button(self, label='...', size=wx.Size(30, -1)) |
|
53 |
self.BrowseButton.Bind(wx.EVT_BUTTON, self.OnBrowseButtonClick) |
|
54 |
main_sizer.AddWindow(self.BrowseButton, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
55 |
|
814 | 56 |
self.Bind(wx.EVT_SIZE, self.OnSize) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
57 |
|
814 | 58 |
self.SetSizer(main_sizer) |
59 |
||
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
60 |
self.Controller = None |
814 | 61 |
self.VarType = None |
62 |
self.Default = False |
|
63 |
||
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
64 |
def __del__(self): |
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
65 |
self.Controller = None |
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
66 |
|
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
67 |
def SetController(self, controller): |
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
68 |
self.Controller = controller |
814 | 69 |
|
70 |
def SetVarType(self, vartype): |
|
71 |
self.VarType = vartype |
|
72 |
||
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
73 |
def GetVarType(self): |
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
74 |
return self.VarType |
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
75 |
|
814 | 76 |
def SetValue(self, value): |
77 |
self.Default = value |
|
78 |
self.Location.SetValue(value) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
79 |
|
814 | 80 |
def GetValue(self): |
81 |
return self.Location.GetValue() |
|
82 |
||
83 |
def OnSize(self, event): |
|
84 |
self.Layout() |
|
85 |
||
86 |
def OnBrowseButtonClick(self, event): |
|
87 |
# pop up the location browser dialog |
|
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
88 |
dialog = BrowseLocationsDialog(self, self.VarType, self.Controller) |
814 | 89 |
if dialog.ShowModal() == wx.ID_OK: |
90 |
infos = dialog.GetValues() |
|
1004
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
91 |
else: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
92 |
infos = None |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
93 |
dialog.Destroy() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
94 |
|
1004
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
95 |
if infos is not None: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
96 |
location = infos["location"] |
814 | 97 |
# set the location |
1004
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
98 |
if not infos["location"].startswith("%"): |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
99 |
dialog = wx.SingleChoiceDialog( |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
100 |
self, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
101 |
_("Select a variable class:"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
102 |
_("Variable class"), |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
103 |
[_("Input"), _("Output"), _("Memory")], |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
104 |
wx.DEFAULT_DIALOG_STYLE | wx.OK | wx.CANCEL) |
1004
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
105 |
if dialog.ShowModal() == wx.ID_OK: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
106 |
selected = dialog.GetSelection() |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
107 |
else: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
108 |
selected = None |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
109 |
dialog.Destroy() |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
110 |
if selected is None: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
111 |
self.Location.SetFocus() |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
112 |
return |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
113 |
if selected == 0: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
114 |
location = "%I" + location |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
115 |
elif selected == 1: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
116 |
location = "%Q" + location |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
117 |
else: |
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
118 |
location = "%M" + location |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
119 |
|
1004
bf3b6998f7b6
Added support in LocationCellEditor for locations with undefined direction
Laurent Bessard
parents:
855
diff
changeset
|
120 |
self.Location.SetValue(location) |
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
121 |
self.VarType = infos["IEC_type"] |
814 | 122 |
|
123 |
self.Location.SetFocus() |
|
124 |
||
125 |
def OnLocationChar(self, event): |
|
126 |
keycode = event.GetKeyCode() |
|
127 |
if keycode in [wx.WXK_RETURN, wx.WXK_TAB]: |
|
128 |
self.Parent.Parent.ProcessEvent(event) |
|
129 |
elif keycode == wx.WXK_ESCAPE: |
|
130 |
self.Location.SetValue(self.Default) |
|
131 |
self.Parent.Parent.CloseEditControl() |
|
132 |
else: |
|
133 |
event.Skip() |
|
134 |
||
135 |
def SetInsertionPoint(self, i): |
|
136 |
self.Location.SetInsertionPoint(i) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
137 |
|
814 | 138 |
def SetFocus(self): |
139 |
self.Location.SetFocus() |
|
140 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
141 |
|
814 | 142 |
class LocationCellEditor(wx.grid.PyGridCellEditor): |
143 |
''' |
|
144 |
Grid cell editor that uses LocationCellControl to display a browse button. |
|
145 |
''' |
|
146 |
def __init__(self, table, controller): |
|
147 |
wx.grid.PyGridCellEditor.__init__(self) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
148 |
|
814 | 149 |
self.Table = table |
150 |
self.Controller = controller |
|
151 |
||
152 |
def __del__(self): |
|
153 |
self.CellControl = None |
|
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
154 |
self.Controller = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
155 |
|
814 | 156 |
def Create(self, parent, id, evt_handler): |
157 |
self.CellControl = LocationCellControl(parent) |
|
158 |
self.SetControl(self.CellControl) |
|
159 |
if evt_handler: |
|
160 |
self.CellControl.PushEventHandler(evt_handler) |
|
161 |
||
162 |
def BeginEdit(self, row, col, grid): |
|
163 |
self.CellControl.Enable() |
|
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
164 |
self.CellControl.SetController(self.Controller) |
814 | 165 |
self.CellControl.SetValue(self.Table.GetValueByName(row, 'Location')) |
166 |
if isinstance(self.CellControl, LocationCellControl): |
|
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
167 |
self.CellControl.SetVarType(self.Table.GetValueByName(row, 'Type')) |
814 | 168 |
self.CellControl.SetFocus() |
169 |
||
1536
3518d10487db
fix issue, that was impossible to change variable location IEC-address, when wx 3.0 is used
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1004
diff
changeset
|
170 |
def EndEditInternal(self, row, col, grid, old_loc): |
814 | 171 |
loc = self.CellControl.GetValue() |
172 |
changed = loc != old_loc |
|
173 |
if changed: |
|
174 |
self.Table.SetValueByName(row, 'Location', loc) |
|
855
b30421d07e8c
Adding support for selecting variable type filtering in BrowseLocationsDialog and modify variable type when validated
Laurent Bessard
parents:
814
diff
changeset
|
175 |
self.Table.SetValueByName(row, 'Type', self.CellControl.GetVarType()) |
814 | 176 |
self.CellControl.Disable() |
177 |
return changed |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
178 |
|
1536
3518d10487db
fix issue, that was impossible to change variable location IEC-address, when wx 3.0 is used
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1004
diff
changeset
|
179 |
if wx.VERSION >= (3, 0, 0): |
3518d10487db
fix issue, that was impossible to change variable location IEC-address, when wx 3.0 is used
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1004
diff
changeset
|
180 |
def EndEdit(self, row, col, grid, oldval): |
1550
deadfe7377e9
fix not saving location address from variable panel
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1540
diff
changeset
|
181 |
return self.EndEditInternal(row, col, grid, oldval) |
1536
3518d10487db
fix issue, that was impossible to change variable location IEC-address, when wx 3.0 is used
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1004
diff
changeset
|
182 |
else: |
3518d10487db
fix issue, that was impossible to change variable location IEC-address, when wx 3.0 is used
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1004
diff
changeset
|
183 |
def EndEdit(self, row, col, grid): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
184 |
old_loc = self.Table.GetValueByName(row, 'Location') |
1550
deadfe7377e9
fix not saving location address from variable panel
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1540
diff
changeset
|
185 |
return self.EndEditInternal(row, col, grid, old_loc) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1578
diff
changeset
|
186 |
|
814 | 187 |
def SetSize(self, rect): |
188 |
self.CellControl.SetDimensions(rect.x + 1, rect.y, |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
189 |
rect.width, rect.height, |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
190 |
wx.SIZE_ALLOW_MINUS_ONE) |
814 | 191 |
|
192 |
def Clone(self): |
|
193 |
return LocationCellEditor(self.Table, self.Controller) |