def execute(self, parent, result): if result == 'Apply': try: v_name = self.name.get() expression = self.expression.get() if not __main__.__dict__.has_key('MV'): exec "from cdms2 import MV" in __main__.__dict__ __main__.__dict__[v_name] = eval(expression, __main__.__dict__) if type(__main__.__dict__[v_name]) in [ types.IntType, types.FloatType ]: __main__.__dict__[v_name] = cdms.asVariable( __main__.__dict__[v_name]) __main__.__dict__[v_name].id = __main__.__dict__[ v_name].name = v_name gui_defined_variables.update_defined() gui_control.record_command(parent, "\n# Record the expression", 1) gui_control.record_command(parent, "%s = %s" % (v_name, expression), 1) except: gui_message.error( "Bad expression! Check expression and try again.") elif result == 'Clear': self.expression.clear() self.fself.doing_calculation_type = '' self.fself.saved_expression = '' self.fself.build_expression = 'no' else: self.dialog.destroy() self.fself.gui_expression = None
def execute(self, parent, result): if result == 'Apply': try: v_name = self.name.get() expression = self.expression.get() if not __main__.__dict__.has_key('MV'): exec "from cdms2 import MV" in __main__.__dict__ __main__.__dict__[v_name] = eval( expression, __main__.__dict__ ) if type(__main__.__dict__[v_name]) in [types.IntType,types.FloatType]: __main__.__dict__[v_name] = cdms.asVariable(__main__.__dict__[v_name]) __main__.__dict__[v_name].id = __main__.__dict__[v_name].name = v_name gui_defined_variables.update_defined( ) gui_control.record_command(parent, "\n# Record the expression", 1 ) gui_control.record_command(parent, "%s = %s" % (v_name, expression), 1 ) except: gui_message.error("Bad expression! Check expression and try again.") elif result == 'Clear': self.expression.clear() self.fself.doing_calculation_type = '' self.fself.saved_expression = '' self.fself.build_expression = 'no' else: self.dialog.destroy() self.fself.gui_expression = None