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 GetPouTypes(): |
32 def GetPouTypes(): |
31 _ = lambda x : x |
33 _ = NoTranslate |
32 return [_("function"), _("functionBlock"), _("program")] |
34 return [_("function"), _("functionBlock"), _("program")] |
|
35 |
|
36 |
33 POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()]) |
37 POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()]) |
34 |
38 |
|
39 |
35 def GetPouLanguages(): |
40 def GetPouLanguages(): |
36 _ = lambda x : x |
41 _ = NoTranslate |
37 return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")] |
42 return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")] |
|
43 |
38 |
44 |
39 class PouDialog(wx.Dialog): |
45 class PouDialog(wx.Dialog): |
40 |
46 |
41 POU_LANGUAGES = GetPouLanguages() |
47 POU_LANGUAGES = GetPouLanguages() |
42 POU_LANGUAGES_DICT = dict([(_(language), language) for language in POU_LANGUAGES]) |
48 POU_LANGUAGES_DICT = dict([(_(language), language) for language in POU_LANGUAGES]) |
43 |
49 |
44 def __init__(self, parent, pou_type=None, type_readonly=False): |
50 def __init__(self, parent, pou_type=None, type_readonly=False): |
45 wx.Dialog.__init__(self, id=-1, parent=parent, |
51 wx.Dialog.__init__(self, id=-1, parent=parent, |
46 name='PouDialog', title=_('Create a new POU'), |
52 name='PouDialog', title=_('Create a new POU'), |
47 style=wx.DEFAULT_DIALOG_STYLE) |
53 style=wx.DEFAULT_DIALOG_STYLE) |
48 |
54 |
49 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) |
50 main_sizer.AddGrowableCol(0) |
56 main_sizer.AddGrowableCol(0) |
51 main_sizer.AddGrowableRow(0) |
57 main_sizer.AddGrowableRow(0) |
52 |
58 |
53 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) |
54 infos_sizer.AddGrowableCol(1) |
60 infos_sizer.AddGrowableCol(1) |
55 main_sizer.AddSizer(infos_sizer, border=20, |
61 main_sizer.AddSizer(infos_sizer, border=20, |
56 flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
62 flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) |
57 |
63 |
58 pouname_label = wx.StaticText(self, label=_('POU Name:')) |
64 pouname_label = wx.StaticText(self, label=_('POU Name:')) |
59 infos_sizer.AddWindow(pouname_label, border=4, |
65 infos_sizer.AddWindow(pouname_label, border=4, |
60 flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
66 flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP) |
61 |
67 |
62 self.PouName = wx.TextCtrl(self) |
68 self.PouName = wx.TextCtrl(self) |
63 infos_sizer.AddWindow(self.PouName, flag=wx.GROW) |
69 infos_sizer.AddWindow(self.PouName, flag=wx.GROW) |
64 |
70 |
65 poutype_label = wx.StaticText(self, label=_('POU Type:')) |
71 poutype_label = wx.StaticText(self, label=_('POU Type:')) |
66 infos_sizer.AddWindow(poutype_label, border=4, |
72 infos_sizer.AddWindow(poutype_label, border=4, |
67 flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
73 flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP) |
68 |
74 |
69 self.PouType = wx.ComboBox(self, style=wx.CB_READONLY) |
75 self.PouType = wx.ComboBox(self, style=wx.CB_READONLY) |
70 self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, self.PouType) |
76 self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, self.PouType) |
71 infos_sizer.AddWindow(self.PouType, flag=wx.GROW) |
77 infos_sizer.AddWindow(self.PouType, flag=wx.GROW) |
72 |
78 |
73 language_label = wx.StaticText(self, label=_('Language:')) |
79 language_label = wx.StaticText(self, label=_('Language:')) |
74 infos_sizer.AddWindow(language_label, border=4, |
80 infos_sizer.AddWindow(language_label, border=4, |
75 flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP) |
81 flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP) |
76 |
82 |
77 self.Language = wx.ComboBox(self, style=wx.CB_READONLY) |
83 self.Language = wx.ComboBox(self, style=wx.CB_READONLY) |
78 infos_sizer.AddWindow(self.Language, flag=wx.GROW) |
84 infos_sizer.AddWindow(self.Language, flag=wx.GROW) |
79 |
85 |
80 button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
86 button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) |
81 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
87 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
82 main_sizer.AddSizer(button_sizer, border=20, |
88 main_sizer.AddSizer(button_sizer, border=20, |
83 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
89 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
84 |
90 |
85 self.SetSizer(main_sizer) |
91 self.SetSizer(main_sizer) |
86 |
92 |
87 for option in GetPouTypes(): |
93 for option in GetPouTypes(): |
88 if not type_readonly or _(option) == _(pou_type): |
94 if not type_readonly or _(option) == _(pou_type): |