Ejemplo n.º 1
0
import math

import operation

import sys
sys.path.append("../")
import plugin_utils


_MAP_FILE_PATH = os.path.join(os.path.dirname(__file__), "computer.map")
PLUGIN = plugin_utils.PieKeyboardPluginFactory("Computer", _MAP_FILE_PATH)

hex = operation.change_base(16, "hex")
oct = operation.change_base(8, "oct")
dec = operation.change_base(10, "dec")
ceil = operation.generate_function(math.ceil, "ceil", operation.Function.REP_FUNCTION, 1)
floor = operation.generate_function(math.floor, "floor", operation.Function.REP_FUNCTION, 1)

PLUGIN.register_operation("hex", hex)
PLUGIN.register_operation("oct", oct)
PLUGIN.register_operation("dec", dec)
PLUGIN.register_operation("ceil", ceil)
PLUGIN.register_operation("floor", floor)

floorDivision = operation.generate_function(operator.floordiv, "//", operation.Function.REP_INFIX, 2)
modulo = operation.generate_function(operator.mod, "%", operation.Function.REP_INFIX, 2)

PLUGIN.register_operation("//", floorDivision)
PLUGIN.register_operation("%", modulo)

bitAnd = operation.generate_function(operator.and_, "&", operation.Function.REP_INFIX, 2)
Ejemplo n.º 2
0
import os
import operator
import math

import operation

import sys
sys.path.append("../")
import plugin_utils


_MAP_FILE_PATH = os.path.join(os.path.dirname(__file__), "builtins.map")
PLUGIN = plugin_utils.PieKeyboardPluginFactory("Builtin", _MAP_FILE_PATH)

addition = operation.generate_function(operator.add, "+", operation.Function.REP_INFIX, 2)
subtraction = operation.generate_function(operator.sub, "-", operation.Function.REP_INFIX, 2)
multiplication = operation.generate_function(operator.mul, "*", operation.Function.REP_INFIX, 2)
trueDivision = operation.generate_function(operator.truediv, "/", operation.Function.REP_INFIX, 2)

PLUGIN.register_operation("+", addition)
PLUGIN.register_operation("-", subtraction)
PLUGIN.register_operation("*", multiplication)
PLUGIN.register_operation("/", trueDivision)

exponentiation = operation.generate_function(operator.pow, "**", operation.Function.REP_INFIX, 2)
abs = operation.generate_function(operator.abs, "abs", operation.Function.REP_FUNCTION, 1)
try:
	fact_func = math.factorial
except AttributeError:
	def fact_func(self, num):
Ejemplo n.º 3
0
def float_or_complex(float_func, complex_func):

	def switching_func(self, *args, **kwd):
		if any(
			isinstance(arg, complex)
			for arg in args
		):
			return complex_func(*args, **kwd)
		else:
			return float_func(*args, **kwd)

	switching_func.__name__ = complex_func.__name__
	switching_func.__doc__ = complex_func.__doc__
	return switching_func

exp = operation.generate_function(float_or_complex(math.exp, cmath.exp), "exp", operation.Function.REP_FUNCTION, 1)
log = operation.generate_function(float_or_complex(math.log, cmath.log), "log", operation.Function.REP_FUNCTION, 1)

PLUGIN.register_operation("exp", exp)
PLUGIN.register_operation("log", log)

cos = operation.generate_function(float_or_complex(math.cos, cmath.cos), "cos", operation.Function.REP_FUNCTION, 1)
acos = operation.generate_function(float_or_complex(math.acos, cmath.acos), "acos", operation.Function.REP_FUNCTION, 1)
sin = operation.generate_function(float_or_complex(math.sin, cmath.sin), "sin", operation.Function.REP_FUNCTION, 1)
asin = operation.generate_function(float_or_complex(math.asin, cmath.asin), "asin", operation.Function.REP_FUNCTION, 1)
tan = operation.generate_function(float_or_complex(math.tan, cmath.tan), "tan", operation.Function.REP_FUNCTION, 1)
atan = operation.generate_function(float_or_complex(math.atan, cmath.atan), "atan", operation.Function.REP_FUNCTION, 1)

PLUGIN.register_operation("cos", cos)
PLUGIN.register_operation("acos", acos)
PLUGIN.register_operation("sin", sin)