author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Thu, 19 Jan 2017 13:56:09 +0300 | |
changeset 1639 | 1953c268a194 |
parent 1571 | 486f94a8032c |
child 1696 | 8043f32de7b8 |
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 |
814 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1493
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:
1493
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:
1493
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:
1493
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:
1493
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:
1493
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:
1493
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:
1493
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:
1493
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:
1493
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:
1493
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:
1493
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
814 | 24 |
|
25 |
import wx |
|
26 |
||
27 |
from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
|
28 |
||
29 |
def GetActionLanguages(): |
|
30 |
_ = lambda x : x |
|
31 |
return [_("IL"), _("ST"), _("LD"), _("FBD")] |
|
32 |
ACTION_LANGUAGES_DICT = dict([(_(language), language) for language in GetActionLanguages()]) |
|
33 |
||
34 |
class PouActionDialog(wx.Dialog): |
|
35 |
||
36 |
def __init__(self, parent): |
|
1493
6dbebfcec074
increase height of some dialog windows so they have enough space for buttons
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
37 |
wx.Dialog.__init__(self, parent, size=wx.Size(320, 200), |
814 | 38 |
title=_('Create a new action')) |
39 |
||
40 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
|
41 |
main_sizer.AddGrowableCol(0) |
|
42 |
main_sizer.AddGrowableRow(0) |
|
43 |
||
44 |
infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15) |
|
45 |
infos_sizer.AddGrowableCol(1) |
|
46 |
main_sizer.AddSizer(infos_sizer, border=20, |
|
47 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
|
48 |
||
49 |
actionname_label = wx.StaticText(self, label=_('Action Name:')) |
|
50 |
infos_sizer.AddWindow(actionname_label, border=4, |
|
51 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
|
52 |
||
53 |
self.ActionName = wx.TextCtrl(self) |
|
54 |
infos_sizer.AddWindow(self.ActionName, flag=wx.GROW) |
|
55 |
||
56 |
language_label = wx.StaticText(self, label=_('Language:')) |
|
57 |
infos_sizer.AddWindow(language_label, border=4, |
|
58 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
|
59 |
||
60 |
self.Language = wx.ComboBox(self, style=wx.CB_READONLY) |
|
61 |
infos_sizer.AddWindow(self.Language, flag=wx.GROW) |
|
62 |
||
63 |
button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
|
64 |
self.Bind(wx.EVT_BUTTON, self.OnOK, |
|
65 |
button_sizer.GetAffirmativeButton()) |
|
66 |
main_sizer.AddSizer(button_sizer, border=20, |
|
67 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
|
68 |
||
69 |
self.SetSizer(main_sizer) |
|
70 |
||
71 |
for option in GetActionLanguages(): |
|
72 |
self.Language.Append(_(option)) |
|
73 |
||
74 |
self.PouNames = [] |
|
75 |
self.PouElementNames = [] |
|
76 |
||
77 |
def OnOK(self, event): |
|
78 |
error = [] |
|
79 |
action_name = self.ActionName.GetValue() |
|
80 |
if action_name == "": |
|
81 |
error.append(_("Action Name")) |
|
82 |
if self.Language.GetSelection() == -1: |
|
83 |
error.append(_("Language")) |
|
84 |
message = None |
|
85 |
if len(error) > 0: |
|
86 |
text = "" |
|
87 |
for i, item in enumerate(error): |
|
88 |
if i == 0: |
|
89 |
text += item |
|
90 |
elif i == len(error) - 1: |
|
91 |
text += _(" and %s")%item |
|
92 |
else: |
|
93 |
text += _(", %s")%item |
|
94 |
message = _("Form isn't complete. %s must be filled!") % text |
|
95 |
elif not TestIdentifier(action_name): |
|
96 |
message = _("\"%s\" is not a valid identifier!") % action_name |
|
97 |
elif action_name.upper() in IEC_KEYWORDS: |
|
98 |
message = _("\"%s\" is a keyword. It can't be used!") % action_name |
|
99 |
elif action_name.upper() in self.PouNames: |
|
100 |
message = _("A POU named \"%s\" already exists!") % action_name |
|
101 |
elif action_name.upper() in self.PouElementNames: |
|
102 |
message = _("\"%s\" element for this pou already exists!") % action_name |
|
103 |
if message is not None: |
|
104 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
105 |
dialog.ShowModal() |
|
106 |
dialog.Destroy() |
|
107 |
else: |
|
108 |
self.EndModal(wx.ID_OK) |
|
109 |
||
110 |
def SetPouNames(self, pou_names): |
|
111 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
112 |
||
113 |
def SetPouElementNames(self, element_names): |
|
114 |
self.PouElementNames = [element_name.upper() for element_name in element_names] |
|
115 |
||
116 |
def SetValues(self, values): |
|
117 |
for item, value in values.items(): |
|
118 |
if item == "actionName": |
|
119 |
self.ActionName.SetValue(value) |
|
120 |
elif item == "language": |
|
121 |
self.Language.SetStringSelection(_(value)) |
|
122 |
||
123 |
def GetValues(self): |
|
124 |
values = {} |
|
125 |
values["actionName"] = self.ActionName.GetValue() |
|
126 |
values["language"] = ACTION_LANGUAGES_DICT[self.Language.GetStringSelection()] |
|
127 |
return values |
|
128 |