29 |
29 |
30 from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
30 from plcopen.structures import TestIdentifier, IEC_KEYWORDS |
31 from util.TranslationCatalogs import NoTranslate |
31 from util.TranslationCatalogs import NoTranslate |
32 |
32 |
33 |
33 |
34 def GetPouTypes(): |
|
35 _ = NoTranslate |
|
36 return [_("function"), _("functionBlock"), _("program")] |
|
37 |
|
38 |
|
39 POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()]) |
|
40 |
|
41 |
|
42 def GetPouLanguages(): |
|
43 _ = NoTranslate |
|
44 return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")] |
|
45 |
|
46 |
|
47 class PouDialog(wx.Dialog): |
34 class PouDialog(wx.Dialog): |
48 |
35 """ |
49 POU_LANGUAGES = GetPouLanguages() |
36 Dialog to create new POU. |
50 POU_LANGUAGES_DICT = dict([(_(language), language) for language in POU_LANGUAGES]) |
37 It allows selection of POU type, name and |
|
38 used IEC 61131-3 programming language |
|
39 """ |
|
40 |
|
41 POU_TYPES = None |
|
42 POU_TYPES_DICT = None |
|
43 POU_LANGUAGES = None |
|
44 POU_LANGUAGES_DICT = None |
51 |
45 |
52 def __init__(self, parent, pou_type=None, type_readonly=False): |
46 def __init__(self, parent, pou_type=None, type_readonly=False): |
53 wx.Dialog.__init__(self, id=-1, parent=parent, |
47 wx.Dialog.__init__(self, id=-1, parent=parent, |
54 name='PouDialog', title=_('Create a new POU'), |
48 name='PouDialog', title=_('Create a new POU'), |
55 style=wx.DEFAULT_DIALOG_STYLE) |
49 style=wx.DEFAULT_DIALOG_STYLE) |
56 |
50 |
|
51 if PouDialog.POU_TYPES_DICT is None: |
|
52 self.InitPouTypesDict() |
|
53 self.InitPouLanguagesDict() |
|
54 |
57 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
55 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10) |
58 main_sizer.AddGrowableCol(0) |
56 main_sizer.AddGrowableCol(0) |
59 main_sizer.AddGrowableRow(0) |
57 main_sizer.AddGrowableRow(0) |
60 |
58 |
61 infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15) |
59 infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15) |
90 main_sizer.AddSizer(button_sizer, border=20, |
88 main_sizer.AddSizer(button_sizer, border=20, |
91 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
89 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
92 |
90 |
93 self.SetSizer(main_sizer) |
91 self.SetSizer(main_sizer) |
94 |
92 |
95 for option in GetPouTypes(): |
93 for option in self.POU_TYPES: |
96 if not type_readonly or _(option) == _(pou_type): |
94 if not type_readonly or _(option) == _(pou_type): |
97 self.PouType.Append(_(option)) |
95 self.PouType.Append(_(option)) |
98 if pou_type is not None: |
96 if pou_type is not None: |
99 self.PouType.SetStringSelection(_(pou_type)) |
97 self.PouType.SetStringSelection(_(pou_type)) |
100 self.RefreshLanguage() |
98 self.RefreshLanguage() |
101 self.Fit() |
99 self.Fit() |
102 self.PouNames = [] |
100 self.PouNames = [] |
103 self.PouElementNames = [] |
101 self.PouElementNames = [] |
|
102 |
|
103 def InitPouTypes(self): |
|
104 """ |
|
105 Initialize POU_TYPES class list. |
|
106 This list contains not translated POU types used in PLCopen XML. |
|
107 _() are necessary so mk18n.py could find these string for localization. |
|
108 """ |
|
109 _ = NoTranslate |
|
110 self.__class__.POU_TYPES = [_("function"), _("functionBlock"), _("program")] |
|
111 |
|
112 def InitPouTypesDict(self): |
|
113 """ |
|
114 Initialize POU_TYPES_DICT class dictionary and POU_TYPE list |
|
115 Dictionary contains localized POU types and they are shown in UI. |
|
116 """ |
|
117 self.InitPouTypes() |
|
118 self.__class__.POU_TYPES_DICT = dict([(_(pou_type), pou_type) |
|
119 for pou_type in self.POU_TYPES]) |
|
120 |
|
121 def InitPouLanguages(self): |
|
122 """ |
|
123 Initialize POU_LANGUAGES class list. |
|
124 This list contains not translated programming languages used in PLCopen XML. |
|
125 _() are necessary so mk18n.py could find these string for localization. |
|
126 """ |
|
127 _ = NoTranslate |
|
128 self.__class__.POU_LANGUAGES = [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")] |
|
129 |
|
130 def InitPouLanguagesDict(self): |
|
131 """ |
|
132 Initialize POU_LANGUAGES_DICT class dictionary and POU_LANGUAGES list |
|
133 Dictionary contains localized names for programming languages |
|
134 as they are shown in UI. |
|
135 """ |
|
136 self.InitPouLanguages() |
|
137 self.__class__.POU_LANGUAGES_DICT = dict([(_(language), language) |
|
138 for language in self.POU_LANGUAGES]) |
104 |
139 |
105 def OnOK(self, event): |
140 def OnOK(self, event): |
106 error = [] |
141 error = [] |
107 pou_name = self.PouName.GetValue() |
142 pou_name = self.PouName.GetValue() |
108 if pou_name == "": |
143 if pou_name == "": |
148 |
183 |
149 def RefreshLanguage(self): |
184 def RefreshLanguage(self): |
150 selection = self.POU_LANGUAGES_DICT.get(self.Language.GetStringSelection(), "") |
185 selection = self.POU_LANGUAGES_DICT.get(self.Language.GetStringSelection(), "") |
151 self.Language.Clear() |
186 self.Language.Clear() |
152 for language in self.POU_LANGUAGES: |
187 for language in self.POU_LANGUAGES: |
153 if language != "SFC" or POU_TYPES_DICT[self.PouType.GetStringSelection()] != "function": |
188 if language != "SFC" or self.POU_TYPES_DICT[self.PouType.GetStringSelection()] != "function": |
154 self.Language.Append(_(language)) |
189 self.Language.Append(_(language)) |
155 if self.Language.FindString(_(selection)) != wx.NOT_FOUND: |
190 if self.Language.FindString(_(selection)) != wx.NOT_FOUND: |
156 self.Language.SetStringSelection(_(selection)) |
191 self.Language.SetStringSelection(_(selection)) |
157 |
192 |
158 def OnTypeChanged(self, event): |
193 def OnTypeChanged(self, event): |