author | Laurent Bessard |
Fri, 08 Jun 2012 12:36:24 +0200 | |
changeset 707 | e850bc674852 |
parent 705 | 1a343b239e9c |
child 714 | 131ea7f237b9 |
permissions | -rw-r--r-- |
705
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
3 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
5 |
#based on the plcopen standard. |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
6 |
# |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
7 |
#Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
8 |
# |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
9 |
#See COPYING file for copyrights details. |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
10 |
# |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
11 |
#This library is free software; you can redistribute it and/or |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
12 |
#modify it under the terms of the GNU General Public |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
13 |
#License as published by the Free Software Foundation; either |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
15 |
# |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
16 |
#This library is distributed in the hope that it will be useful, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
19 |
#General Public License for more details. |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
20 |
# |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
21 |
#You should have received a copy of the GNU General Public |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
22 |
#License along with this library; if not, write to the Free Software |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
24 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
25 |
import wx |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
26 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
27 |
from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
28 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
29 |
def GetPouTypes(): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
30 |
_ = lambda x : x |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
31 |
return [_("function"), _("functionBlock"), _("program")] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
32 |
POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()]) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
33 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
34 |
def GetPouLanguages(): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
35 |
_ = lambda x : x |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
36 |
return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
37 |
POU_LANGUAGES_DICT = dict([(_(language), language) for language in GetPouLanguages()]) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
38 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
39 |
class PouDialog(wx.Dialog): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
40 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
41 |
def __init__(self, parent, pou_type = None): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
42 |
wx.Dialog.__init__(self, id=-1, parent=parent, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
43 |
name='PouDialog', title=_('Create a new POU'), |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
44 |
size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
45 |
self.SetClientSize(wx.Size(300, 200)) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
46 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
47 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
48 |
main_sizer.AddGrowableCol(0) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
49 |
main_sizer.AddGrowableRow(0) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
50 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
51 |
infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
52 |
infos_sizer.AddGrowableCol(1) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
53 |
main_sizer.AddSizer(infos_sizer, 0, border=20, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
54 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
55 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
56 |
pouname_label = wx.StaticText(id=-1, parent=self, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
57 |
label=_('POU Name:'), name='pouname_label', |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
58 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
59 |
infos_sizer.AddWindow(pouname_label, 0, border=4, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
60 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
61 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
62 |
self.PouName = wx.TextCtrl(id=-1, parent=self, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
63 |
name='POUName', pos=wx.Point(0, 0), |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
64 |
size=wx.Size(0, 24), style=0) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
65 |
infos_sizer.AddWindow(self.PouName, 0, border=0, flag=wx.GROW) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
66 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
67 |
poutype_label = wx.StaticText(id=-1, parent=self, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
68 |
label=_('POU Type:'), name='poutype_label', |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
69 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
70 |
infos_sizer.AddWindow(poutype_label, 0, border=4, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
71 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
72 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
73 |
self.PouType = wx.ComboBox(id=-1, parent=self, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
74 |
name='POUType', pos=wx.Point(0, 0), |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
75 |
size=wx.Size(0, 28), style=wx.CB_READONLY) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
76 |
self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, id=self.PouType.GetId()) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
77 |
infos_sizer.AddWindow(self.PouType, 0, border=0, flag=wx.GROW) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
78 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
79 |
language_label = wx.StaticText(id=-1, parent=self, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
80 |
label=_('Language:'), name='language_label', |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
81 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
82 |
infos_sizer.AddWindow(language_label, 0, border=4, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
83 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
84 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
85 |
self.Language = wx.ComboBox(id=-1, parent=self, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
86 |
name='Language', pos=wx.Point(0, 0), |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
87 |
size=wx.Size(0, 28), style=wx.CB_READONLY) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
88 |
infos_sizer.AddWindow(self.Language, 0, border=0, flag=wx.GROW) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
89 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
90 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
91 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
92 |
main_sizer.AddSizer(self.ButtonSizer, 0, border=20, |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
93 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
94 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
95 |
self.SetSizer(main_sizer) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
96 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
97 |
for option in GetPouTypes(): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
98 |
self.PouType.Append(_(option)) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
99 |
if pou_type is not None: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
100 |
self.PouType.SetStringSelection(_(pou_type)) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
101 |
self.RefreshLanguage() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
102 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
103 |
self.PouNames = [] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
104 |
self.PouElementNames = [] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
105 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
106 |
def OnOK(self, event): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
107 |
error = [] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
108 |
pou_name = self.PouName.GetValue() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
109 |
if pou_name == "": |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
110 |
error.append(_("POU Name")) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
111 |
if self.PouType.GetSelection() == -1: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
112 |
error.append(_("POU Type")) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
113 |
if self.Language.GetSelection() == -1: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
114 |
error.append(_("Language")) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
115 |
message = None |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
116 |
question = False |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
117 |
if len(error) > 0: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
118 |
text = "" |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
119 |
for i, item in enumerate(error): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
120 |
if i == 0: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
121 |
text += item |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
122 |
elif i == len(error) - 1: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
123 |
text += _(" and %s")%item |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
124 |
else: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
125 |
text += _(", %s")%item |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
126 |
message = _("Form isn't complete. %s must be filled!") % text |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
127 |
elif not TestIdentifier(pou_name): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
128 |
message = _("\"%s\" is not a valid identifier!") % pou_name |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
129 |
elif pou_name.upper() in IEC_KEYWORDS: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
130 |
message = _("\"%s\" is a keyword. It can't be used!") % pou_name |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
131 |
elif pou_name.upper() in self.PouNames: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
132 |
message = _("\"%s\" pou already exists!") % pou_name |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
133 |
elif pou_name.upper() in self.PouElementNames: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
134 |
message = _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?") % pou_name |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
135 |
question = True |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
136 |
if message is not None: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
137 |
if question: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
138 |
dialog = wx.MessageDialog(self, message, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
139 |
result = dialog.ShowModal() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
140 |
dialog.Destroy() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
141 |
if result == wx.ID_YES: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
142 |
self.EndModal(wx.ID_OK) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
143 |
else: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
144 |
dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
145 |
dialog.ShowModal() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
146 |
dialog.Destroy() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
147 |
else: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
148 |
self.EndModal(wx.ID_OK) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
149 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
150 |
def RefreshLanguage(self): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
151 |
selection = POU_LANGUAGES_DICT.get(self.Language.GetStringSelection(), "") |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
152 |
self.Language.Clear() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
153 |
for language in GetPouLanguages(): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
154 |
if language != "SFC" or POU_TYPES_DICT[self.PouType.GetStringSelection()] != "function": |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
155 |
self.Language.Append(_(language)) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
156 |
if self.Language.FindString(_(selection)) != wx.NOT_FOUND: |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
157 |
self.Language.SetStringSelection(_(selection)) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
158 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
159 |
def OnTypeChanged(self, event): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
160 |
self.RefreshLanguage() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
161 |
event.Skip() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
162 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
163 |
def SetPouNames(self, pou_names): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
164 |
self.PouNames = [pou_name.upper() for pou_name in pou_names] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
165 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
166 |
def SetPouElementNames(self, element_names): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
167 |
self.PouElementNames = [element_name.upper() for element_name in element_names] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
168 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
169 |
def SetValues(self, values): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
170 |
for item, value in values.items(): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
171 |
if item == "pouName": |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
172 |
self.PouName.SetValue(value) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
173 |
elif item == "pouType": |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
174 |
self.PouType.SetStringSelection(_(value)) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
175 |
elif item == "language": |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
176 |
self.Language.SetStringSelection(_(value)) |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
177 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
178 |
def GetValues(self): |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
179 |
values = {} |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
180 |
values["pouName"] = self.PouName.GetValue() |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
181 |
values["pouType"] = POU_TYPES_DICT[self.PouType.GetStringSelection()] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
182 |
values["language"] = POU_LANGUAGES_DICT[self.Language.GetStringSelection()] |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
183 |
return values |
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
184 |
|
1a343b239e9c
Replacing dialog asking for a name when adding datatype, configuration and resource by automatically generated name
Laurent Bessard
parents:
diff
changeset
|
185 |