opensignalbox-macro 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. opensignalbox/macro/__init__.py +1 -0
  2. opensignalbox/macro/actions/__init__.py +23 -0
  3. opensignalbox/macro/actions/base.py +268 -0
  4. opensignalbox/macro/actions/block_working.py +178 -0
  5. opensignalbox/macro/actions/inputs.py +418 -0
  6. opensignalbox/macro/actions/logic.py +117 -0
  7. opensignalbox/macro/actions/loops.py +115 -0
  8. opensignalbox/macro/actions/macros.py +140 -0
  9. opensignalbox/macro/actions/relays.py +62 -0
  10. opensignalbox/macro/actions/sound.py +39 -0
  11. opensignalbox/macro/actions/timing.py +148 -0
  12. opensignalbox/macro/assets/favicon.ico +0 -0
  13. opensignalbox/macro/macros.py +580 -0
  14. opensignalbox/macro/main.py +112 -0
  15. opensignalbox/macro/models.py +143 -0
  16. opensignalbox/macro/routes.py +491 -0
  17. opensignalbox/macro/shared_variables.py +41 -0
  18. opensignalbox/macro/sv_types.py +11 -0
  19. opensignalbox/macro/version.py +1 -0
  20. opensignalbox/macro/web_ui/.gitignore +26 -0
  21. opensignalbox/macro/web_ui/.vscode/extensions.json +3 -0
  22. opensignalbox/macro/web_ui/README.md +9 -0
  23. opensignalbox/macro/web_ui/components.json +14 -0
  24. opensignalbox/macro/web_ui/dist/android-chrome-192x192.png +0 -0
  25. opensignalbox/macro/web_ui/dist/android-chrome-512x512.png +0 -0
  26. opensignalbox/macro/web_ui/dist/apple-touch-icon.png +0 -0
  27. opensignalbox/macro/web_ui/dist/assets/index-C95a6Gjt.js +63201 -0
  28. opensignalbox/macro/web_ui/dist/assets/index-C95a6Gjt.js.map +1 -0
  29. opensignalbox/macro/web_ui/dist/assets/index-DuU9TAU0.css +2349 -0
  30. opensignalbox/macro/web_ui/dist/favicon-16x16.png +0 -0
  31. opensignalbox/macro/web_ui/dist/favicon-32x32.png +0 -0
  32. opensignalbox/macro/web_ui/dist/favicon.ico +0 -0
  33. opensignalbox/macro/web_ui/dist/icon.svg +65 -0
  34. opensignalbox/macro/web_ui/dist/index.html +17 -0
  35. opensignalbox/macro/web_ui/dist/menu-icon.svg +16 -0
  36. opensignalbox/macro/web_ui/dist/site.webmanifest +1 -0
  37. opensignalbox/macro/web_ui/index.html +16 -0
  38. opensignalbox/macro/web_ui/package-lock.json +3790 -0
  39. opensignalbox/macro/web_ui/package.json +42 -0
  40. opensignalbox/macro/web_ui/public/android-chrome-192x192.png +0 -0
  41. opensignalbox/macro/web_ui/public/android-chrome-512x512.png +0 -0
  42. opensignalbox/macro/web_ui/public/apple-touch-icon.png +0 -0
  43. opensignalbox/macro/web_ui/public/favicon-16x16.png +0 -0
  44. opensignalbox/macro/web_ui/public/favicon-32x32.png +0 -0
  45. opensignalbox/macro/web_ui/public/favicon.ico +0 -0
  46. opensignalbox/macro/web_ui/public/icon.svg +65 -0
  47. opensignalbox/macro/web_ui/public/menu-icon.svg +16 -0
  48. opensignalbox/macro/web_ui/public/site.webmanifest +1 -0
  49. opensignalbox/macro/web_ui/src/App.vue +32 -0
  50. opensignalbox/macro/web_ui/src/assets/favicon.ico +0 -0
  51. opensignalbox/macro/web_ui/src/assets/index.css +79 -0
  52. opensignalbox/macro/web_ui/src/blocks/blockWorking.ts +199 -0
  53. opensignalbox/macro/web_ui/src/blocks/index.ts +43 -0
  54. opensignalbox/macro/web_ui/src/blocks/logic.ts +164 -0
  55. opensignalbox/macro/web_ui/src/blocks/loops.ts +15 -0
  56. opensignalbox/macro/web_ui/src/blocks/macros.ts +83 -0
  57. opensignalbox/macro/web_ui/src/blocks/misc.ts +31 -0
  58. opensignalbox/macro/web_ui/src/blocks/number.ts +159 -0
  59. opensignalbox/macro/web_ui/src/blocks/relay.ts +52 -0
  60. opensignalbox/macro/web_ui/src/blocks/sound.ts +31 -0
  61. opensignalbox/macro/web_ui/src/blocks/text.ts +148 -0
  62. opensignalbox/macro/web_ui/src/blocks/timetable.ts +97 -0
  63. opensignalbox/macro/web_ui/src/blocks/timing.ts +94 -0
  64. opensignalbox/macro/web_ui/src/components/BlocklyComponent.vue +209 -0
  65. opensignalbox/macro/web_ui/src/components/MacroEditGeneralDetails.vue +118 -0
  66. opensignalbox/macro/web_ui/src/components/MacroEditLocalVariables.vue +144 -0
  67. opensignalbox/macro/web_ui/src/components/MacroEditor.vue +34 -0
  68. opensignalbox/macro/web_ui/src/components/MacroInstanceControls.vue +74 -0
  69. opensignalbox/macro/web_ui/src/components/MacroInstanceGeneralDetails.vue +84 -0
  70. opensignalbox/macro/web_ui/src/components/MacroInstanceLocalVariables.vue +121 -0
  71. opensignalbox/macro/web_ui/src/components/MacroInstanceViewer.vue +101 -0
  72. opensignalbox/macro/web_ui/src/components/MacrosHelp.vue +31 -0
  73. opensignalbox/macro/web_ui/src/components/MacrosLibraryList.vue +475 -0
  74. opensignalbox/macro/web_ui/src/components/MacrosRunningList.vue +187 -0
  75. opensignalbox/macro/web_ui/src/components/Picker.vue +199 -0
  76. opensignalbox/macro/web_ui/src/components/ui/accordion/Accordion.vue +19 -0
  77. opensignalbox/macro/web_ui/src/components/ui/accordion/AccordionContent.vue +24 -0
  78. opensignalbox/macro/web_ui/src/components/ui/accordion/AccordionItem.vue +24 -0
  79. opensignalbox/macro/web_ui/src/components/ui/accordion/AccordionTrigger.vue +39 -0
  80. opensignalbox/macro/web_ui/src/components/ui/accordion/index.ts +4 -0
  81. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialog.vue +14 -0
  82. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogAction.vue +20 -0
  83. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogCancel.vue +27 -0
  84. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogContent.vue +42 -0
  85. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogDescription.vue +25 -0
  86. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogFooter.vue +21 -0
  87. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogHeader.vue +16 -0
  88. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogTitle.vue +22 -0
  89. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/AlertDialogTrigger.vue +11 -0
  90. opensignalbox/macro/web_ui/src/components/ui/alert-dialog/index.ts +9 -0
  91. opensignalbox/macro/web_ui/src/components/ui/badge/Badge.vue +16 -0
  92. opensignalbox/macro/web_ui/src/components/ui/badge/index.ts +25 -0
  93. opensignalbox/macro/web_ui/src/components/ui/button/Button.vue +28 -0
  94. opensignalbox/macro/web_ui/src/components/ui/button/index.ts +35 -0
  95. opensignalbox/macro/web_ui/src/components/ui/card/Card.vue +21 -0
  96. opensignalbox/macro/web_ui/src/components/ui/card/CardContent.vue +14 -0
  97. opensignalbox/macro/web_ui/src/components/ui/card/CardDescription.vue +14 -0
  98. opensignalbox/macro/web_ui/src/components/ui/card/CardFooter.vue +14 -0
  99. opensignalbox/macro/web_ui/src/components/ui/card/CardHeader.vue +14 -0
  100. opensignalbox/macro/web_ui/src/components/ui/card/CardTitle.vue +18 -0
  101. opensignalbox/macro/web_ui/src/components/ui/card/index.ts +6 -0
  102. opensignalbox/macro/web_ui/src/components/ui/checkbox/Checkbox.vue +33 -0
  103. opensignalbox/macro/web_ui/src/components/ui/checkbox/index.ts +1 -0
  104. opensignalbox/macro/web_ui/src/components/ui/collapsible/Collapsible.vue +15 -0
  105. opensignalbox/macro/web_ui/src/components/ui/collapsible/CollapsibleContent.vue +11 -0
  106. opensignalbox/macro/web_ui/src/components/ui/collapsible/CollapsibleTrigger.vue +11 -0
  107. opensignalbox/macro/web_ui/src/components/ui/collapsible/index.ts +3 -0
  108. opensignalbox/macro/web_ui/src/components/ui/dialog/Dialog.vue +14 -0
  109. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogClose.vue +11 -0
  110. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogContent.vue +50 -0
  111. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogDescription.vue +24 -0
  112. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogFooter.vue +19 -0
  113. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogHeader.vue +16 -0
  114. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogScrollContent.vue +59 -0
  115. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogTitle.vue +29 -0
  116. opensignalbox/macro/web_ui/src/components/ui/dialog/DialogTrigger.vue +11 -0
  117. opensignalbox/macro/web_ui/src/components/ui/dialog/index.ts +9 -0
  118. opensignalbox/macro/web_ui/src/components/ui/drawer/Drawer.vue +19 -0
  119. opensignalbox/macro/web_ui/src/components/ui/drawer/DrawerContent.vue +28 -0
  120. opensignalbox/macro/web_ui/src/components/ui/drawer/DrawerDescription.vue +20 -0
  121. opensignalbox/macro/web_ui/src/components/ui/drawer/DrawerFooter.vue +14 -0
  122. opensignalbox/macro/web_ui/src/components/ui/drawer/DrawerHeader.vue +14 -0
  123. opensignalbox/macro/web_ui/src/components/ui/drawer/DrawerOverlay.vue +18 -0
  124. opensignalbox/macro/web_ui/src/components/ui/drawer/DrawerTitle.vue +20 -0
  125. opensignalbox/macro/web_ui/src/components/ui/drawer/index.ts +8 -0
  126. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenu.vue +14 -0
  127. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuCheckboxItem.vue +40 -0
  128. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuContent.vue +38 -0
  129. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuGroup.vue +11 -0
  130. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuItem.vue +28 -0
  131. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuLabel.vue +24 -0
  132. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuRadioGroup.vue +19 -0
  133. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuRadioItem.vue +41 -0
  134. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuSeparator.vue +22 -0
  135. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue +14 -0
  136. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuSub.vue +19 -0
  137. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuSubContent.vue +30 -0
  138. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue +33 -0
  139. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/DropdownMenuTrigger.vue +13 -0
  140. opensignalbox/macro/web_ui/src/components/ui/dropdown-menu/index.ts +16 -0
  141. opensignalbox/macro/web_ui/src/components/ui/input/Input.vue +24 -0
  142. opensignalbox/macro/web_ui/src/components/ui/input/index.ts +1 -0
  143. opensignalbox/macro/web_ui/src/components/ui/label/Label.vue +27 -0
  144. opensignalbox/macro/web_ui/src/components/ui/label/index.ts +1 -0
  145. opensignalbox/macro/web_ui/src/components/ui/pagination/Pagination.vue +26 -0
  146. opensignalbox/macro/web_ui/src/components/ui/pagination/PaginationContent.vue +22 -0
  147. opensignalbox/macro/web_ui/src/components/ui/pagination/PaginationEllipsis.vue +25 -0
  148. opensignalbox/macro/web_ui/src/components/ui/pagination/PaginationFirst.vue +33 -0
  149. opensignalbox/macro/web_ui/src/components/ui/pagination/PaginationItem.vue +34 -0
  150. opensignalbox/macro/web_ui/src/components/ui/pagination/PaginationLast.vue +33 -0
  151. opensignalbox/macro/web_ui/src/components/ui/pagination/PaginationNext.vue +33 -0
  152. opensignalbox/macro/web_ui/src/components/ui/pagination/PaginationPrevious.vue +33 -0
  153. opensignalbox/macro/web_ui/src/components/ui/pagination/index.ts +8 -0
  154. opensignalbox/macro/web_ui/src/components/ui/scroll-area/ScrollArea.vue +29 -0
  155. opensignalbox/macro/web_ui/src/components/ui/scroll-area/ScrollBar.vue +30 -0
  156. opensignalbox/macro/web_ui/src/components/ui/scroll-area/index.ts +2 -0
  157. opensignalbox/macro/web_ui/src/components/ui/select/Select.vue +15 -0
  158. opensignalbox/macro/web_ui/src/components/ui/select/SelectContent.vue +53 -0
  159. opensignalbox/macro/web_ui/src/components/ui/select/SelectGroup.vue +19 -0
  160. opensignalbox/macro/web_ui/src/components/ui/select/SelectItem.vue +44 -0
  161. opensignalbox/macro/web_ui/src/components/ui/select/SelectItemText.vue +11 -0
  162. opensignalbox/macro/web_ui/src/components/ui/select/SelectLabel.vue +13 -0
  163. opensignalbox/macro/web_ui/src/components/ui/select/SelectScrollDownButton.vue +24 -0
  164. opensignalbox/macro/web_ui/src/components/ui/select/SelectScrollUpButton.vue +24 -0
  165. opensignalbox/macro/web_ui/src/components/ui/select/SelectSeparator.vue +17 -0
  166. opensignalbox/macro/web_ui/src/components/ui/select/SelectTrigger.vue +31 -0
  167. opensignalbox/macro/web_ui/src/components/ui/select/SelectValue.vue +11 -0
  168. opensignalbox/macro/web_ui/src/components/ui/select/index.ts +11 -0
  169. opensignalbox/macro/web_ui/src/components/ui/separator/Separator.vue +20 -0
  170. opensignalbox/macro/web_ui/src/components/ui/separator/index.ts +1 -0
  171. opensignalbox/macro/web_ui/src/components/ui/sheet/Sheet.vue +14 -0
  172. opensignalbox/macro/web_ui/src/components/ui/sheet/SheetClose.vue +11 -0
  173. opensignalbox/macro/web_ui/src/components/ui/sheet/SheetContent.vue +56 -0
  174. opensignalbox/macro/web_ui/src/components/ui/sheet/SheetDescription.vue +22 -0
  175. opensignalbox/macro/web_ui/src/components/ui/sheet/SheetFooter.vue +19 -0
  176. opensignalbox/macro/web_ui/src/components/ui/sheet/SheetHeader.vue +16 -0
  177. opensignalbox/macro/web_ui/src/components/ui/sheet/SheetTitle.vue +22 -0
  178. opensignalbox/macro/web_ui/src/components/ui/sheet/SheetTrigger.vue +11 -0
  179. opensignalbox/macro/web_ui/src/components/ui/sheet/index.ts +31 -0
  180. opensignalbox/macro/web_ui/src/components/ui/table/Table.vue +16 -0
  181. opensignalbox/macro/web_ui/src/components/ui/table/TableBody.vue +14 -0
  182. opensignalbox/macro/web_ui/src/components/ui/table/TableCaption.vue +14 -0
  183. opensignalbox/macro/web_ui/src/components/ui/table/TableCell.vue +21 -0
  184. opensignalbox/macro/web_ui/src/components/ui/table/TableEmpty.vue +37 -0
  185. opensignalbox/macro/web_ui/src/components/ui/table/TableFooter.vue +14 -0
  186. opensignalbox/macro/web_ui/src/components/ui/table/TableHead.vue +14 -0
  187. opensignalbox/macro/web_ui/src/components/ui/table/TableHeader.vue +14 -0
  188. opensignalbox/macro/web_ui/src/components/ui/table/TableRow.vue +14 -0
  189. opensignalbox/macro/web_ui/src/components/ui/table/index.ts +8 -0
  190. opensignalbox/macro/web_ui/src/components/ui/tabs/Tabs.vue +15 -0
  191. opensignalbox/macro/web_ui/src/components/ui/tabs/TabsContent.vue +22 -0
  192. opensignalbox/macro/web_ui/src/components/ui/tabs/TabsList.vue +25 -0
  193. opensignalbox/macro/web_ui/src/components/ui/tabs/TabsTrigger.vue +27 -0
  194. opensignalbox/macro/web_ui/src/components/ui/tabs/index.ts +4 -0
  195. opensignalbox/macro/web_ui/src/components/ui/tags-input/TagsInput.vue +22 -0
  196. opensignalbox/macro/web_ui/src/components/ui/tags-input/TagsInputInput.vue +19 -0
  197. opensignalbox/macro/web_ui/src/components/ui/tags-input/TagsInputItem.vue +22 -0
  198. opensignalbox/macro/web_ui/src/components/ui/tags-input/TagsInputItemDelete.vue +24 -0
  199. opensignalbox/macro/web_ui/src/components/ui/tags-input/TagsInputItemText.vue +19 -0
  200. opensignalbox/macro/web_ui/src/components/ui/tags-input/index.ts +5 -0
  201. opensignalbox/macro/web_ui/src/components/ui/textarea/Textarea.vue +24 -0
  202. opensignalbox/macro/web_ui/src/components/ui/textarea/index.ts +1 -0
  203. opensignalbox/macro/web_ui/src/components/ui/toast/Toast.vue +28 -0
  204. opensignalbox/macro/web_ui/src/components/ui/toast/ToastAction.vue +19 -0
  205. opensignalbox/macro/web_ui/src/components/ui/toast/ToastClose.vue +22 -0
  206. opensignalbox/macro/web_ui/src/components/ui/toast/ToastDescription.vue +19 -0
  207. opensignalbox/macro/web_ui/src/components/ui/toast/ToastProvider.vue +11 -0
  208. opensignalbox/macro/web_ui/src/components/ui/toast/ToastTitle.vue +19 -0
  209. opensignalbox/macro/web_ui/src/components/ui/toast/ToastViewport.vue +17 -0
  210. opensignalbox/macro/web_ui/src/components/ui/toast/Toaster.vue +30 -0
  211. opensignalbox/macro/web_ui/src/components/ui/toast/index.ts +38 -0
  212. opensignalbox/macro/web_ui/src/components/ui/toast/use-toast.ts +165 -0
  213. opensignalbox/macro/web_ui/src/components/ui/tooltip/Tooltip.vue +14 -0
  214. opensignalbox/macro/web_ui/src/components/ui/tooltip/TooltipContent.vue +31 -0
  215. opensignalbox/macro/web_ui/src/components/ui/tooltip/TooltipProvider.vue +11 -0
  216. opensignalbox/macro/web_ui/src/components/ui/tooltip/TooltipTrigger.vue +11 -0
  217. opensignalbox/macro/web_ui/src/components/ui/tooltip/index.ts +4 -0
  218. opensignalbox/macro/web_ui/src/libs/utils.ts +16 -0
  219. opensignalbox/macro/web_ui/src/main.ts +41 -0
  220. opensignalbox/macro/web_ui/src/types.ts +16 -0
  221. opensignalbox/macro/web_ui/src/views/GlobalVariables.vue +728 -0
  222. opensignalbox/macro/web_ui/src/views/MacroEdit.vue +200 -0
  223. opensignalbox/macro/web_ui/src/views/MacroInstanceView.vue +87 -0
  224. opensignalbox/macro/web_ui/src/views/MacrosLibrary.vue +9 -0
  225. opensignalbox/macro/web_ui/src/views/MacrosRunning.vue +9 -0
  226. opensignalbox/macro/web_ui/src/views/UserShortcuts.vue +288 -0
  227. opensignalbox/macro/web_ui/src/vite-env.d.ts +1 -0
  228. opensignalbox/macro/web_ui/tailwind.config.js +93 -0
  229. opensignalbox/macro/web_ui/tsconfig.json +30 -0
  230. opensignalbox/macro/web_ui/tsconfig.node.json +11 -0
  231. opensignalbox/macro/web_ui/tsconfig.node.tsbuildinfo +1 -0
  232. opensignalbox/macro/web_ui/vite.config.ts +62 -0
  233. opensignalbox_macro-0.1.0.dist-info/METADATA +29 -0
  234. opensignalbox_macro-0.1.0.dist-info/RECORD +236 -0
  235. opensignalbox_macro-0.1.0.dist-info/WHEEL +4 -0
  236. opensignalbox_macro-0.1.0.dist-info/entry_points.txt +5 -0
