author | Edouard Tisserant |
Tue, 20 Aug 2019 10:30:59 +0200 | |
branch | svghmi |
changeset 2762 | 282500e03dbc |
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:
1571
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:
1768
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:
1768
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 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
33 |
|
814 | 34 |
def GetActionLanguages(): |
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
|
35 |
_ = NoTranslate |
814 | 36 |
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
|
37 |
|
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
|
38 |
|
814 | 39 |
class PouActionDialog(wx.Dialog): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
40 |
|
814 | 41 |
def __init__(self, parent): |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
42 |
wx.Dialog.__init__(self, parent, title=_('Create a new action')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
43 |
|
2301
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
44 |
self.ACTION_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
|
45 |
for language in GetActionLanguages()]) |
5b8a7dd43f9f
Avoid usage of localized strings before initialization during import in many modules
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1881
diff
changeset
|
46 |
|
814 | 47 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
48 |
main_sizer.AddGrowableCol(0) |
|
49 |
main_sizer.AddGrowableRow(0) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
50 |
|
814 | 51 |
infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15) |
52 |
infos_sizer.AddGrowableCol(1) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
|
814 | 56 |
actionname_label = wx.StaticText(self, label=_('Action Name:')) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
57 |
infos_sizer.AddWindow(actionname_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
|
58 |
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
|
59 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
60 |
self.ActionName = wx.TextCtrl(self, size=wx.Size(180, -1)) |
814 | 61 |
infos_sizer.AddWindow(self.ActionName, flag=wx.GROW) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
62 |
|
814 | 63 |
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
|
64 |
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
|
65 |
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
|
66 |
|
814 | 67 |
self.Language = wx.ComboBox(self, style=wx.CB_READONLY) |
68 |
infos_sizer.AddWindow(self.Language, flag=wx.GROW) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
69 |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
70 |
button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
71 |
self.Bind(wx.EVT_BUTTON, self.OnOK, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
72 |
button_sizer.GetAffirmativeButton()) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
73 |
main_sizer.AddSizer(button_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
|
74 |
flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
75 |
|
814 | 76 |
self.SetSizer(main_sizer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
77 |
|
814 | 78 |
for option in GetActionLanguages(): |
79 |
self.Language.Append(_(option)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
80 |
|
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
81 |
self.Fit() |
814 | 82 |
self.PouNames = [] |
83 |
self.PouElementNames = [] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
84 |
|
814 | 85 |
def OnOK(self, event): |
86 |
error = [] |
|
87 |
action_name = self.ActionName.GetValue() |
|
88 |
if action_name == "": |
|
89 |
error.append(_("Action Name")) |
|
90 |
if self.Language.GetSelection() == -1: |
|
91 |
error.append(_("Language")) |
|
92 |
message = None |
|
93 |
if len(error) > 0: |
|
94 |
text = "" |
|
95 |
for i, item in enumerate(error): |
|
96 |
if i == 0: |
|
97 |
text += item |
|
98 |
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
|
99 |
text += _(" and %s") % item |
814 | 100 |
else: |
1734
750eeb7230a1
clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
101 |
text += _(", %s") % item |
814 | 102 |
message = _("Form isn't complete. %s must be filled!") % text |
103 |
elif not TestIdentifier(action_name): |
|
104 |
message = _("\"%s\" is not a valid identifier!") % action_name |
|
105 |
elif action_name.upper() in IEC_KEYWORDS: |
|
106 |
message = _("\"%s\" is a keyword. It can't be used!") % action_name |
|
107 |
elif action_name.upper() in self.PouNames: |
|
108 |
message = _("A POU named \"%s\" already exists!") % action_name |
|
109 |
elif action_name.upper() in self.PouElementNames: |
|
110 |
message = _("\"%s\" element for this pou already exists!") % action_name |
|
111 |
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
|
112 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
814 | 113 |
dialog.ShowModal() |
114 |
dialog.Destroy() |
|
115 |
else: |
|
116 |
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
|
117 |
|
814 | 118 |
def SetPouNames(self, pou_names): |
119 |
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
|
120 |
|
814 | 121 |
def SetPouElementNames(self, element_names): |
122 |
self.PouElementNames = [element_name.upper() for element_name in element_names] |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
123 |
|
814 | 124 |
def SetValues(self, values): |
125 |
for item, value in values.items(): |
|
126 |
if item == "actionName": |
|
127 |
self.ActionName.SetValue(value) |
|
128 |
elif item == "language": |
|
129 |
self.Language.SetStringSelection(_(value)) |
|
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
130 |
|
814 | 131 |
def GetValues(self): |
132 |
values = {} |
|
133 |
values["actionName"] = self.ActionName.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
|
134 |
values["language"] = self.ACTION_LANGUAGES_DICT[self.Language.GetStringSelection()] |
814 | 135 |
return values |