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