summaryrefslogtreecommitdiff
path: root/examples/environment.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2017-08-28 16:47:57 -0600
committerkotfu <kotfu@kotfu.net>2017-08-28 16:47:57 -0600
commit6d331a51f407418b4ebddcf984e52eb2ad73fe65 (patch)
treeabf94585628039db9601356b49b1724e749308f7 /examples/environment.py
parentc2418a993243f79ee89334e92802aac954265ac7 (diff)
downloadcmd2-git-6d331a51f407418b4ebddcf984e52eb2ad73fe65.tar.gz
Revise environment setting documentation
Diffstat (limited to 'examples/environment.py')
-rwxr-xr-xexamples/environment.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/environment.py b/examples/environment.py
new file mode 100755
index 00000000..ca39711e
--- /dev/null
+++ b/examples/environment.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+# coding=utf-8
+"""
+A sample application for cmd2 demonstrating customized environment parameters
+"""
+
+from cmd2 import Cmd
+
+
+class EnvironmentApp(Cmd):
+ """ Example cmd2 application. """
+
+ degrees_c = 22
+ sunny = False
+
+ def __init__(self):
+ self.settable.update({'degrees_c': 'Temperature in Celsius'})
+ self.settable.update({'sunny': 'Is it sunny outside?'})
+ Cmd.__init__(self)
+
+ def do_sunbathe(self, arg):
+ if self.degrees_c < 20:
+ result = "It's {} C - are you a penguin?".format(self.degrees_c)
+ elif not self.sunny:
+ result = 'Too dim.'
+ else:
+ result = 'UV is bad for your skin.'
+ self.poutput(result)
+
+ def _onchange_degrees_c(self, old, new):
+ # if it's over 40C, it's gotta be sunny, right?
+ if new > 40:
+ self.sunny = True
+
+
+if __name__ == '__main__':
+ c = EnvironmentApp()
+ c.cmdloop()