@@ -0,0 +1 @@
1
+ __doc__ = "openSignalBox macro module."
@@ -0,0 +1,23 @@
1
+ from . import (
2
+ base,
3
+ block_working,
4
+ inputs,
5
+ logic,
6
+ loops,
7
+ macros,
8
+ relays,
9
+ sound,
10
+ timing,
11
+ )
12
+
13
+ __all__ = [
14
+ "base",
15
+ "block_working",
16
+ "inputs",
17
+ "logic",
18
+ "loops",
19
+ "macros",
20
+ "relays",
21
+ "sound",
22
+ "timing",
23
+ ]
@@ -0,0 +1,268 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from abc import ABC, abstractmethod
5
+ from typing import TYPE_CHECKING, Any, Type, TypeVar
6
+
7
+ from opensignalbox.macro.actions.inputs import inputs_from_blocks
8
+
9
+ if TYPE_CHECKING:
10
+ from opensignalbox.macro.macros import MacroController
11
+
12
+ from opensignalbox.common.variables import (
13
+ VariableType,
14
+ get_pubbed_shared_variables,
15
+ get_subbed_shared_variables,
16
+ )
17
+
18
+ pubbed_shared_variables = get_pubbed_shared_variables()
19
+ subbed_shared_variables = get_subbed_shared_variables()
20
+
21
+ T = TypeVar("T", bound="Action")
22
+
23
+ input_shared_variable_suffix = "_sv"
24
+ input_local_variable_suffix = "_lv"
25
+ input_global_variable_suffix = "_gv"
26
+ input_parameter_suffix = "_param"
27
+
28
+ logger = logging.getLogger(__name__)
29
+
30
+ _action_registry = {}
31
+
32
+
33
+ def register_action(block_type: str, action_class: Type[Action]):
34
+ """Register an action class for a block type."""
35
+ _action_registry[block_type] = action_class
36
+
37
+
38
+ def action(block_type: str):
39
+ """Decorator to register action classes for a block type."""
40
+
41
+ def decorator(cls: Type[Action]) -> Type[Action]:
42
+ register_action(block_type, cls)
43
+ return cls
44
+
45
+ return decorator
46
+
47
+
48
+ def actions_from_blocks(
49
+ block_parent: dict[str, Any],
50
+ subs: set[str] | None = None,
51
+ pubs: set[str] | None = None,
52
+ return_action: str | None = None,
53
+ ) -> tuple[dict[str, Action], set[str], set[str]]:
54
+ subs = subs or set()
55
+ pubs = pubs or set()
56
+ block = block_parent.get("block", {})
57
+ action_class = _action_registry.get(block.get("type"))
58
+ if not action_class:
59
+ logger.warning(f"Unknown action type: {block.get('type')}")
60
+ return {}, set(), set()
61
+ actions, action_subs, action_pubs = action_class.from_block(block, return_action)
62
+
63
+ subs.update(action_subs)
64
+ pubs.update(action_pubs)
65
+
66
+ # Handle next block
67
+ if next_block := block.get("next", {}):
68
+ next_actions, next_subs, next_pubs = actions_from_blocks(
69
+ next_block, return_action=return_action, subs=subs, pubs=pubs
70
+ )
71
+ actions.update(next_actions)
72
+ subs.update(next_subs)
73
+ pubs.update(next_pubs)
74
+
75
+ return actions, subs, pubs
76
+
77
+
78
+ class MacroError(Exception):
79
+ def __init__(self, message: str):
80
+ super().__init__(message)
81
+ logger.debug("MacroError raised: {}".format(message))
82
+
83
+
84
+ class Action(ABC):
85
+ def __init__(
86
+ self, block_id: str | None = None, next_action: str | None = None, **kwargs
87
+ ) -> None:
88
+ self.block_id = block_id
89
+ self.next_action = next_action
90
+ self.action_params: dict[str, Any] = {}
91
+ self.action_params.update(kwargs["action_params"])
92
+ self.waitable = False
93
+
94
+ @classmethod
95
+ @abstractmethod
96
+ def from_block(
97
+ cls: Type[T], block: dict[str, Any], return_action: str | None
98
+ ) -> tuple[dict[str, T], set[str], set[str]]:
99
+ return {"": cls()}, set(), set()
100
+
101
+ @abstractmethod
102
+ def evaluate(
103
+ self, macro_controller: MacroController, macro_instance_name: str
104
+ ) -> str | None:
105
+ """
106
+ Returns the action id for the next cycle.
107
+ Reset the action at the end, otherwise loops won't work!
108
+ """
109
+ pass
110
+
111
+ @classmethod
112
+ def _extract_block_info(
113
+ cls, block: dict[str, Any], return_action: str | None
114
+ ) -> tuple[str, str | None]:
115
+ """Extract common block ID and next action."""
116
+ block_id = block.get("id", "")
117
+ next_action = block.get("next", {}).get("block", {}).get("id", return_action)
118
+ return block_id, next_action
119
+
120
+ @classmethod
121
+ def _extract_field(
122
+ cls, block: dict[str, Any], field_name: str, default: str = ""
123
+ ) -> str:
124
+ """Extract field value with default."""
125
+ value = block.get("fields", {}).get(field_name, "")
126
+ return value if value else default
127
+
128
+ @classmethod
129
+ def _extract_input(cls, block: dict[str, Any], input_name: str) -> dict[str, Any]:
130
+ """Extract input value from block."""
131
+ return block.get("inputs", {}).get(input_name, {})
132
+
133
+ def _validate_required_params(self, *param_names: str) -> None:
134
+ """Validate that required parameters exist and are not empty."""
135
+ for param in param_names:
136
+ value = self.action_params.get(param)
137
+ if not value or value == "":
138
+ raise ValueError(
139
+ f"Missing or invalid '{param}' parameter for {self.__class__.__name__}"
140
+ )
141
+
142
+
143
+ @action("entry")
144
+ class ActionEntry(Action):
145
+ @classmethod
146
+ def from_block(
147
+ cls: Type[T], block: dict[str, Any], return_action: str | None
148
+ ) -> tuple[dict[str, Action], set[str], set[str]]:
149
+ block_id, next_action = cls._extract_block_info(block, return_action)
150
+ instance = cls(block_id=block_id, next_action=next_action, action_params={})
151
+ return {block_id: instance}, set(), set()
152
+
153
+ def evaluate(
154
+ self, macro_controller: MacroController, macro_instance_name: str
155
+ ) -> str | None:
156
+ return self.next_action
157
+
158
+
159
+ @action("set_logic_local_variable")
160
+ @action("set_number_local_variable")
161
+ @action("set_text_local_variable")
162
+ @action("set_logic_global_variable")
163
+ @action("set_number_global_variable")
164
+ @action("set_text_global_variable")
165
+ @action("set_logic_shared_variable")
166
+ @action("set_number_shared_variable")
167
+ @action("set_text_shared_variable")
168
+ class ActionSetVariable(Action):
169
+ @classmethod
170
+ def from_block(
171
+ cls: Type[T], block: dict[str, Any], return_action: str | None
172
+ ) -> tuple[dict[str, Action], set[str], set[str]]:
173
+ block_id, next_action = cls._extract_block_info(block, return_action)
174
+ if "local" in block.get("type", ""):
175
+ scope = "local"
176
+ variable = cls._extract_field(block, "LOCALVARIABLE")
177
+ elif "global" in block.get("type", ""):
178
+ scope = "global"
179
+ variable = cls._extract_field(block, "GLOBALVARIABLE")
180
+ elif "shared" in block.get("type", ""):
181
+ scope = "shared"
182
+ variable = cls._extract_field(block, "SHAREDVARIABLE")
183
+ else:
184
+ raise MacroError(
185
+ f"Unknown variable scope type: {block['type']} for block {block_id} of type {cls.__name__}"
186
+ )
187
+ if "logic" in block.get("type", ""):
188
+ typestring = VariableType.LOGIC
189
+ elif "number" in block.get("type", ""):
190
+ typestring = VariableType.NUMBER
191
+ elif "text" in block.get("type", ""):
192
+ typestring = VariableType.TEXT
193
+ else:
194
+ raise MacroError(
195
+ f"Unknown variable type: {block['type']} for block {block_id} of type {cls.__name__}"
196
+ )
197
+ input = cls._extract_input(block, "VALUE")
198
+ value_input, subs = inputs_from_blocks(input)
199
+ action_params = {
200
+ "variable": variable,
201
+ "scope": scope,
202
+ "typestring": typestring,
203
+ "value_input": value_input,
204
+ }
205
+ instance = cls(
206
+ block_id=block_id, next_action=next_action, action_params=action_params
207
+ )
208
+ return {block_id: instance}, subs, set()
209
+
210
+ def evaluate(
211
+ self, macro_controller: "MacroController", macro_instance_name: str
212
+ ) -> str | None:
213
+ self._validate_required_params("variable", "typestring", "value_input")
214
+ value = self.action_params["value_input"].evaluate(
215
+ macro_controller, macro_instance_name
216
+ )
217
+ if self.action_params["typestring"] == VariableType.LOGIC:
218
+ # Handle logic variable
219
+ value = bool(value) # Ensure value is boolean
220
+ elif self.action_params["typestring"] == VariableType.NUMBER:
221
+ # Handle number variable
222
+ value = float(value) # Ensure value is float
223
+ elif self.action_params["typestring"] == VariableType.TEXT:
224
+ # Handle text variable
225
+ value = str(value) # Ensure value is string
226
+ if self.action_params["scope"] == "local":
227
+ instance = macro_controller.macro_instances[macro_instance_name]
228
+ if self.action_params["variable"] in instance.local_variables:
229
+ macro_controller.set_local_variable(
230
+ macro_instance_name, self.action_params["variable"], value
231
+ )
232
+ elif self.action_params["scope"] == "global":
233
+ macro_controller.set_global_variable(self.action_params["variable"], value)
234
+ elif self.action_params["scope"] == "shared":
235
+ pubbed_shared_variables[self.action_params["variable"]].update(
236
+ {"value": value}
237
+ )
238
+
239
+ return self.next_action
240
+
241
+
242
+ @action("notification")
243
+ class ActionNotification(Action):
244
+ @classmethod
245
+ def from_block(
246
+ cls: Type[T], block: dict[str, Any], return_action: str | None
247
+ ) -> tuple[dict[str, Action], set[str], set[str]]:
248
+ block_id, next_action = cls._extract_block_info(block, return_action)
249
+ input = cls._extract_input(block, "MESSAGE")
250
+ message_input, subs = inputs_from_blocks(input)
251
+ instance = cls(
252
+ block_id=block_id,
253
+ next_action=next_action,
254
+ action_params={"message_input": message_input},
255
+ )
256
+ return {block_id: instance}, set(), subs
257
+
258
+ def evaluate(
259
+ self, macro_controller: "MacroController", macro_instance_name: str
260
+ ) -> str | None:
261
+ self._validate_required_params("message_input")
262
+ message = self.action_params["message_input"].evaluate(
263
+ macro_controller, macro_instance_name
264
+ )
265
+ macro_controller.send_notification(
266
+ "Notification from Macro", macro_instance_name + ": " + message
267
+ )
268
+ return self.next_action
@@ -0,0 +1,178 @@
1
+ from datetime import datetime, timedelta
2
+ from typing import TYPE_CHECKING, Any, Type, cast
3
+
4
+ from opensignalbox.common.variables import BellCodeSVData
5
+ from opensignalbox.macro.actions.inputs import inputs_from_blocks
6
+ from opensignalbox.macro.models import StatusEnum
7
+
8
+ from .base import (
9
+ Action,
10
+ MacroError,
11
+ T,
12
+ action,
13
+ pubbed_shared_variables,
14
+ subbed_shared_variables,
15
+ )
16
+
17
+ if TYPE_CHECKING:
18
+ from opensignalbox.macro.macros import MacroController
19
+
20
+
21
+ @action("send_bellcode")
22
+ class ActionSendBellcode(Action):
23
+ @classmethod
24
+ def from_block(
25
+ cls: Type[T], block: dict[str, Any], return_action: str | None
26
+ ) -> tuple[dict[str, Action], set[str], set[str]]:
27
+ block_id, next_action = cls._extract_block_info(block, return_action)
28
+ shared_variable = cls._extract_field(block, "SHAREDVARIABLE")
29
+ input = cls._extract_input(block, "BELLCODE")
30
+ bellcode_input, subs = inputs_from_blocks(input)
31
+ action_params = {
32
+ "shared_variable": shared_variable,
33
+ "bellcode_input": bellcode_input,
34
+ "count": 0,
35
+ }
36
+ instance = cls(
37
+ block_id=block_id, next_action=next_action, action_params=action_params
38
+ )
39
+ return {block_id: instance}, subs, set()
40
+
41
+ def evaluate(
42
+ self, macro_controller: "MacroController", macro_instance_name: str
43
+ ) -> str | None:
44
+ self._validate_required_params("shared_variable")
45
+ bellcode = self.action_params["bellcode_input"].evaluate(
46
+ macro_controller, macro_instance_name
47
+ )
48
+ try:
49
+ self.action_params["count"] += 1
50
+ # logger.debug(f"Sending bellcode: {bellcode} with count {self.action_params['count'] } to shared variable {self.action_params['shared_variable']}")
51
+ pubbed_shared_variables[self.action_params["shared_variable"]].update(
52
+ {"code": bellcode, "count": self.action_params["count"]}
53
+ )
54
+ except KeyError as exc:
55
+ raise MacroError(
56
+ f"Variable {self.action_params['shared_variable']} not found"
57
+ ) from exc
58
+ return self.next_action
59
+
60
+
61
+ @action("wait_for_bellcode")
62
+ class ActionWaitForBellcodeEquals(Action):
63
+ def __init__(
64
+ self, block_id: str | None = None, next_action: str | None = None, **kwargs
65
+ ) -> None:
66
+ super().__init__(block_id, next_action, **kwargs)
67
+ self.waitable = True
68
+
69
+ @classmethod
70
+ def from_block(
71
+ cls: Type[T], block: dict[str, Any], return_action: str | None
72
+ ) -> tuple[dict[str, Action], set[str], set[str]]:
73
+ block_id, next_action = cls._extract_block_info(block, return_action)
74
+ shared_variable = cls._extract_field(block, "SHAREDVARIABLE")
75
+ local_variable = cls._extract_field(block, "LOCALVARIABLE")
76
+ subbed_shared_variables.add(shared_variable, BellCodeSVData(count=0, code=""))
77
+ instance = cls(
78
+ block_id=block_id,
79
+ next_action=next_action,
80
+ action_params={
81
+ "value": None,
82
+ "shared_variable": shared_variable,
83
+ "local_variable": local_variable,
84
+ },
85
+ )
86
+ return {block_id: instance}, {shared_variable}, set()
87
+
88
+ def evaluate(
89
+ self, macro_controller: "MacroController", macro_instance_name: str
90
+ ) -> str | None:
91
+ self._validate_required_params("shared_variable", "local_variable")
92
+ sv_value = subbed_shared_variables.get_value(
93
+ self.action_params["shared_variable"]
94
+ )
95
+ new_value = cast(BellCodeSVData, sv_value)
96
+ if self.action_params["value"] is None:
97
+ self.action_params["value"] = new_value
98
+ if (
99
+ macro_controller.macro_instances[macro_instance_name].run_state
100
+ == StatusEnum.STEP
101
+ ):
102
+ return self.next_action
103
+ if new_value == self.action_params["value"]:
104
+ return self.block_id # Wait for the next evaluation
105
+ self.action_params["value"] = new_value
106
+ if self.action_params["local_variable"]:
107
+ macro_controller.set_local_variable(
108
+ macro_instance_name,
109
+ self.action_params["local_variable"],
110
+ new_value.code,
111
+ )
112
+ return self.next_action
113
+
114
+
115
+ @action("wait_for_bellcode_with_timeout")
116
+ class ActionWaitForBellcodeWithTimeout(Action):
117
+ def __init__(
118
+ self, block_id: str | None = None, next_action: str | None = None, **kwargs
119
+ ) -> None:
120
+ super().__init__(block_id, next_action, **kwargs)
121
+ self.end: datetime | None = None
122
+ self.waitable = True
123
+
124
+ @classmethod
125
+ def from_block(
126
+ cls: Type[T], block: dict[str, Any], return_action: str | None
127
+ ) -> tuple[dict[str, Action], set[str], set[str]]:
128
+ block_id, next_action = cls._extract_block_info(block, return_action)
129
+ shared_variable = cls._extract_field(block, "SHAREDVARIABLE")
130
+ local_variable = cls._extract_field(block, "LOCALVARIABLE")
131
+ subbed_shared_variables.add(shared_variable, BellCodeSVData(count=0, code=""))
132
+ input = cls._extract_input(block, "TIMEOUT")
133
+ timeout_input, subs = inputs_from_blocks(input)
134
+ action_params = {
135
+ "value": None,
136
+ "shared_variable": shared_variable,
137
+ "local_variable": local_variable,
138
+ "timeout": timeout_input,
139
+ }
140
+ instance = cls(
141
+ block_id=block_id, next_action=next_action, action_params=action_params
142
+ )
143
+ return {block_id: instance}, subs, set()
144
+
145
+ def evaluate(
146
+ self, macro_controller: "MacroController", macro_instance_name: str
147
+ ) -> str | None:
148
+ self._validate_required_params("shared_variable", "local_variable", "timeout")
149
+ sv_value = subbed_shared_variables.get_value(
150
+ self.action_params["shared_variable"]
151
+ )
152
+ new_value = cast(BellCodeSVData, sv_value)
153
+ if self.action_params["value"] is None:
154
+ self.action_params["value"] = new_value
155
+ if self.end is None:
156
+ self.end = datetime.now() + timedelta(
157
+ seconds=self.action_params["timeout"].evaluate(
158
+ macro_controller, macro_instance_name
159
+ )
160
+ )
161
+ if datetime.now() > self.end:
162
+ self.end = None
163
+ return self.next_action
164
+ if (
165
+ macro_controller.macro_instances[macro_instance_name].run_state
166
+ == StatusEnum.STEP
167
+ ):
168
+ return self.next_action
169
+ if new_value == self.action_params["value"]:
170
+ return self.block_id # Wait for the next evaluation
171
+ self.action_params["value"] = new_value
172
+ if self.action_params["local_variable"]:
173
+ macro_controller.set_local_variable(
174
+ macro_instance_name,
175
+ self.action_params["local_variable"],
176
+ new_value.code,
177
+ )
178
+ return self.next_action