فهرست منبع

Added the possibility to use a function to create a hint message.

Taddeus Kroes 14 سال پیش
والد
کامیت
09820ea805
2فایلهای تغییر یافته به همراه16 افزوده شده و 2 حذف شده
  1. 6 1
      src/possibilities.py
  2. 10 1
      src/rules/lineq.py

+ 6 - 1
src/possibilities.py

@@ -16,7 +16,12 @@ class Possibility(object):
 
     def __str__(self):
         if self.handler in MESSAGES:
-            return MESSAGES[self.handler].format(self.root, *self.args)
+            msg = MESSAGES[self.handler]
+
+            if callable(msg):
+                msg = msg(self.root, self.args)
+
+            return msg.format(self.root, *self.args)
 
         return repr(self)
 

+ 10 - 1
src/rules/lineq.py

@@ -98,7 +98,16 @@ def subtract_term(root, args):
     return eq(left - term, right - term)
 
 
-MESSAGES[subtract_term] = _('Subtract {1} from both sides of the equation.')
+def subtract_term_msg(root, args):
+    term = args[0]
+
+    if term.negated == 1:
+        return _('Add %s to both sides of the equation.' % +term)
+
+    return _('Subtract {1} from both sides of the equation.')
+
+
+MESSAGES[subtract_term] = subtract_term_msg
 
 
 def divide_term(root, args):