dialogs/ArrayTypeDialog.py
changeset 714 131ea7f237b9
parent 640 c32c169b8f63
equal deleted inserted replaced
713:95a0a427f3ef 714:131ea7f237b9
    26 
    26 
    27 import wx
    27 import wx
    28 
    28 
    29 from controls import CustomEditableListBox
    29 from controls import CustomEditableListBox
    30 
    30 
       
    31 #-------------------------------------------------------------------------------
       
    32 #                                  Helpers
       
    33 #-------------------------------------------------------------------------------
       
    34 
    31 DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
    35 DIMENSION_MODEL = re.compile("([0-9]+)\.\.([0-9]+)$")
    32 
    36 
    33 [ID_ARRAYTYPEDIALOG, ID_ARRAYTYPEDIALOGBASETYPE, 
    37 #-------------------------------------------------------------------------------
    34  ID_ARRAYTYPEDIALOGDIMENSIONS, ID_ARRAYTYPEDIALOGDIALOGSTATICTEXT1, 
    38 #                             Array Type Dialog
    35 ] = [wx.NewId() for _init_ctrls in range(4)]
    39 #-------------------------------------------------------------------------------
    36 
    40 
    37 class ArrayTypeDialog(wx.Dialog):
    41 class ArrayTypeDialog(wx.Dialog):
    38     
    42     
    39     if wx.VERSION < (2, 6, 0):
    43     def __init__(self, parent, datatypes, infos):
    40         def Bind(self, event, function, id = None):
    44         wx.Dialog.__init__(self, parent,
    41             if id is not None:
    45               size=wx.Size(500, 300), title=_('Edit array type properties'))
    42                 event(self, id, function)
       
    43             else:
       
    44                 event(self, function)
       
    45     
       
    46     def _init_coll_flexGridSizer1_Items(self, parent):
       
    47         parent.AddSizer(self.TopSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
       
    48         parent.AddWindow(self.Dimensions, 0, border=20, flag=wx.GROW|wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT)
       
    49         parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
       
    50         
    46         
    51     def _init_coll_flexGridSizer1_Growables(self, parent):
    47         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
    52         parent.AddGrowableCol(0)
    48         main_sizer.AddGrowableCol(0)
    53         parent.AddGrowableRow(1)
    49         main_sizer.AddGrowableRow(1)
    54         
    50         
    55     def _init_coll_TopSizer_Items(self, parent):
    51         top_sizer = wx.BoxSizer(wx.HORIZONTAL)
    56         parent.AddWindow(self.staticText1, 1, border=0, flag=wx.GROW)
    52         main_sizer.AddSizer(top_sizer, border=20, 
    57         parent.AddWindow(self.BaseType, 1, border=0, flag=wx.GROW)
    53               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
    58     
       
    59     def _init_sizers(self):
       
    60         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
       
    61         self.TopSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    62         
    54         
    63         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
    55         basetype_label = wx.StaticText(self, label=_('Base Type:'))
    64         self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
    56         top_sizer.AddWindow(basetype_label, 1, flag=wx.ALIGN_BOTTOM)
    65         self._init_coll_TopSizer_Items(self.TopSizer)
       
    66         
    57         
    67         self.SetSizer(self.flexGridSizer1)
    58         self.BaseType = wx.ComboBox(self, style=wx.CB_READONLY)
    68     
    59         top_sizer.AddWindow(self.BaseType, 1, flag=wx.GROW)
    69     def _init_ctrls(self, prnt):
       
    70         wx.Dialog.__init__(self, id=ID_ARRAYTYPEDIALOG,
       
    71               name='ArrayTypeDialog', parent=prnt,
       
    72               size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
       
    73               title=_('Edit array type properties'))
       
    74         self.SetClientSize(wx.Size(500, 300))
       
    75         
    60         
    76         self.staticText1 = wx.StaticText(id=ID_ARRAYTYPEDIALOGDIALOGSTATICTEXT1,
    61         self.Dimensions = CustomEditableListBox(self, label=_("Dimensions:"), 
    77               label=_('Base Type:'), name='staticText1', parent=self,
    62               style=wx.gizmos.EL_ALLOW_NEW|
    78               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
    63                     wx.gizmos.EL_ALLOW_EDIT|
    79 
    64                     wx.gizmos.EL_ALLOW_DELETE)
    80         self.BaseType = wx.ComboBox(id=ID_ARRAYTYPEDIALOGBASETYPE, 
    65         for func in ["_OnLabelEndEdit", 
    81               name='BaseType', parent=self, pos=wx.Point(0, 0),
    66                      "_OnAddButton", 
    82               size=wx.Size(0, 28), style=wx.CB_READONLY)
    67                      "_OnDelButton", 
       
    68                      "_OnUpButton", 
       
    69                      "_OnDownButton"]:
       
    70             setattr(self.Dimensions, func, self.OnDimensionsChanged)
       
    71         main_sizer.AddSizer(self.Dimensions, border=20, 
       
    72               flag=wx.GROW|wx.LEFT|wx.RIGHT)
    83         
    73         
    84         self.Dimensions = CustomEditableListBox(id=ID_ARRAYTYPEDIALOGDIMENSIONS, 
    74         button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
    85               name='ArrayDimensions', parent=self, label=_("Dimensions:"), pos=wx.Point(0, 0),
    75         self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
    86               size=wx.Size(0, 24), style=wx.gizmos.EL_ALLOW_NEW | wx.gizmos.EL_ALLOW_EDIT | wx.gizmos.EL_ALLOW_DELETE)
    76         main_sizer.AddSizer(button_sizer, border=20, 
    87         for func in ["_OnLabelEndEdit", "_OnAddButton", "_OnDelButton", "_OnUpButton", "_OnDownButton"]:
    77               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
    88             setattr(self.Dimensions, func, self.OnDimensionsChanged)
       
    89         
    78         
    90         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
    79         self.SetSizer(main_sizer)
    91         if wx.VERSION >= (2, 5, 0):
       
    92             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
       
    93         else:
       
    94             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
       
    95         
       
    96         self._init_sizers()
       
    97 
       
    98     def __init__(self, parent, datatypes, infos):
       
    99         self._init_ctrls(parent)
       
   100         
    80         
   101         for datatype in datatypes:
    81         for datatype in datatypes:
   102             self.BaseType.Append(datatype)
    82             self.BaseType.Append(datatype)
   103         
    83         
   104         if isinstance(infos, TupleType) and infos[0] == "array":
    84         if isinstance(infos, TupleType) and infos[0] == "array":