changeset 212:9c4c4d012a92

parameter onchange hook
author catherine@Elli.myhome.westell.com
date Sat, 14 Mar 2009 20:03:57 -0400
parents 5da7d72e72ee
children 500955dece3f
files cmd2.py
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Thu Mar 12 07:58:32 2009 -0400
+++ b/cmd2.py	Sat Mar 14 20:03:57 2009 -0400
@@ -699,6 +699,12 @@
                     val = cast(currentVal, val)
                 setattr(self, paramName, val)
                 self.stdout.write('%s - was: %s\nnow: %s\n' % (paramName, currentVal, val))
+                if currentVal != val:
+                    try:
+                        onchange_hook = getattr(self, '_onchange_%s' % paramName)
+                        onchange_hook(old=currentVal, new=val)
+                    except AttributeError:
+                        pass
             else:
                 self.do_show(paramName)
         except (ValueError, AttributeError, NotSettableError), e: