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