Initial checkin
[ejpi] / src / plugins / computer.py
1 from __future__ import division
2
3 import os
4 import operator
5 import math
6
7 import operation
8
9 import sys
10 sys.path.append("../")
11 import plugin_utils
12
13
14 _MAP_FILE_PATH = os.path.join(os.path.dirname(__file__), "computer.map")
15 PLUGIN = plugin_utils.PieKeyboardPluginFactory("Computer", _MAP_FILE_PATH)
16
17 hex = operation.change_base(16, "hex")
18 oct = operation.change_base(8, "oct")
19 dec = operation.change_base(10, "dec")
20 ceil = operation.generate_function(math.ceil, "ceil", operation.Function.REP_FUNCTION, 1)
21 floor = operation.generate_function(math.floor, "floor", operation.Function.REP_FUNCTION, 1)
22
23 PLUGIN.register_operation("hex", hex)
24 PLUGIN.register_operation("oct", oct)
25 PLUGIN.register_operation("dec", dec)
26 PLUGIN.register_operation("ceil", ceil)
27 PLUGIN.register_operation("floor", floor)
28
29 floorDivision = operation.generate_function(operator.floordiv, "//", operation.Function.REP_INFIX, 2)
30 modulo = operation.generate_function(operator.mod, "%", operation.Function.REP_INFIX, 2)
31
32 PLUGIN.register_operation("//", floorDivision)
33 PLUGIN.register_operation("%", modulo)
34
35 bitAnd = operation.generate_function(operator.and_, "&", operation.Function.REP_INFIX, 2)
36 bitOr = operation.generate_function(operator.or_, "|", operation.Function.REP_INFIX, 2)
37 bitXor = operation.generate_function(operator.xor, "^", operation.Function.REP_INFIX, 2)
38 bitInvert = operation.generate_function(operator.invert, "~", operation.Function.REP_PREFIX, 1)
39
40 PLUGIN.register_operation("&", bitAnd)
41 PLUGIN.register_operation("|", bitOr)
42 PLUGIN.register_operation("^", bitXor)
43 PLUGIN.register_operation("~", bitInvert)