def __init__(self, parent, shape, title=_("Data properties")): self.parent = parent self.shape = shape label, etype = self._getLabel() self.etype = etype SimpleDialog.__init__(self, parent, title) self.element = Select( parent=self.panel, type=self.shape.GetPrompt(), validator=SimpleValidator( callback=self.ValidatorCallback)) if shape.GetValue(): self.element.SetValue(shape.GetValue()) self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK) self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel) if self.etype: self.typeSelect = ElementSelect( parent=self.panel, elements=[ 'raster', 'raster_3d', 'vector'], size=globalvar.DIALOG_GSELECT_SIZE) self.typeSelect.Bind(wx.EVT_CHOICE, self.OnType) self.typeSelect.SetSelection(0) self.element.SetType('raster') if shape.GetValue(): self.btnOK.Enable() self._layout() self.SetMinSize(self.GetSize())
class ModelDataDialog(SimpleDialog): """Data item properties dialog""" def __init__(self, parent, shape, title=_("Data properties")): self.parent = parent self.shape = shape label, etype = self._getLabel() self.etype = etype SimpleDialog.__init__(self, parent, title) self.element = Select( parent=self.panel, type=self.shape.GetPrompt(), validator=SimpleValidator( callback=self.ValidatorCallback)) if shape.GetValue(): self.element.SetValue(shape.GetValue()) self.Bind(wx.EVT_BUTTON, self.OnOK, self.btnOK) self.Bind(wx.EVT_BUTTON, self.OnCancel, self.btnCancel) if self.etype: self.typeSelect = ElementSelect( parent=self.panel, elements=[ 'raster', 'raster_3d', 'vector'], size=globalvar.DIALOG_GSELECT_SIZE) self.typeSelect.Bind(wx.EVT_CHOICE, self.OnType) self.typeSelect.SetSelection(0) self.element.SetType('raster') if shape.GetValue(): self.btnOK.Enable() self._layout() self.SetMinSize(self.GetSize()) def _getLabel(self): etype = False prompt = self.shape.GetPrompt() if prompt == 'raster': label = _('Name of raster map:') elif prompt == 'vector': label = _('Name of vector map:') else: etype = True label = _('Name of element:') return label, etype def _layout(self): """Do layout""" if self.etype: self.dataSizer.Add( StaticText( parent=self.panel, id=wx.ID_ANY, label=_("Type of element:")), proportion=0, flag=wx.ALL, border=1) self.dataSizer.Add(self.typeSelect, proportion=0, flag=wx.ALL, border=1) self.dataSizer.Add(StaticText(parent=self.panel, id=wx.ID_ANY, label=_("Name of element:")), proportion=0, flag=wx.ALL, border=1) self.dataSizer.Add(self.element, proportion=0, flag=wx.EXPAND | wx.ALL, border=1) self.panel.SetSizer(self.sizer) self.sizer.Fit(self) def GetType(self): """Get element type""" if not self.etype: return return self.element.tcp.GetType() def OnType(self, event): """Select element type""" evalue = self.typeSelect.GetValue(event.GetString()) self.element.SetType(evalue) def OnOK(self, event): """Ok pressed""" self.shape.SetValue(self.element.GetValue()) if self.etype: elem = self.GetType() if elem == 'raster': self.shape.SetPrompt('raster') elif elem == 'vector': self.shape.SetPrompt('vector') elif elem == 'raster_3d': self.shape.SetPrompt('raster_3d') self.parent.canvas.Refresh() self.parent.SetStatusText('', 0) self.shape.SetPropDialog(None) if self.IsModal(): event.Skip() else: self.Destroy() def OnCancel(self, event): """Cancel pressed""" self.shape.SetPropDialog(None) if self.IsModal(): event.Skip() else: self.Destroy()