26 |
26 |
27 import wx |
27 import wx |
28 |
28 |
29 from controls import CustomEditableListBox |
29 from controls import CustomEditableListBox |
30 |
30 |
31 #------------------------------------------------------------------------------- |
31 # ------------------------------------------------------------------------------- |
32 # Helpers |
32 # Helpers |
33 #------------------------------------------------------------------------------- |
33 # ------------------------------------------------------------------------------- |
34 |
34 |
35 DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") |
35 DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") |
36 |
36 |
37 #------------------------------------------------------------------------------- |
37 # ------------------------------------------------------------------------------- |
38 # Array Type Dialog |
38 # Array Type Dialog |
39 #------------------------------------------------------------------------------- |
39 # ------------------------------------------------------------------------------- |
|
40 |
40 |
41 |
41 class ArrayTypeDialog(wx.Dialog): |
42 class ArrayTypeDialog(wx.Dialog): |
42 |
43 |
43 def __init__(self, parent, datatypes, infos): |
44 def __init__(self, parent, datatypes, infos): |
44 wx.Dialog.__init__(self, parent, title=_('Edit array type properties')) |
45 wx.Dialog.__init__(self, parent, title=_('Edit array type properties')) |
45 |
46 |
46 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
47 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
47 main_sizer.AddGrowableCol(0) |
48 main_sizer.AddGrowableCol(0) |
48 main_sizer.AddGrowableRow(1) |
49 main_sizer.AddGrowableRow(1) |
49 |
50 |
50 top_sizer = wx.BoxSizer(wx.HORIZONTAL) |
51 top_sizer = wx.BoxSizer(wx.HORIZONTAL) |
51 main_sizer.AddSizer(top_sizer, border=20, |
52 main_sizer.AddSizer(top_sizer, border=20, |
52 flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) |
53 flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT) |
53 |
54 |
54 basetype_label = wx.StaticText(self, label=_('Base Type:')) |
55 basetype_label = wx.StaticText(self, label=_('Base Type:')) |
55 top_sizer.AddWindow(basetype_label, 1, flag=wx.ALIGN_BOTTOM) |
56 top_sizer.AddWindow(basetype_label, 1, flag=wx.ALIGN_BOTTOM) |
56 |
57 |
57 self.BaseType = wx.ComboBox(self, style=wx.CB_READONLY) |
58 self.BaseType = wx.ComboBox(self, style=wx.CB_READONLY) |
58 top_sizer.AddWindow(self.BaseType, 1, flag=wx.GROW) |
59 top_sizer.AddWindow(self.BaseType, 1, flag=wx.GROW) |
59 |
60 |
60 self.Dimensions = CustomEditableListBox(self, label=_("Dimensions:"), |
61 self.Dimensions = CustomEditableListBox(self, label=_("Dimensions:"), |
61 style=wx.gizmos.EL_ALLOW_NEW| |
62 style=(wx.gizmos.EL_ALLOW_NEW | |
62 wx.gizmos.EL_ALLOW_EDIT| |
63 wx.gizmos.EL_ALLOW_EDIT | |
63 wx.gizmos.EL_ALLOW_DELETE) |
64 wx.gizmos.EL_ALLOW_DELETE)) |
64 for func in ["_OnLabelEndEdit", |
65 for func in ["_OnLabelEndEdit", |
65 "_OnAddButton", |
66 "_OnAddButton", |
66 "_OnDelButton", |
67 "_OnDelButton", |
67 "_OnUpButton", |
68 "_OnUpButton", |
68 "_OnDownButton"]: |
69 "_OnDownButton"]: |
69 setattr(self.Dimensions, func, self.OnDimensionsChanged) |
70 setattr(self.Dimensions, func, self.OnDimensionsChanged) |
70 main_sizer.AddSizer(self.Dimensions, border=20, |
71 main_sizer.AddSizer(self.Dimensions, border=20, |
71 flag=wx.GROW|wx.LEFT|wx.RIGHT) |
72 flag=wx.GROW | wx.LEFT | wx.RIGHT) |
72 |
73 |
73 button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
74 button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE) |
74 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
75 self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) |
75 main_sizer.AddSizer(button_sizer, border=20, |
76 main_sizer.AddSizer(button_sizer, border=20, |
76 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
77 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
77 |
78 |
78 self.SetSizer(main_sizer) |
79 self.SetSizer(main_sizer) |
79 |
80 |
80 for datatype in datatypes: |
81 for datatype in datatypes: |
81 self.BaseType.Append(datatype) |
82 self.BaseType.Append(datatype) |
82 |
83 |
83 if isinstance(infos, TupleType) and infos[0] == "array": |
84 if isinstance(infos, TupleType) and infos[0] == "array": |
84 self.BaseType.SetStringSelection(infos[1]) |
85 self.BaseType.SetStringSelection(infos[1]) |
85 self.Dimensions.SetStrings(map(lambda x : "..".join(x), infos[2])) |
86 self.Dimensions.SetStrings(map(lambda x: "..".join(x), infos[2])) |
86 elif infos in datatypes: |
87 elif infos in datatypes: |
87 self.BaseType.SetStringSelection(infos) |
88 self.BaseType.SetStringSelection(infos) |
88 |
89 |
89 self.BaseType.SetFocus() |
90 self.BaseType.SetFocus() |
90 self.Fit() |
91 self.Fit() |
91 |
92 |
92 def GetDimensions(self): |
93 def GetDimensions(self): |
93 message = None |
94 message = None |
94 dimensions_list = [] |
95 dimensions_list = [] |
95 dimension_strings = self.Dimensions.GetStrings() |
96 dimension_strings = self.Dimensions.GetStrings() |
96 if len(dimension_strings) == 0: |
97 if len(dimension_strings) == 0: |
97 message = _("Empty dimension isn't allowed.") |
98 message = _("Empty dimension isn't allowed.") |
98 |
99 |
99 for dimensions in dimension_strings: |
100 for dimensions in dimension_strings: |
100 result = DIMENSION_MODEL.match(dimensions) |
101 result = DIMENSION_MODEL.match(dimensions) |
101 if result is None: |
102 if result is None: |
102 message = _("\"%s\" value isn't a valid array dimension!")%dimensions |
103 message = _("\"%s\" value isn't a valid array dimension!") % dimensions |
103 break |
104 break |
104 bounds = result.groups() |
105 bounds = result.groups() |
105 if int(bounds[0]) >= int(bounds[1]): |
106 if int(bounds[0]) >= int(bounds[1]): |
106 message = _("\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value.")%dimensions |
107 message = _("\"%s\" value isn't a valid array dimension!\nRight value must be greater than left value.") % dimensions |
107 break |
108 break |
108 dimensions_list.append(bounds) |
109 dimensions_list.append(bounds) |
109 |
110 |
110 if message is not None: |
111 if message is not None: |
111 dlg = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
112 dlg = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR) |
112 dlg.ShowModal() |
113 dlg.ShowModal() |
113 dlg.Destroy() |
114 dlg.Destroy() |
114 return None |
115 return None |
115 return dimensions_list |
116 return dimensions_list |
116 |
117 |
117 def OnDimensionsChanged(self, event): |
118 def OnDimensionsChanged(self, event): |
118 wx.CallAfter(self.GetDimensions) |
119 wx.CallAfter(self.GetDimensions) |
119 event.Skip() |
120 event.Skip() |
120 |
121 |
121 def OnOK(self, event): |
122 def OnOK(self, event): |
122 if self.GetDimensions() is not None: |
123 if self.GetDimensions() is not None: |
123 self.EndModal(wx.ID_OK) |
124 self.EndModal(wx.ID_OK) |
124 |
125 |
125 def GetValue(self): |
126 def GetValue(self): |
126 return "array", self.BaseType.GetStringSelection(), self.GetDimensions() |
127 return "array", self.BaseType.GetStringSelection(), self.GetDimensions() |