1 from __future__ import division
7 from ejpi import operation
8 from ejpi import plugin_utils
12 _ICON = "builtins.png"
17 "CENTER": {"action": "7", "type": "text", "text": "7", },
18 "showAllSlices": True,
21 "CENTER": {"action": "8", "type": "text", "text": "8", },
22 "SOUTH": {"action": "[**]", "type": "text", "text": "x ** y", },
23 "EAST": {"action": "[sq]", "type": "text", "text": "x ** 2", },
24 "WEST": {"action": "[sqrt]", "type": "text", "text": "sqrt", },
25 "showAllSlices": False,
28 "CENTER": {"action": "9", "type": "text", "text": "9", },
29 "showAllSlices": True,
32 "CENTER": {"action": "4", "type": "text", "text": "4", },
33 "showAllSlices": True,
36 "CENTER": {"action": "5", "type": "text", "text": "5", },
37 "EAST": {"action": "[+]", "type": "text", "text": "+", },
38 "WEST": {"action": "[-]", "type": "text", "text": "-", },
39 "NORTH": {"action": "[*]", "type": "text", "text": "*", },
40 "SOUTH": {"action": "[/]", "type": "text", "text": "/", },
41 "showAllSlices": True,
44 "CENTER": {"action": "6", "type": "text", "text": "6", },
45 "showAllSlices": True,
48 "CENTER": {"action": "1", "type": "text", "text": "1", },
49 "NORTH": {"action": ".", "type": "text", "text": ".", },
50 "EAST": {"action": "0", "type": "text", "text": "0", },
51 "showAllSlices": True,
54 "CENTER": {"action": "2", "type": "text", "text": "2", },
55 "EAST": {"action": "[abs]", "type": "text", "text": "abs", },
56 "WEST": {"action": "[+-]", "type": "text", "text": "+/-", },
57 "showAllSlices": True,
60 "CENTER": {"action": "3", "type": "text", "text": "3", },
61 "NORTH": {"action": "[!]", "type": "text", "text": "x !", },
62 "WEST": {"action": "j", "type": "text", "text": "j", },
63 "showAllSlices": True,
67 _ICON_PATH = [os.path.join(os.path.dirname(__file__), "images")]
68 PLUGIN = plugin_utils.PieKeyboardPluginFactory(_NAME, _ICON, _MAP, _ICON_PATH)
70 addition = operation.generate_function(operator.add, "+", operation.Function.REP_INFIX, 2)
71 subtraction = operation.generate_function(operator.sub, "-", operation.Function.REP_INFIX, 2)
72 multiplication = operation.generate_function(operator.mul, "*", operation.Function.REP_INFIX, 2)
73 trueDivision = operation.generate_function(operator.truediv, "/", operation.Function.REP_INFIX, 2)
75 PLUGIN.register_operation("+", addition)
76 PLUGIN.register_operation("-", subtraction)
77 PLUGIN.register_operation("*", multiplication)
78 PLUGIN.register_operation("/", trueDivision)
80 exponentiation = operation.generate_function(operator.pow, "**", operation.Function.REP_INFIX, 2)
81 abs = operation.generate_function(operator.abs, "abs", operation.Function.REP_FUNCTION, 1)
83 fact_func = math.factorial
84 except AttributeError:
85 def fact_func(self, num):
88 return num * fact_func(self, num - 1)
89 factorial = operation.generate_function(fact_func, "!", operation.Function.REP_POSTFIX, 1)
90 negate = operation.generate_function(operator.neg, "+-", operation.Function.REP_PREFIX, 1)
91 square = operation.generate_function((lambda self, x: x ** 2), "sq", operation.Function.REP_FUNCTION, 1)
92 square_root = operation.generate_function((lambda self, x: x ** 0.5), "sqrt", operation.Function.REP_FUNCTION, 1)
94 # @todo Possibly make a graphic for this of x^y
95 PLUGIN.register_operation("**", exponentiation)
96 PLUGIN.register_operation("abs", abs)
97 PLUGIN.register_operation("!", factorial)
98 PLUGIN.register_operation("+-", negate)
99 PLUGIN.register_operation("sq", square)
100 PLUGIN.register_operation("sqrt", square_root)