1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
from _plover_stroke import StrokeHelper
class BaseStroke(int):
_helper = None
@classmethod
def setup(cls, keys, implicit_hyphen_keys=None,
number_key=None, numbers=None,
feral_number_key=False):
cls._helper = StrokeHelper()
if number_key is None:
assert numbers is None
else:
assert numbers is not None
if implicit_hyphen_keys is not None and not isinstance(implicit_hyphen_keys, set):
implicit_hyphen_keys = set(implicit_hyphen_keys)
cls._helper.setup(keys, implicit_hyphen_keys=implicit_hyphen_keys,
number_key=number_key, numbers=numbers,
feral_number_key=feral_number_key)
@classmethod
def from_steno(cls, steno):
return int.__new__(cls, cls._helper.stroke_from_steno(steno))
@classmethod
def from_keys(cls, keys):
return int.__new__(cls, cls._helper.stroke_from_keys(keys))
@classmethod
def from_integer(cls, integer):
return int.__new__(cls, cls._helper.stroke_from_int(integer))
def __new__(cls, value):
return int.__new__(cls, cls._helper.stroke_from_any(value))
def __hash__(self):
return int(self)
def __eq__(self, other):
return self._helper.stroke_eq(self, other)
def __ge__(self, other):
return self._helper.stroke_ge(self, other)
def __gt__(self, other):
return self._helper.stroke_gt(self, other)
def __le__(self, other):
return self._helper.stroke_le(self, other)
def __lt__(self, other):
return self._helper.stroke_lt(self, other)
def __ne__(self, other):
return self._helper.stroke_ne(self, other)
def __contains__(self, other):
return self._helper.stroke_in(other, self)
def __invert__(self):
return self.from_integer(self._helper.stroke_invert(self))
def __or__(self, other):
return self.from_integer(self._helper.stroke_or(self, other))
def __and__(self, other):
return self.from_integer(self._helper.stroke_and(self, other))
def __add__(self, other):
return self.from_integer(self._helper.stroke_or(self, other))
def __sub__(self, other):
return self.from_integer(self._helper.stroke_sub(self, other))
def __len__(self):
return self._helper.stroke_len(self)
def __iter__(self):
return iter(self._helper.stroke_to_keys(self))
def __repr__(self):
return self._helper.stroke_to_steno(self)
def __str__(self):
return self._helper.stroke_to_steno(self)
def first(self):
return self._helper.stroke_first_key(self)
def last(self):
return self._helper.stroke_last_key(self)
def keys(self):
return self._helper.stroke_to_keys(self)
def has_digit(self):
return self._helper.stroke_has_digit(self)
def is_number(self):
return self._helper.stroke_is_number(self)
def is_prefix(self, other):
return self._helper.stroke_is_prefix(self, other)
def is_suffix(self, other):
return self._helper.stroke_is_suffix(self, other)
# Prevent use of 'from stroke import *'.
__all__ = ()
|