-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmodels.py
59 lines (43 loc) · 1.27 KB
/
models.py
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
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import List
class Action(Enum):
TYPE = "type"
COPY = "copy"
CLIPBOARD = "clipboard"
UNICODE = "unicode"
COPY_UNICODE = "copy-unicode"
STDOUT = "print"
MENU = "menu"
TYPE_NUMERICAL = "type-numerical"
def __str__(self):
return self.value
def __repr__(self):
return self.value
class CANCEL:
def __eq__(self, other):
return isinstance(other, CANCEL)
class DEFAULT:
def __eq__(self, other):
return isinstance(other, DEFAULT)
@dataclass
class Shortcut:
index: int
@dataclass
class CharacterEntry:
character: str
description: str | None
def __init__(self, character: str, description: str | None = None):
self.character = character
self.description = description
def merge(self, other: "CharacterEntry"):
if self == other:
return self
if self.character != other.character:
raise Exception("Cannot merge different characters")
if other.description:
if self.description:
self.description = f"{self.description}, {other.description}"
else:
self.description = other.description