summaryrefslogtreecommitdiff
path: root/examples/environment.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2020-02-06 18:20:50 -0500
committerGitHub <noreply@github.com>2020-02-06 18:20:50 -0500
commitc7ac2e965d025806ce5baddfc718814e3e58d639 (patch)
tree6e046c2445edf62b024a9389dc719865584dc9cf /examples/environment.py
parent60a212c1c585f0c4c06ffcfeb9882520af8dbf35 (diff)
parentc4893ea8a132c06bc71b0ddd63801604e6f85177 (diff)
downloadcmd2-git-c7ac2e965d025806ce5baddfc718814e3e58d639.tar.gz
Merge pull request #873 from python-cmd2/set_update
Updated set command to support tab completion of values
Diffstat (limited to 'examples/environment.py')
-rwxr-xr-xexamples/environment.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/examples/environment.py b/examples/environment.py
index 9e611f08..670b63ac 100755
--- a/examples/environment.py
+++ b/examples/environment.py
@@ -9,15 +9,19 @@ import cmd2
class EnvironmentApp(cmd2.Cmd):
""" Example cmd2 application. """
- degrees_c = 22
- sunny = False
-
def __init__(self):
super().__init__()
- self.settable.update({'degrees_c': 'Temperature in Celsius'})
- self.settable.update({'sunny': 'Is it sunny outside?'})
+ self.degrees_c = 22
+ self.sunny = False
+ self.add_settable(cmd2.Settable('degrees_c',
+ int,
+ 'Temperature in Celsius',
+ onchange_cb=self._onchange_degrees_c
+ ))
+ self.add_settable(cmd2.Settable('sunny', bool, 'Is it sunny outside?'))
def do_sunbathe(self, arg):
+ """Attempt to sunbathe."""
if self.degrees_c < 20:
result = "It's {} C - are you a penguin?".format(self.degrees_c)
elif not self.sunny:
@@ -26,7 +30,7 @@ class EnvironmentApp(cmd2.Cmd):
result = 'UV is bad for your skin.'
self.poutput(result)
- def _onchange_degrees_c(self, old, new):
+ def _onchange_degrees_c(self, param_name, old, new):
# if it's over 40C, it's gotta be sunny, right?
if new > 40:
self.sunny = True