First pass at packaging for Harmattan
[ejpi] / ejpi / plugins / computer.py
1 from __future__ import division
2
3 import os
4 import operator
5 import math
6
7 from ejpi import operation
8 from ejpi import plugin_utils
9
10
11 _NAME = "Computer"
12 _ICON = "computer.png"
13 _MAP = {
14         "name": _NAME,
15         "keys": {
16                 (0, 0): {
17                         "CENTER": {"action": "7", "type": "text", "text": "7", },
18                         "SOUTH": {"action": "d", "type": "text", "text": "D", },
19                         "showAllSlices": False,
20                 },
21                 (0, 1): {
22                         "CENTER": {"action": "8", "type": "text", "text": "8", },
23                         "SOUTH": {"action": "e", "type": "text", "text": "E", },
24                         "showAllSlices": False,
25                 },
26                 (0, 2): {
27                         "CENTER": {"action": "9", "type": "text", "text": "9", },
28                         "SOUTH": {"action": "f", "type": "text", "text": "F", },
29                         "showAllSlices": False,
30                 },
31                 (1, 0): {
32                         "CENTER": {"action": "4", "type": "text", "text": "4", },
33                         "NORTH_EAST": {"action": "0o", "type": "text", "text": "0o", },
34                         "EAST": {"action": "0x", "type": "text", "text": "0x", },
35                         "SOUTH_EAST": {"action": "0b", "type": "text", "text": "0b", },
36                         "showAllSlices": True,
37                 },
38                 (1, 1): {
39                         "CENTER": {"action": "5", "type": "text", "text": "5", },
40                         "NORTH": {"action": "[&]", "type": "text", "text": "and", },
41                         "WEST": {"action": "[|]", "type": "text", "text": "or", },
42                         "SOUTH": {"action": "[~]", "type": "text", "text": "not", },
43                         "EAST": {"action": "[^]", "type": "text", "text": "xor", },
44                         "showAllSlices": True,
45                 },
46                 (1, 2): {
47                         "CENTER": {"action": "6", "type": "text", "text": "6", },
48                         "NORTH_WEST": {"action": "[oct]", "type": "text", "text": "-> oct", },
49                         "WEST": {"action": "[dec]", "type": "text", "text": "-> dec", },
50                         "SOUTH_WEST": {"action": "[hex]", "type": "text", "text": "-> hex", },
51                         "showAllSlices": True,
52                 },
53                 (2, 0): {
54                         "CENTER": {"action": "1", "type": "text", "text": "1", },
55                         "NORTH": {"action": "a", "type": "text", "text": "A", },
56                         "EAST": {"action": "0", "type": "text", "text": "0", },
57                         "showAllSlices": False,
58                 },
59                 (2, 1): {
60                         "CENTER": {"action": "2", "type": "text", "text": "2", },
61                         "NORTH": {"action": "b", "type": "text", "text": "B", },
62                         "EAST": {"action": "[//]", "type": "text", "text": "x // y", },
63                         "WEST": {"action": "[%]", "type": "text", "text": "x % y", },
64                         "showAllSlices": False,
65                 },
66                 (2, 2): {
67                         "CENTER": {"action": "3", "type": "text", "text": "3", },
68                         "NORTH": {"action": "c", "type": "text", "text": "C", },
69                         "showAllSlices": False,
70                 },
71         },
72 }
73 _ICON_PATH = [os.path.join(os.path.dirname(__file__), "images")]
74 PLUGIN = plugin_utils.PieKeyboardPluginFactory(_NAME, _ICON, _MAP, _ICON_PATH)
75
76 hex = operation.change_base(16, "hex")
77 oct = operation.change_base(8, "oct")
78 dec = operation.change_base(10, "dec")
79 ceil = operation.generate_function(math.ceil, "ceil", operation.Function.REP_FUNCTION, 1)
80 floor = operation.generate_function(math.floor, "floor", operation.Function.REP_FUNCTION, 1)
81
82 PLUGIN.register_operation("hex", hex)
83 PLUGIN.register_operation("oct", oct)
84 PLUGIN.register_operation("dec", dec)
85 PLUGIN.register_operation("ceil", ceil)
86 PLUGIN.register_operation("floor", floor)
87
88 floorDivision = operation.generate_function(operator.floordiv, "//", operation.Function.REP_INFIX, 2)
89 modulo = operation.generate_function(operator.mod, "%", operation.Function.REP_INFIX, 2)
90
91 PLUGIN.register_operation("//", floorDivision)
92 PLUGIN.register_operation("%", modulo)
93
94 bitAnd = operation.generate_function(operator.and_, "&", operation.Function.REP_INFIX, 2)
95 bitOr = operation.generate_function(operator.or_, "|", operation.Function.REP_INFIX, 2)
96 bitXor = operation.generate_function(operator.xor, "^", operation.Function.REP_INFIX, 2)
97 bitInvert = operation.generate_function(operator.invert, "~", operation.Function.REP_PREFIX, 1)
98
99 PLUGIN.register_operation("&", bitAnd)
100 PLUGIN.register_operation("|", bitOr)
101 PLUGIN.register_operation("^", bitXor)
102 PLUGIN.register_operation("~", bitInvert)