def __init__(self, parent=None): SpatialLag_xrc.xrcSpLagVariable.__init__(self, parent) self.model = M_spLagVariable() self.model.addListener(self.populate) d = {} d['var'] = self.__var d['vars'] = self.__var d['newVarName'] = self.__newVarName d['caution'] = self.__caution self.dispatch = d self.varsChoice.Bind(wx.EVT_CHOICE, self.__var) # AppendItems(self.model.get('vars')) self.newVarNameCtrl.Bind(wx.EVT_TEXT, self.__newVarName) # SetValue(newVarName)
def __init__(self, parent=None): SpatialLag_xrc.xrcSpLagVariable.__init__(self, parent) self.model = M_spLagVariable() self.model.addListener(self.populate) d = {} d['var'] = self.__var d['vars'] = self.__var d['newVarName'] = self.__newVarName d['caution'] = self.__caution self.dispatch = d self.varsChoice.Bind( wx.EVT_CHOICE, self.__var) # AppendItems(self.model.get('vars')) self.newVarNameCtrl.Bind( wx.EVT_TEXT, self.__newVarName) # SetValue(newVarName)
class C_spLagVariable(SpatialLag_xrc.xrcSpLagVariable): """ Control for an XRC panel that contains, [textCtrl] = W*[dropDown] """ def __init__(self, parent=None): SpatialLag_xrc.xrcSpLagVariable.__init__(self, parent) self.model = M_spLagVariable() self.model.addListener(self.populate) d = {} d['var'] = self.__var d['vars'] = self.__var d['newVarName'] = self.__newVarName d['caution'] = self.__caution self.dispatch = d self.varsChoice.Bind(wx.EVT_CHOICE, self.__var) # AppendItems(self.model.get('vars')) self.newVarNameCtrl.Bind(wx.EVT_TEXT, self.__newVarName) # SetValue(newVarName) # self.warn.Bind(wx.EVT_MOTION,self.info) # def info(self,evt): # print evt # print self.warn # print dir(self.warn) def populate(self, model): data = self.model.get() for key in self.model.DATA_KEYS_ORDER: v = data[key] if key in self.dispatch: self.dispatch[key](value=v) else: print "Warning: %s, has not been implemented" % key self.able() def able(self): if self.model.get('var') == -1: self.newVarNameCtrl.Disable() else: self.newVarNameCtrl.Enable() def __var(self, evt=None, value=None): # print "__var...EVT: ",evt,"Value:",value if evt is not None: # evt fired old_value = self.model.get('var') value = self.varsChoice.GetSelection() self.model.set('var', value) if not old_value == value: self.__newVarName(value=value) elif value is not None: # model changed if type(value) == int: old_value = self.varsChoice.GetSelection() self.varsChoice.SetSelection(value) if value != -1 and old_value != value: self.__newVarName(value=value) # self.model.set('newVarName', self.model.get('vars') # [self.model.get('var')]) else: # assume list if self.model.varsChanged: self.varsChoice.Clear() if '' in value: value.remove('') self.varsChoice.AppendItems(value) self.model.varsChanged = False def __newVarName(self, evt=None, value=None): # print "__newVarName...EVT: ",evt,"Value:",value if evt is not None: # pass if self.newVarNameCtrl.GetValue() != self.model.get('newVarName'): self.model.set('newVarName', self.newVarNameCtrl.GetValue()) elif value is not None: if type(value) == int: # change from __var # print self.model.get('var') # print self.model.get('vars') varName = self.model.get('vars')[self.model.get('var')] newVarName = 'W_' + varName self.model.set('newVarName', newVarName, passive=False) else: # assume string self.warn.Show() # self.good.Show() self.newVarNameCtrl.SetValue(value) def __caution(self, evt=None, value=None): if value is not None: if self.model.get('newVarName') in self.model.get('vars'): self.warn.SetToolTipString( "This variable already exists, and will be overwritten!") self.warn.Show() self.model.set('caution', True, True) elif len(self.model.get('newVarName')) < 1 and \ self.newVarNameCtrl.IsEnabled(): self.warn.SetToolTipString( "Please enter a variable name, or leave empty to exclude\ this variable.") self.warn.Show() self.model.set('caution', True, True) elif self.model.newVars.count(self.model.get('newVarName')) > 1: self.warn.SetToolTipString( "You are creating another new variable with this name,\ please change one of them!") self.warn.Show() self.model.set('caution', True, True) elif len(self.model.get('newVarName')) > 10: self.warn.SetToolTipString( "This variable name is too long. Truncated to 10 chars.") self.warn.Show() self.model.set('caution', True, True) else: self.warn.Hide() self.model.set('caution', False, True)
class C_spLagVariable(SpatialLag_xrc.xrcSpLagVariable): """ Control for an XRC panel that contains, [textCtrl] = W*[dropDown] """ def __init__(self, parent=None): SpatialLag_xrc.xrcSpLagVariable.__init__(self, parent) self.model = M_spLagVariable() self.model.addListener(self.populate) d = {} d['var'] = self.__var d['vars'] = self.__var d['newVarName'] = self.__newVarName d['caution'] = self.__caution self.dispatch = d self.varsChoice.Bind( wx.EVT_CHOICE, self.__var) # AppendItems(self.model.get('vars')) self.newVarNameCtrl.Bind( wx.EVT_TEXT, self.__newVarName) # SetValue(newVarName) # self.warn.Bind(wx.EVT_MOTION,self.info) # def info(self,evt): # print evt # print self.warn # print dir(self.warn) def populate(self, model): data = self.model.get() for key in self.model.DATA_KEYS_ORDER: v = data[key] if key in self.dispatch: self.dispatch[key](value=v) else: print "Warning: %s, has not been implemented" % key self.able() def able(self): if self.model.get('var') == -1: self.newVarNameCtrl.Disable() else: self.newVarNameCtrl.Enable() def __var(self, evt=None, value=None): # print "__var...EVT: ",evt,"Value:",value if evt is not None: # evt fired old_value = self.model.get('var') value = self.varsChoice.GetSelection() self.model.set('var', value) if not old_value == value: self.__newVarName(value=value) elif value is not None: # model changed if type(value) == int: old_value = self.varsChoice.GetSelection() self.varsChoice.SetSelection(value) if value != -1 and old_value != value: self.__newVarName(value=value) # self.model.set('newVarName', self.model.get('vars') # [self.model.get('var')]) else: # assume list if self.model.varsChanged: self.varsChoice.Clear() if '' in value: value.remove('') self.varsChoice.AppendItems(value) self.model.varsChanged = False def __newVarName(self, evt=None, value=None): # print "__newVarName...EVT: ",evt,"Value:",value if evt is not None: # pass if self.newVarNameCtrl.GetValue() != self.model.get('newVarName'): self.model.set('newVarName', self.newVarNameCtrl.GetValue()) elif value is not None: if type(value) == int: # change from __var # print self.model.get('var') # print self.model.get('vars') varName = self.model.get('vars')[self.model.get('var')] newVarName = 'W_' + varName self.model.set('newVarName', newVarName, passive=False) else: # assume string self.warn.Show() # self.good.Show() self.newVarNameCtrl.SetValue(value) def __caution(self, evt=None, value=None): if value is not None: if self.model.get('newVarName') in self.model.get('vars'): self.warn.SetToolTipString( "This variable already exists, and will be overwritten!") self.warn.Show() self.model.set('caution', True, True) elif len(self.model.get('newVarName')) < 1 and \ self.newVarNameCtrl.IsEnabled(): self.warn.SetToolTipString( "Please enter a variable name, or leave empty to exclude\ this variable.") self.warn.Show() self.model.set('caution', True, True) elif self.model.newVars.count(self.model.get('newVarName')) > 1: self.warn.SetToolTipString( "You are creating another new variable with this name,\ please change one of them!") self.warn.Show() self.model.set('caution', True, True) elif len(self.model.get('newVarName')) > 10: self.warn.SetToolTipString( "This variable name is too long. Truncated to 10 chars.") self.warn.Show() self.model.set('caution', True, True) else: self.warn.Hide() self.model.set('caution', False, True)