| 1 | """Synthetic AT-SPI tree: no desktop service or native input is imported.""" |
| 2 | import json |
| 3 | import os |
| 4 | |
| 5 | |
| 6 | STATE_ENABLED = 1 |
| 7 | STATE_EDITABLE = 2 |
| 8 | |
| 9 | |
| 10 | class Node: |
| 11 | def __init__(self, name, children=()): |
| 12 | self.name = name |
| 13 | self.children = list(children) |
| 14 | self.childCount = len(self.children) |
| 15 | self.nActions = 1 |
| 16 | self.value = "Before" |
| 17 | self.numeric_value = 0 |
| 18 | self.mode = os.environ.get("CU_ATSPI_EDIT_MODE", "text") |
| 19 | |
| 20 | def getChildAtIndex(self, index): |
| 21 | return self.children[index] |
| 22 | |
| 23 | def getRoleName(self): |
| 24 | return "application" |
| 25 | |
| 26 | def getState(self): |
| 27 | return self |
| 28 | |
| 29 | def contains(self, state): |
| 30 | return self.mode != ("disabled" if state == STATE_ENABLED else "readonly") |
| 31 | |
| 32 | def queryEditableText(self): |
| 33 | if self.mode == "numeric": |
| 34 | raise NotImplementedError() |
| 35 | if self.mode == "query-failed": |
| 36 | raise RuntimeError("interface_failed") |
| 37 | return self |
| 38 | |
| 39 | def record_value(self, value): |
| 40 | with open(os.environ["CU_ATSPI_ACTIONS"], "a", encoding="utf-8") as output: |
| 41 | output.write(json.dumps({"name": self.name, "value": value}) + "\n") |
| 42 | |
| 43 | def setTextContents(self, value): |
| 44 | self.record_value(value) |
| 45 | self.value = "unexpected" if self.mode == "mismatch" else value |
| 46 | return self.mode != "rejected" |
| 47 | |
| 48 | def queryText(self): |
| 49 | return self |
| 50 | |
| 51 | @property |
| 52 | def characterCount(self): |
| 53 | return len(self.value) |
| 54 | |
| 55 | def getText(self, start, end): |
| 56 | return self.value[start:end] |
| 57 | |
| 58 | def queryValue(self): |
| 59 | if self.mode != "numeric": |
| 60 | raise NotImplementedError() |
| 61 | return self |
| 62 | |
| 63 | @property |
| 64 | def currentValue(self): |
| 65 | return self.numeric_value |
| 66 | |
| 67 | @currentValue.setter |
| 68 | def currentValue(self, value): |
| 69 | self.record_value(value) |
| 70 | self.numeric_value = value |
| 71 | |
| 72 | def queryAction(self): |
| 73 | return self |
| 74 | |
| 75 | def getName(self, index): |
| 76 | return "click" |
| 77 | |
| 78 | def doAction(self, index): |
| 79 | with open(os.environ["CU_ATSPI_ACTIONS"], "a", encoding="utf-8") as output: |
| 80 | output.write(json.dumps({"name": self.name, "action": "click"}) + "\n") |
| 81 | |
| 82 | |
| 83 | class Registry: |
| 84 | @staticmethod |
| 85 | def getDesktop(index): |
| 86 | names = ["Fixture Extended", "Fixture"] |
| 87 | if os.environ.get("CU_ATSPI_DUPLICATE") == "1": |
| 88 | names.append("FIXTURE") |
| 89 | return Node("desktop", [Node(name, [Node("child")]) for name in names]) |
| 90 |