author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Mon, 17 Jan 2022 15:17:47 +0100 | |
changeset 3407 | 2f5c30054d50 |
parent 2301 | 5b8a7dd43f9f |
child 3303 | 0ffb41625592 |
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:
1493
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:
1493
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:
1493
diff
changeset
|
7 |
# Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1670
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
814 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1493
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
814 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1493
diff
changeset
|
12 |
# 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:
1493
diff
changeset
|
13 |
# 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:
1493
diff
changeset
|
14 |
# 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:
1493
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
814 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1493
diff
changeset
|
17 |
# 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:
1493
diff
changeset
|
18 |
# 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:
1493
diff
changeset
|
19 |
# 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:
1493
diff
changeset
|
20 |
# GNU General Public License for more details. |
814 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1493
diff
changeset
|
22 |
# 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:
1493
diff
changeset
|
23 |
# 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:
1493
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 25 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
26 |
|
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
27 |
from __future__ import absolute_import |
814 | 28 |
import wx |
29 |
||
30 |
from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
|
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
31 |
from util.TranslationCatalogs import NoTranslate |
814 | 32 |
|
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
33 |
# ------------------------------------------------------------------------------- |
814 | 34 |
# POU Transition Dialog |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
35 |
# ------------------------------------------------------------------------------- |
814 | 36 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
37 |
|
814 | 38 |
def GetTransitionLanguages(): |
1762
fcc406143e5b
clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
39 |
_ = NoTranslate |
1670
cd03b8432541
enable to write SFC transition in IL
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1617
diff
changeset
|
40 |
return [_("IL"), _("ST"), _("LD"), _("FBD")] |
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
41 |
|
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
42 |
|
814 | 43 |
class PouTransitionDialog(wx.Dialog): |
44 |
def __init__(self, parent): |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1670
diff
changeset
|
45 |
wx.Dialog.__init__(self, parent, title=_('Create a new transition')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
46 |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
47 |
self.TRANSITION_LANGUAGES_DICT = dict([(_(language), language) |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
48 |
for language in GetTransitionLanguages()]) |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
49 |
|
814 | 50 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
51 |
main_sizer.AddGrowableCol(0) |
|
52 |
main_sizer.AddGrowableRow(0) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
53 |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1670
diff
changeset
|
54 |
infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=10) |
814 | 55 |
infos_sizer.AddGrowableCol(1) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
56 |
main_sizer.AddSizer(infos_sizer, border=20, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
57 |
flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
58 |
|
814 | 59 |
transitionname_label = wx.StaticText(self, label=_('Transition Name:')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
60 |
infos_sizer.AddWindow(transitionname_label, border=4, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
61 |
flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP) |
814 | 62 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
63 |
self.TransitionName = wx.TextCtrl(self, size=wx.Size(180, -1)) |
814 | 64 |
infos_sizer.AddWindow(self.TransitionName, flag=wx.GROW) |
65 |
||
66 |
language_label = wx.StaticText(self, label=_('Language:')) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
67 |
infos_sizer.AddWindow(language_label, border=4, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
68 |
flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
69 |
|
814 | 70 |
self.Language = wx.ComboBox(self, style=wx.CB_READONLY) |
71 |
infos_sizer.AddWindow(self.Language, flag=wx.GROW) |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1670
diff
changeset
|
72 |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
73 |
button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) |
814 | 74 |
self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
75 |
main_sizer.AddSizer(button_sizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
76 |
|
814 | 77 |
self.SetSizer(main_sizer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
78 |
|
814 | 79 |
for language in GetTransitionLanguages(): |
80 |
self.Language.Append(_(language)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
81 |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1670
diff
changeset
|
82 |
self.Fit() |
814 | 83 |
self.PouNames = [] |
84 |
self.PouElementNames = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
85 |
|
814 | 86 |
def OnOK(self, event): |
87 |
error = [] |
|
88 |
transition_name = self.TransitionName.GetValue() |
|
89 |
if self.TransitionName.GetValue() == "": |
|
90 |
error.append(_("Transition Name")) |
|
91 |
if self.Language.GetSelection() == -1: |
|
92 |
error.append(_("Language")) |
|
93 |
message = None |
|
94 |
if len(error) > 0: |
|
95 |
text = "" |
|
96 |
for i, item in enumerate(error): |
|
97 |
if i == 0: |
|
98 |
text += item |
|
99 |
elif i == len(error) - 1: |
|
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
100 |
text += _(" and %s") % item |
814 | 101 |
else: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
102 |
text += _(", %s") % item |
814 | 103 |
message = _("Form isn't complete. %s must be filled!") % text |
104 |
elif not TestIdentifier(transition_name): |
|
105 |
message = _("\"%s\" is not a valid identifier!") % transition_name |
|
106 |
elif transition_name.upper() in IEC_KEYWORDS: |
|
107 |
message = _("\"%s\" is a keyword. It can't be used!") % transition_name |
|
108 |
elif transition_name.upper() in self.PouNames: |
|
109 |
message = _("A POU named \"%s\" already exists!") % transition_name |
|
110 |
elif transition_name.upper() in self.PouElementNames: |
|
111 |
message = _("\"%s\" element for this pou already exists!") % transition_name |
|
112 |
if message is not None: |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
113 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 114 |
dialog.ShowModal() |
115 |
dialog.Destroy() |
|
116 |
else: |
|
117 |
self.EndModal(wx.ID_OK) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
118 |
|
814 | 119 |
def SetPouNames(self, pou_names): |
120 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
121 |
|
814 | 122 |
def SetPouElementNames(self, pou_names): |
123 |
self.PouElementNames = [pou_name.upper() for pou_name in pou_names] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
124 |
|
814 | 125 |
def SetValues(self, values): |
126 |
for item, value in values.items(): |
|
127 |
if item == "transitionName": |
|
128 |
self.TransitionName.SetValue(value) |
|
129 |
elif item == "language": |
|
130 |
self.Language.SetSelection(_(value)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
131 |
|
814 | 132 |
def GetValues(self): |
133 |
values = {} |
|
134 |
values["transitionName"] = self.TransitionName.GetValue() |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
135 |
values["language"] = self.TRANSITION_LANGUAGES_DICT[self.Language.GetStringSelection()] |
814 | 136 |
return values |