1 from __future__ import division
10 sys.path.append("../")
14 _ICON = "builtins.png"
19 "CENTER": {"action": "7", "type": "text", "text": "7", },
20 "showAllSlices": True,
23 "CENTER": {"action": "8", "type": "text", "text": "8", },
24 "SOUTH": {"action": "[**]", "type": "text", "text": "x ** y", },
25 "EAST": {"action": "[sq]", "type": "text", "text": "x ** 2", },
26 "WEST": {"action": "[sqrt]", "type": "text", "text": "sqrt", },
27 "showAllSlices": False,
30 "CENTER": {"action": "9", "type": "text", "text": "9", },
31 "showAllSlices": True,
34 "CENTER": {"action": "4", "type": "text", "text": "4", },
35 "showAllSlices": True,
38 "CENTER": {"action": "5", "type": "text", "text": "5", },
39 "EAST": {"action": "[+]", "type": "text", "text": "+", },
40 "WEST": {"action": "[-]", "type": "text", "text": "-", },
41 "NORTH": {"action": "[*]", "type": "text", "text": "*", },
42 "SOUTH": {"action": "[/]", "type": "text", "text": "/", },
43 "showAllSlices": True,
46 "CENTER": {"action": "6", "type": "text", "text": "6", },
47 "showAllSlices": True,
50 "CENTER": {"action": "1", "type": "text", "text": "1", },
51 "NORTH": {"action": ".", "type": "text", "text": ".", },
52 "EAST": {"action": "0", "type": "text", "text": "0", },
53 "showAllSlices": True,
56 "CENTER": {"action": "2", "type": "text", "text": "2", },
57 "EAST": {"action": "[abs]", "type": "text", "text": "abs", },
58 "WEST": {"action": "[+-]", "type": "text", "text": "+/-", },
59 "showAllSlices": True,
62 "CENTER": {"action": "3", "type": "text", "text": "3", },
63 "NORTH": {"action": "[!]", "type": "text", "text": "x !", },
64 "WEST": {"action": "j", "type": "text", "text": "j", },
65 "showAllSlices": True,
69 _ICON_PATH = [os.path.join(os.path.dirname(__file__), "images")]
70 PLUGIN = plugin_utils.PieKeyboardPluginFactory(_NAME, _ICON, _MAP, _ICON_PATH)
72 addition = operation.generate_function(operator.add, "+", operation.Function.REP_INFIX, 2)
73 subtraction = operation.generate_function(operator.sub, "-", operation.Function.REP_INFIX, 2)
74 multiplication = operation.generate_function(operator.mul, "*", operation.Function.REP_INFIX, 2)
75 trueDivision = operation.generate_function(operator.truediv, "/", operation.Function.REP_INFIX, 2)
77 PLUGIN.register_operation("+", addition)
78 PLUGIN.register_operation("-", subtraction)
79 PLUGIN.register_operation("*", multiplication)
80 PLUGIN.register_operation("/", trueDivision)
82 exponentiation = operation.generate_function(operator.pow, "**", operation.Function.REP_INFIX, 2)
83 abs = operation.generate_function(operator.abs, "abs", operation.Function.REP_FUNCTION, 1)
85 fact_func = math.factorial
86 except AttributeError:
87 def fact_func(self, num):
90 return num * fact_func(self, num - 1)
91 factorial = operation.generate_function(fact_func, "!", operation.Function.REP_POSTFIX, 1)
92 negate = operation.generate_function(operator.neg, "+-", operation.Function.REP_PREFIX, 1)
93 square = operation.generate_function((lambda self, x: x ** 2), "sq", operation.Function.REP_FUNCTION, 1)
94 square_root = operation.generate_function((lambda self, x: x ** 0.5), "sqrt", operation.Function.REP_FUNCTION, 1)
96 # @todo Possibly make a graphic for this of x^y
97 PLUGIN.register_operation("**", exponentiation)
98 PLUGIN.register_operation("abs", abs)
99 PLUGIN.register_operation("!", factorial)
100 PLUGIN.register_operation("+-", negate)
101 PLUGIN.register_operation("sq", square)
102 PLUGIN.register_operation("sqrt", square_root)