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