diff -r 95a0a427f3ef -r 131ea7f237b9 dialogs/ArrayTypeDialog.py --- a/dialogs/ArrayTypeDialog.py Fri Jun 15 18:03:25 2012 +0200 +++ b/dialogs/ArrayTypeDialog.py Mon Jun 25 20:03:53 2012 +0200 @@ -28,75 +28,55 @@ from controls import CustomEditableListBox +#------------------------------------------------------------------------------- +# Helpers +#------------------------------------------------------------------------------- + DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$") -[ID_ARRAYTYPEDIALOG, ID_ARRAYTYPEDIALOGBASETYPE, - ID_ARRAYTYPEDIALOGDIMENSIONS, ID_ARRAYTYPEDIALOGDIALOGSTATICTEXT1, -] = [wx.NewId() for _init_ctrls in range(4)] +#------------------------------------------------------------------------------- +# Array Type Dialog +#------------------------------------------------------------------------------- class ArrayTypeDialog(wx.Dialog): - if wx.VERSION < (2, 6, 0): - def Bind(self, event, function, id = None): - if id is not None: - event(self, id, function) - else: - event(self, function) - - def _init_coll_flexGridSizer1_Items(self, parent): - parent.AddSizer(self.TopSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) - parent.AddWindow(self.Dimensions, 0, border=20, flag=wx.GROW|wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT) - parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) + def __init__(self, parent, datatypes, infos): + wx.Dialog.__init__(self, parent, + size=wx.Size(500, 300), title=_('Edit array type properties')) - def _init_coll_flexGridSizer1_Growables(self, parent): - parent.AddGrowableCol(0) - parent.AddGrowableRow(1) + main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) + main_sizer.AddGrowableCol(0) + main_sizer.AddGrowableRow(1) - def _init_coll_TopSizer_Items(self, parent): - parent.AddWindow(self.staticText1, 1, border=0, flag=wx.GROW) - parent.AddWindow(self.BaseType, 1, border=0, flag=wx.GROW) - - def _init_sizers(self): - self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) - self.TopSizer = wx.BoxSizer(wx.HORIZONTAL) + top_sizer = wx.BoxSizer(wx.HORIZONTAL) + main_sizer.AddSizer(top_sizer, border=20, + flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT) - self._init_coll_flexGridSizer1_Items(self.flexGridSizer1) - self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1) - self._init_coll_TopSizer_Items(self.TopSizer) + basetype_label = wx.StaticText(self, label=_('Base Type:')) + top_sizer.AddWindow(basetype_label, 1, flag=wx.ALIGN_BOTTOM) - self.SetSizer(self.flexGridSizer1) - - def _init_ctrls(self, prnt): - wx.Dialog.__init__(self, id=ID_ARRAYTYPEDIALOG, - name='ArrayTypeDialog', parent=prnt, - size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER, - title=_('Edit array type properties')) - self.SetClientSize(wx.Size(500, 300)) + self.BaseType = wx.ComboBox(self, style=wx.CB_READONLY) + top_sizer.AddWindow(self.BaseType, 1, flag=wx.GROW) - self.staticText1 = wx.StaticText(id=ID_ARRAYTYPEDIALOGDIALOGSTATICTEXT1, - label=_('Base Type:'), name='staticText1', parent=self, - pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) - - self.BaseType = wx.ComboBox(id=ID_ARRAYTYPEDIALOGBASETYPE, - name='BaseType', parent=self, pos=wx.Point(0, 0), - size=wx.Size(0, 28), style=wx.CB_READONLY) + self.Dimensions = CustomEditableListBox(self, label=_("Dimensions:"), + style=wx.gizmos.EL_ALLOW_NEW| + wx.gizmos.EL_ALLOW_EDIT| + wx.gizmos.EL_ALLOW_DELETE) + for func in ["_OnLabelEndEdit", + "_OnAddButton", + "_OnDelButton", + "_OnUpButton", + "_OnDownButton"]: + setattr(self.Dimensions, func, self.OnDimensionsChanged) + main_sizer.AddSizer(self.Dimensions, border=20, + flag=wx.GROW|wx.LEFT|wx.RIGHT) - self.Dimensions = CustomEditableListBox(id=ID_ARRAYTYPEDIALOGDIMENSIONS, - name='ArrayDimensions', parent=self, label=_("Dimensions:"), pos=wx.Point(0, 0), - size=wx.Size(0, 24), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE) - for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]: - setattr(self.Dimensions, func, self.OnDimensionsChanged) + button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) + self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton()) + main_sizer.AddSizer(button_sizer, border=20, + flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) - self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) - if wx.VERSION >= (2, 5, 0): - self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) - else: - self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) - - self._init_sizers() - - def __init__(self, parent, datatypes, infos): - self._init_ctrls(parent) + self.SetSizer(main_sizer) for datatype in datatypes: self.BaseType.Append(datatype)