1
#! /usr/bin/env python3
2
# -*- coding: utf-8 -*-
4
# Copyright 2011, Cas Widdershoven
5
# Copyright 2009-2013, Marten de Vries
7
# This file is part of OpenTeacher.
9
# OpenTeacher is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# OpenTeacher is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
22
class ECTSNoteCalculatorModule:
23
def __init__(self, moduleManager, *args, **kwargs):
24
super().__init__(*args, **kwargs)
25
self._mm = moduleManager
27
self.type = "noteCalculator"
29
self._mm.mods("javaScriptImplementation", type="percentsCalculator"),
30
self._mm.mods("javaScriptImplementation", type="bisectfunc"),
31
self._mm.mods(type="javaScriptEvaluator"),
34
self._mm.mods(type="translator"),
36
self.filesWithTranslations = ("ects.py",)
37
self.javaScriptImplementation = True
43
calculateNote = property(lambda self: self._js.global_.calculateNote)
44
calculateAverageNote = property(lambda self: self._js.global_.calculateAverageNote)
47
self._modules = next(iter(self._mm.mods(type="modules")))
48
self.code = self._modules.default(
50
"javaScriptImplementation",
51
type="percentsCalculator"
53
self.code += self._modules.default(
55
"javaScriptImplementation",
58
with open(self._mm.resourcePath("ects.js"), encoding='UTF-8') as f:
61
self._js = self._modules.default("active", type="javaScriptEvaluator").createEvaluator()
62
self._js.eval(self.code)
64
#Connect to the languageChanged event so retranslating is done.
66
translator = self._modules.default("active", type="translator")
70
translator.languageChanged.handle(self._retranslate)
75
def _retranslate(self):
78
translator = self._modules.default("active", type="translator")
80
_, ngettext = str, lambda a, b, n: a if n == 1 else b
82
_, ngettext = translator.gettextFunctions(
83
self._mm.resourcePath("translations")
94
def init(moduleManager):
95
return ECTSNoteCalculatorModule(moduleManager)