[kupfer: 3/18] calculator: add missing operators (&|~); update description and manual



commit efe6b255cf57f2c39d50df9999a9887395f6d8e7
Author: Karol BÄdkowski <karol bedkowski gmail com>
Date:   Sat Jun 9 11:36:21 2012 +0200

    calculator: add missing operators (&|~); update description and manual

 help/C/plugin-calculator.page |    4 ++++
 kupfer/plugin/calculator.py   |   16 ++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/help/C/plugin-calculator.page b/help/C/plugin-calculator.page
index fd67c56..78f5e89 100644
--- a/help/C/plugin-calculator.page
+++ b/help/C/plugin-calculator.page
@@ -62,6 +62,10 @@
       </p>
      </item>
      </list>
+     <p>
+       The Calculator lets you also calculate expression without "=" on the 
+       beginning as long it have inside one of operators: +, -, *, /, ^, |, &, ~.
+     </p>
    </section>
   
 </page>
diff --git a/kupfer/plugin/calculator.py b/kupfer/plugin/calculator.py
index 2e8c00e..3de7e22 100644
--- a/kupfer/plugin/calculator.py
+++ b/kupfer/plugin/calculator.py
@@ -1,9 +1,8 @@
 from __future__ import division
 __kupfer_name__ = _("Calculator")
 __kupfer_actions__ = ("Calculate", )
-__description__ = _("Calculate expressions starting with '=', or " \
-"containing mathematical operators")
-__version__ = ""
+__description__ = _("Calculate mathematical expressions")
+__version__ = "2012-06-09"
 __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 
 
@@ -17,6 +16,7 @@ from kupfer import pretty
 class IgnoreResultException (Exception):
 	pass
 
+
 class KupferSurprise (float):
 	"""kupfer
 
@@ -27,10 +27,12 @@ class KupferSurprise (float):
 		utils.show_url(version.WEBSITE)
 		raise IgnoreResultException
 
+
 class DummyResult (object):
 	def __unicode__(self):
 		return u"<Result of last expression>"
 
+
 class Help (object):
 	"""help()
 
@@ -73,6 +75,7 @@ class Help (object):
 	def __complex__(self):
 		return self()
 
+
 def make_environment(last_result=None):
 	"Return a namespace for the calculator's expressions to be executed in."
 	environment = dict(vars(math))
@@ -86,6 +89,7 @@ def make_environment(last_result=None):
 	environment["__builtins__"] = {}
 	return environment
 
+
 def format_result(res):
 	cres = complex(res)
 	parts = []
@@ -95,6 +99,7 @@ def format_result(res):
 		parts.append(u"%s" % complex(0, cres.imag))
 	return u"+".join(parts) or u"%s" % res
 
+
 class Calculate (Action):
 	# since it applies only to special queries, we can up the rank
 	rank_adjust = 10
@@ -134,7 +139,10 @@ class Calculate (Action):
 				"-" in text or
 				"*" in text or
 				"/" in text or
-				"^" in text)
+				"^" in text or
+				"&" in text or
+				"|" in text or
+				"~" in text)
 
 	def get_description(self):
 		return None



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]