Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functions.py19
-rw-r--r--mathlib.py5
-rw-r--r--toolbars.py14
3 files changed, 26 insertions, 12 deletions
diff --git a/functions.py b/functions.py
index ddc1088..c777af3 100644
--- a/functions.py
+++ b/functions.py
@@ -86,12 +86,22 @@ def _d(val):
else:
return None
-_angle_scaling = 1
+class ClassValue():
+ """
+ Class to share a value with the outside world.
+ This is required because plain floats / integers are not asigned by
+ reference, and can therefore not easily be changed in a different place.
+ """
+ def __init__(self, val):
+ self.value = val
+
+angle_scaling = ClassValue(1.0)
+
def _scale_angle(x):
- return x * _angle_scaling
+ return x * angle_scaling.value
def _inv_scale_angle(x):
- return x / _angle_scaling
+ return x / angle_scaling.value
def abs(x):
return math.fabs(x)
@@ -289,6 +299,9 @@ def mod(x, y):
return x % y
else:
raise ValueError(_('Can only calculate x modulo <integer>'))
+mod.__doc__ = _(
+'mod(x, y), return the modulus of x with respect to y. This is the remainder \
+after dividing x by y.')
def mul(x, y):
if isinstance(x, _Decimal) or isinstance(y, _Decimal):
diff --git a/mathlib.py b/mathlib.py
index 610bb07..c1ae273 100644
--- a/mathlib.py
+++ b/mathlib.py
@@ -40,7 +40,6 @@ class MathLib:
FORMAT_SCIENTIFIC = 2
def __init__(self):
- self.set_angle_type(self.ANGLE_DEG)
self.set_format_type(self.FORMAT_SCIENTIFIC)
self.set_digit_limit(9)
@@ -69,10 +68,6 @@ class MathLib:
if len(self.div_sym) == 0 or len(self.div_sym) > 3:
self.div_sym = '/'
- def set_angle_type(self, type):
- self.angle_scaling = self.d(type)
- _logger.debug('Angle type set to %s', self.angle_scaling)
-
def set_format_type(self, fmt, digit_limit=9):
self.format_type = fmt
_logger.debug('Format type set to %s', fmt)
diff --git a/toolbars.py b/toolbars.py
index 69cc940..221dbd7 100644
--- a/toolbars.py
+++ b/toolbars.py
@@ -290,6 +290,7 @@ class MiscToolbar(gtk.Toolbar):
target_toolbar.insert(IconToggleToolButton(el,
lambda x: self.update_angle_type(x, calc),
_('Degrees / radians')), -1)
+ self.update_angle_type('deg', calc)
el = [
{'icon': 'format-sci', 'html': 'sci'},
@@ -312,17 +313,22 @@ class MiscToolbar(gtk.Toolbar):
self.show_all()
def update_angle_type(self, text, calc):
+ var = calc.parser.get_var('angle_scaling')
+ if var is None:
+ _logger.warning('Variable angle_scaling not defined.')
+ return
+
if text == 'deg':
- calc.ml.set_angle_type(MathLib.ANGLE_DEG)
+ var.value = MathLib.ANGLE_DEG
elif text == 'rad':
- calc.ml.set_angle_type(MathLib.ANGLE_RAD)
- _logger.debug('Angle type: %s', calc.ml.angle_scaling)
+ var.value = MathLib.ANGLE_RAD
+ _logger.debug('Angle scaling: %s', var.value)
def update_format_type(self, text, calc):
if text == 'exp':
calc.ml.set_format_type(MathLib.FORMAT_EXPONENT)
elif text == 'sci':
- calc.ml.set_angle_type(MathLib.FORMAT_SCIENTIFIC)
+ calc.ml.set_format_type(MathLib.FORMAT_SCIENTIFIC)
_logger.debug('Format type: %s', calc.ml.format_type)
def update_digits(self, text, calc):