pyautoscene 0.1.0__tar.gz → 0.2.0__tar.gz

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 (26) hide show
  1. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/.gitignore +3 -0
  2. pyautoscene-0.2.0/LICENSE +201 -0
  3. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/PKG-INFO +38 -17
  4. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/README.md +36 -14
  5. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/main.py +8 -8
  6. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/manual_flow.py +8 -8
  7. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/pyproject.toml +11 -5
  8. pyautoscene-0.2.0/src/pyautoscene/__init__.py +5 -0
  9. pyautoscene-0.2.0/src/pyautoscene/ocr.py +70 -0
  10. pyautoscene-0.2.0/src/pyautoscene/ocr_config.yaml +112 -0
  11. pyautoscene-0.2.0/src/pyautoscene/references.py +78 -0
  12. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/src/pyautoscene/scene.py +5 -5
  13. pyautoscene-0.2.0/src/pyautoscene/screen.py +79 -0
  14. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/src/pyautoscene/session.py +2 -2
  15. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/uv.lock +53 -30
  16. pyautoscene-0.1.0/src/pyautoscene/__init__.py +0 -5
  17. pyautoscene-0.1.0/src/pyautoscene/references.py +0 -38
  18. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/.pre-commit-config.yaml +0 -0
  19. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/.python-version +0 -0
  20. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/references/add_to_cart_button.png +0 -0
  21. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/references/backpack.png +0 -0
  22. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/references/cart_icon.png +0 -0
  23. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/references/checkout_button.png +0 -0
  24. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/references/login_button.png +0 -0
  25. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/examples/saucedemo/references/username.png +0 -0
  26. {pyautoscene-0.1.0 → pyautoscene-0.2.0}/src/pyautoscene/utils.py +0 -0
@@ -9,4 +9,7 @@ wheels/
9
9
  # Virtual environments
10
10
  .venv
11
11
 
12
+ # Environment variables
13
+ .env
14
+
12
15
  explore/
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,15 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyautoscene
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Advance GUI automation
5
5
  Author-email: pritam-dey3 <pritam.pritamdey.984@gmail.com>
6
+ License-File: LICENSE
6
7
  Requires-Python: >=3.13
7
8
  Requires-Dist: networkx>=3.5
8
- Requires-Dist: onnxruntime>=1.22.0
9
9
  Requires-Dist: pillow>=11.3.0
10
10
  Requires-Dist: pyautogui>=0.9.54
11
11
  Requires-Dist: python-statemachine[diagrams]
12
- Requires-Dist: rapidocr>=3.2.0
13
12
  Description-Content-Type: text/markdown
14
13
 
15
14
  # PyAutoScene
@@ -21,7 +20,8 @@ PyAutoScene is a Python library that provides a declarative approach to GUI auto
21
20
  ## 🌟 Features
22
21
 
23
22
  - **Scene-Based Architecture**: Model your application as a collection of scenes with defined elements and transitions
24
- - **Visual Element Detection**: Supports both image-based element recognition. (Text recognition support coming soon!)
23
+ - **Visual Element Detection**: Supports both image-based and text-based element recognition
24
+ - **Region Specification**: Flexible region syntax for targeting specific screen areas
25
25
  - **Automatic Navigation**: Intelligent pathfinding between scenes using graph algorithms
26
26
  - **Action Decorators**: Clean, declarative syntax for defining scene actions and transitions
27
27
 
@@ -39,15 +39,15 @@ Here's how to automate a simple login flow:
39
39
 
40
40
  ```python
41
41
  import pyautogui as gui
42
- from pyautoscene import ReferenceImage, ReferenceText, Scene, Session
42
+ from pyautoscene import ImageElement, TextElement, Scene, Session
43
43
  from pyautoscene.utils import locate_and_click
44
44
 
45
45
  # Define scenes
46
46
  login = Scene(
47
47
  "Login",
48
48
  elements=[
49
- ReferenceText("Welcome to Login"),
50
- ReferenceImage("references/login_button.png"),
49
+ TextElement("Welcome to Login"),
50
+ ImageElement("references/login_button.png"),
51
51
  ],
52
52
  initial=True,
53
53
  )
@@ -55,8 +55,8 @@ login = Scene(
55
55
  dashboard = Scene(
56
56
  "Dashboard",
57
57
  elements=[
58
- ReferenceText("Dashboard"),
59
- ReferenceImage("references/user_menu.png"),
58
+ TextElement("Dashboard"),
59
+ ImageElement("references/user_menu.png"),
60
60
  ],
61
61
  )
62
62
 
@@ -89,8 +89,8 @@ A **Scene** represents a distinct state in your application's UI. Each scene con
89
89
  scene = Scene(
90
90
  "SceneName",
91
91
  elements=[
92
- ReferenceImage("path/to/image.png"),
93
- ReferenceText("Expected Text"),
92
+ ImageElement("path/to/image.png"),
93
+ TextElement("Expected Text"),
94
94
  ],
95
95
  initial=False # Set to True for starting scene
96
96
  )
@@ -100,20 +100,33 @@ scene = Scene(
100
100
 
101
101
  PyAutoScene supports two types of reference elements:
102
102
 
103
- #### ReferenceImage
103
+ #### ImageElement
104
104
 
105
105
  Detects scenes using image matching:
106
106
 
107
107
  ```python
108
- ReferenceImage("path/to/reference/image.png")
108
+ ImageElement("path/to/reference/image.png")
109
109
  ```
110
110
 
111
- #### ReferenceText
112
- (Coming soon)
111
+ #### TextElement
112
+
113
113
  Detects scenes using text recognition:
114
114
 
115
115
  ```python
116
- ReferenceText("Expected text on screen")
116
+ TextElement("Expected text on screen")
117
+ ```
118
+
119
+ Both elements support region specification for limiting search areas. You can specify regions using a string format like `"x:2/3 y:(1-2)/3"` to easily define screen regions:
120
+
121
+ ```python
122
+ # Search for text in the top-left third of the screen
123
+ TextElement("Login", region="x:1/3 y:1/3")
124
+
125
+ # Search in a horizontal band across the middle third of the screen
126
+ ImageElement("button.png", region="y:2/3")
127
+
128
+ # Search in a specific area spanning columns 1-2 out of 3 columns
129
+ TextElement("Welcome", region="x:(1-2)/3 y:1/3")
117
130
  ```
118
131
 
119
132
  ### Actions and Transitions
@@ -194,7 +207,15 @@ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENS
194
207
 
195
208
  ## 🔮 Roadmap
196
209
 
197
- - [ ] Text recognition implementation
198
210
  - [ ] Enhanced image matching algorithms
211
+ - [ ] TemplateScene
212
+ - [ ] Relation between images
199
213
  - [ ] Multiple session support
200
214
 
215
+ ## 🙏 Credits
216
+
217
+ PyAutoScene builds on the work of several open-source projects:
218
+
219
+ - [PyAutoGUI](https://github.com/asweigart/pyautogui) by Al Sweigart
220
+ - [python-statemachine](https://github.com/fgmacedo/python-statemachine) by Filipe Macedo
221
+ - [RapidOCR](https://github.com/RapidAI/RapidOCR) by RapidAI contributors
@@ -7,7 +7,8 @@ PyAutoScene is a Python library that provides a declarative approach to GUI auto
7
7
  ## 🌟 Features
8
8
 
9
9
  - **Scene-Based Architecture**: Model your application as a collection of scenes with defined elements and transitions
10
- - **Visual Element Detection**: Supports both image-based element recognition. (Text recognition support coming soon!)
10
+ - **Visual Element Detection**: Supports both image-based and text-based element recognition
11
+ - **Region Specification**: Flexible region syntax for targeting specific screen areas
11
12
  - **Automatic Navigation**: Intelligent pathfinding between scenes using graph algorithms
12
13
  - **Action Decorators**: Clean, declarative syntax for defining scene actions and transitions
13
14
 
@@ -25,15 +26,15 @@ Here's how to automate a simple login flow:
25
26
 
26
27
  ```python
27
28
  import pyautogui as gui
28
- from pyautoscene import ReferenceImage, ReferenceText, Scene, Session
29
+ from pyautoscene import ImageElement, TextElement, Scene, Session
29
30
  from pyautoscene.utils import locate_and_click
30
31
 
31
32
  # Define scenes
32
33
  login = Scene(
33
34
  "Login",
34
35
  elements=[
35
- ReferenceText("Welcome to Login"),
36
- ReferenceImage("references/login_button.png"),
36
+ TextElement("Welcome to Login"),
37
+ ImageElement("references/login_button.png"),
37
38
  ],
38
39
  initial=True,
39
40
  )
@@ -41,8 +42,8 @@ login = Scene(
41
42
  dashboard = Scene(
42
43
  "Dashboard",
43
44
  elements=[
44
- ReferenceText("Dashboard"),
45
- ReferenceImage("references/user_menu.png"),
45
+ TextElement("Dashboard"),
46
+ ImageElement("references/user_menu.png"),
46
47
  ],
47
48
  )
48
49
 
@@ -75,8 +76,8 @@ A **Scene** represents a distinct state in your application's UI. Each scene con
75
76
  scene = Scene(
76
77
  "SceneName",
77
78
  elements=[
78
- ReferenceImage("path/to/image.png"),
79
- ReferenceText("Expected Text"),
79
+ ImageElement("path/to/image.png"),
80
+ TextElement("Expected Text"),
80
81
  ],
81
82
  initial=False # Set to True for starting scene
82
83
  )
@@ -86,20 +87,33 @@ scene = Scene(
86
87
 
87
88
  PyAutoScene supports two types of reference elements:
88
89
 
89
- #### ReferenceImage
90
+ #### ImageElement
90
91
 
91
92
  Detects scenes using image matching:
92
93
 
93
94
  ```python
94
- ReferenceImage("path/to/reference/image.png")
95
+ ImageElement("path/to/reference/image.png")
95
96
  ```
96
97
 
97
- #### ReferenceText
98
- (Coming soon)
98
+ #### TextElement
99
+
99
100
  Detects scenes using text recognition:
100
101
 
101
102
  ```python
102
- ReferenceText("Expected text on screen")
103
+ TextElement("Expected text on screen")
104
+ ```
105
+
106
+ Both elements support region specification for limiting search areas. You can specify regions using a string format like `"x:2/3 y:(1-2)/3"` to easily define screen regions:
107
+
108
+ ```python
109
+ # Search for text in the top-left third of the screen
110
+ TextElement("Login", region="x:1/3 y:1/3")
111
+
112
+ # Search in a horizontal band across the middle third of the screen
113
+ ImageElement("button.png", region="y:2/3")
114
+
115
+ # Search in a specific area spanning columns 1-2 out of 3 columns
116
+ TextElement("Welcome", region="x:(1-2)/3 y:1/3")
103
117
  ```
104
118
 
105
119
  ### Actions and Transitions
@@ -180,7 +194,15 @@ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENS
180
194
 
181
195
  ## 🔮 Roadmap
182
196
 
183
- - [ ] Text recognition implementation
184
197
  - [ ] Enhanced image matching algorithms
198
+ - [ ] TemplateScene
199
+ - [ ] Relation between images
185
200
  - [ ] Multiple session support
186
201
 
202
+ ## 🙏 Credits
203
+
204
+ PyAutoScene builds on the work of several open-source projects:
205
+
206
+ - [PyAutoGUI](https://github.com/asweigart/pyautogui) by Al Sweigart
207
+ - [python-statemachine](https://github.com/fgmacedo/python-statemachine) by Filipe Macedo
208
+ - [RapidOCR](https://github.com/RapidAI/RapidOCR) by RapidAI contributors
@@ -1,13 +1,14 @@
1
1
  import pyautogui as gui
2
2
 
3
- from pyautoscene import ReferenceImage, ReferenceText, Scene, Session
3
+ from pyautoscene import ImageElement, Scene, Session, TextElement
4
4
  from pyautoscene.utils import locate_and_click
5
5
 
6
6
  login = Scene(
7
7
  "Login",
8
8
  elements=[
9
- ReferenceText("Welcome to Login"),
10
- ReferenceImage("examples/saucedemo/references/login_button.png"),
9
+ TextElement("Username", region="x-1/3 y-(1-2)/3"),
10
+ TextElement("Password", region="x-1/3 y-(2-3)/3"),
11
+ # ReferenceImage("examples/saucedemo/references/login_button.png"),
11
12
  ],
12
13
  initial=True,
13
14
  )
@@ -15,17 +16,16 @@ login = Scene(
15
16
  dashboard = Scene(
16
17
  "Dashboard",
17
18
  elements=[
18
- ReferenceText("Swag Labs"),
19
- ReferenceText("Products"),
20
- ReferenceImage("examples/saucedemo/references/cart_icon.png"),
19
+ TextElement("Swag Labs", region="x-2/3 y-1/3"),
20
+ TextElement("Products", region="x-1/3 y-1/3"),
21
21
  ],
22
22
  )
23
23
 
24
24
  cart = Scene(
25
25
  "Cart",
26
26
  elements=[
27
- ReferenceText("Your Cart"),
28
- ReferenceImage("examples/saucedemo/references/cart_icon.png"),
27
+ TextElement("Your Cart", region="x-1/3 y-1/3"),
28
+ ImageElement("examples/saucedemo/references/cart_icon.png"),
29
29
  ],
30
30
  )
31
31
 
@@ -1,13 +1,13 @@
1
1
  import pyautogui as gui
2
2
 
3
- from pyautoscene import ReferenceImage, ReferenceText, Scene, Session
3
+ from pyautoscene import ImageElement, Scene, Session, TextElement
4
4
  from pyautoscene.utils import locate_and_click
5
5
 
6
6
  login = Scene(
7
7
  "Login",
8
8
  elements=[
9
- ReferenceText("Welcome to Login"),
10
- ReferenceImage("examples/saucedemo/references/login_button.png"),
9
+ TextElement("Welcome to Login"),
10
+ ImageElement("examples/saucedemo/references/login_button.png"),
11
11
  ],
12
12
  initial=True,
13
13
  )
@@ -15,17 +15,17 @@ login = Scene(
15
15
  dashboard = Scene(
16
16
  "Dashboard",
17
17
  elements=[
18
- ReferenceText("Swag Labs"),
19
- ReferenceText("Products"),
20
- ReferenceImage("examples/saucedemo/references/cart_icon.png"),
18
+ TextElement("Swag Labs"),
19
+ TextElement("Products"),
20
+ ImageElement("examples/saucedemo/references/cart_icon.png"),
21
21
  ],
22
22
  )
23
23
 
24
24
  cart = Scene(
25
25
  "Cart",
26
26
  elements=[
27
- ReferenceText("Your Cart"),
28
- ReferenceImage("examples/saucedemo/references/cart_icon.png"),
27
+ TextElement("Your Cart"),
28
+ ImageElement("examples/saucedemo/references/cart_icon.png"),
29
29
  ],
30
30
  )
31
31
 
@@ -4,17 +4,15 @@ authors = [
4
4
  ]
5
5
  dependencies = [
6
6
  "networkx>=3.5",
7
- "onnxruntime>=1.22.0",
8
7
  "pillow>=11.3.0",
9
8
  "pyautogui>=0.9.54",
10
9
  "python-statemachine[diagrams]",
11
- "rapidocr>=3.2.0",
12
10
  ]
13
11
  description = "Advance GUI automation"
14
12
  name = "pyautoscene"
15
13
  readme = "README.md"
16
14
  requires-python = ">=3.13"
17
- version = "0.1.0"
15
+ version = "0.2.0"
18
16
 
19
17
  [project.scripts]
20
18
  pyautoscene = "pyautoscene:main"
@@ -28,9 +26,17 @@ python-statemachine = {git = "https://github.com/fgmacedo/python-statemachine.gi
28
26
 
29
27
  [dependency-groups]
30
28
  dev = [
31
- "pre-commit>=4.2.0",
32
- "types-networkx>=3.5.0.20250712",
29
+ "pre-commit>=4.2.0",
30
+ "types-networkx>=3.5.0.20250712",
31
+ ]
32
+ ocr = [
33
+ "rapidocr>=3.2.0",
34
+ "onnxruntime>=1.22.0",
35
+ ]
36
+ opencv = [
37
+ "opencv-python-headless>=4.12.0.88",
33
38
  ]
34
39
 
35
40
  [tool.poe.tasks]
36
41
  precmt = "pre-commit run --all-files"
42
+
@@ -0,0 +1,5 @@
1
+ from .references import ImageElement, TextElement
2
+ from .scene import Scene
3
+ from .session import Session
4
+
5
+ __all__ = ["Scene", "Session", "ImageElement", "TextElement"]
@@ -0,0 +1,70 @@
1
+ import logging
2
+ from hashlib import sha256
3
+ from pathlib import Path
4
+
5
+ import numpy as np
6
+ from PIL import Image
7
+
8
+ from .screen import Region
9
+
10
+ logging.basicConfig(level=logging.INFO)
11
+ logger = logging.getLogger(__name__)
12
+
13
+ try:
14
+ from rapidocr import RapidOCR
15
+ from rapidocr.utils.output import RapidOCROutput
16
+ except ImportError:
17
+ raise ImportError(
18
+ "RapidOCR is not installed. Please install it using 'pip install pyautoscene[ocr]'."
19
+ )
20
+
21
+ ocr_config_path = Path(__file__).parent / "ocr_config.yaml"
22
+
23
+
24
+ def hash_image(img: Image.Image) -> str:
25
+ return sha256(img.tobytes()).hexdigest()
26
+
27
+
28
+ def convert_points_to_ltwh(points: np.ndarray) -> Region:
29
+ if points.shape[0] == 0:
30
+ raise ValueError("Points array is empty")
31
+
32
+ x_min = np.min(points[:, 0])
33
+ y_min = np.min(points[:, 1])
34
+ x_max = np.max(points[:, 0])
35
+ y_max = np.max(points[:, 1])
36
+
37
+ return Region(left=x_min, top=y_min, width=x_max - x_min, height=y_max - y_min)
38
+
39
+
40
+ class OCR:
41
+ engine: RapidOCR | None = None
42
+ img_cache: dict[str, tuple[tuple[str, Region], ...]] = {}
43
+
44
+ def __new__(cls):
45
+ if cls.engine is None:
46
+ cls.engine = RapidOCR(config_path=ocr_config_path.as_posix())
47
+ return super().__new__(cls)
48
+
49
+ def recognize_text(self, img: Image.Image) -> tuple[tuple[str, Region], ...]:
50
+ img_gray = img.convert("L")
51
+ img_hash = hash_image(img_gray)
52
+ if img_hash in self.img_cache:
53
+ logger.debug(f"Using cached result for image hash: {img_hash}")
54
+ return self.img_cache[img_hash]
55
+
56
+ assert self.engine is not None, "Engine should be initialized in __new__"
57
+ result = self.engine(np.array(img_gray))
58
+ assert isinstance(result, RapidOCROutput), (
59
+ "Result should be of type RapidOCROutput"
60
+ )
61
+ assert result.txts is not None and result.boxes is not None, (
62
+ "Text recognition failed, txts and boxes should not be None"
63
+ )
64
+
65
+ detections = tuple(
66
+ (txt, convert_points_to_ltwh(box))
67
+ for txt, box in zip(result.txts, result.boxes)
68
+ )
69
+ self.img_cache[img_hash] = detections
70
+ return detections
@@ -0,0 +1,112 @@
1
+ Global:
2
+ text_score: 0.5
3
+
4
+ use_det: true
5
+ use_cls: false
6
+ use_angle_cls: false
7
+ use_rec: true
8
+
9
+ min_height: 30
10
+ width_height_ratio: 8
11
+ max_side_len: 2000
12
+ min_side_len: 30
13
+
14
+ return_word_box: false
15
+ return_single_char_box: false
16
+
17
+ font_path: null
18
+
19
+ EngineConfig:
20
+ onnxruntime:
21
+ intra_op_num_threads: -1
22
+ inter_op_num_threads: -1
23
+ enable_cpu_mem_arena: false
24
+
25
+ cpu_ep_cfg:
26
+ arena_extend_strategy: "kSameAsRequested"
27
+
28
+ use_cuda: false
29
+ cuda_ep_cfg:
30
+ device_id: 0
31
+ arena_extend_strategy: "kNextPowerOfTwo"
32
+ cudnn_conv_algo_search: "EXHAUSTIVE"
33
+ do_copy_in_default_stream: true
34
+
35
+ use_dml: false
36
+ dm_ep_cfg: null
37
+
38
+ use_cann: false
39
+ cann_ep_cfg:
40
+ device_id: 0
41
+ arena_extend_strategy: "kNextPowerOfTwo"
42
+ npu_mem_limit: 21474836480 # 20 * 1024 * 1024 * 1024
43
+ op_select_impl_mode: "high_performance"
44
+ optypelist_for_implmode: "Gelu"
45
+ enable_cann_graph: true
46
+
47
+ openvino:
48
+ inference_num_threads: -1
49
+
50
+ paddle:
51
+ cpu_math_library_num_threads: -1
52
+ use_cuda: false
53
+ gpu_id: 0
54
+ gpu_mem: 500
55
+
56
+ torch:
57
+ use_cuda: false
58
+ gpu_id: 0
59
+
60
+ Det:
61
+ engine_type: "onnxruntime"
62
+ lang_type: "en"
63
+ model_type: "mobile"
64
+ ocr_version: "PP-OCRv4"
65
+
66
+ task_type: "det"
67
+
68
+ model_path: null
69
+ model_dir: null
70
+
71
+ limit_side_len: 736
72
+ limit_type: min
73
+ std: [ 0.5, 0.5, 0.5 ]
74
+ mean: [ 0.5, 0.5, 0.5 ]
75
+
76
+ thresh: 0.3
77
+ box_thresh: 0.5
78
+ max_candidates: 1000
79
+ unclip_ratio: 1.6
80
+ use_dilation: true
81
+ score_mode: fast
82
+
83
+ Cls:
84
+ engine_type: "onnxruntime"
85
+ lang_type: "ch"
86
+ model_type: "mobile"
87
+ ocr_version: "PP-OCRv4"
88
+
89
+ task_type: "cls"
90
+
91
+ model_path: null
92
+ model_dir: null
93
+
94
+ cls_image_shape: [3, 48, 192]
95
+ cls_batch_num: 6
96
+ cls_thresh: 0.9
97
+ label_list: ["0", "180"]
98
+
99
+ Rec:
100
+ engine_type: "onnxruntime"
101
+ lang_type: "en"
102
+ model_type: "mobile"
103
+ ocr_version: "PP-OCRv4"
104
+
105
+ task_type: "rec"
106
+
107
+ model_path: null
108
+ model_dir: null
109
+
110
+ rec_keys_path: null
111
+ rec_img_shape: [3, 48, 320]
112
+ rec_batch_num: 6
@@ -0,0 +1,78 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import override
3
+
4
+ import pyautogui as gui
5
+
6
+ from .screen import RegionSpec, generate_region_from_spec, locate_on_screen
7
+
8
+
9
+ class ReferenceElement(ABC):
10
+ """Base class for reference elements used to identify scenes."""
11
+
12
+ @abstractmethod
13
+ def is_visible(self, region: RegionSpec | None = None) -> RegionSpec | None:
14
+ """Detect the presence of the reference element."""
15
+ raise NotImplementedError("Subclasses must implement this method")
16
+
17
+
18
+ class ImageElement(ReferenceElement):
19
+ """Reference element that identifies a scene by an image."""
20
+
21
+ def __init__(
22
+ self,
23
+ path: str | list[str],
24
+ confidence: float = 0.999,
25
+ region: RegionSpec | None = None,
26
+ ):
27
+ self.path = path
28
+ self.confidence = confidence
29
+ self.region = region
30
+
31
+ @override
32
+ def is_visible(self, region: RegionSpec | None = None):
33
+ """Method to detect the presence of the image in the current screen."""
34
+ if isinstance(self.path, str):
35
+ path = [self.path] # Ensure path is a list for consistency
36
+ else:
37
+ path = self.path
38
+ for image_path in path:
39
+ try:
40
+ location = locate_on_screen(
41
+ image_path, region=region or self.region, confidence=self.confidence
42
+ )
43
+ return location
44
+ except gui.ImageNotFoundException:
45
+ continue
46
+
47
+
48
+ class TextElement(ReferenceElement):
49
+ """Reference element that identifies a scene by text."""
50
+
51
+ def __init__(
52
+ self,
53
+ text: str,
54
+ region: RegionSpec | None = None,
55
+ case_sensitive: bool = False,
56
+ ):
57
+ self.text = text
58
+ self.region = region
59
+ self.case_sensitive = case_sensitive
60
+ if not case_sensitive:
61
+ self.text = self.text.lower()
62
+
63
+ def is_visible(self, region: RegionSpec | None = None):
64
+ """Method to detect the presence of the text in the current screen."""
65
+ from .ocr import OCR
66
+
67
+ ocr = OCR()
68
+ region = region or self.region
69
+ for text, detected_region in ocr.recognize_text(
70
+ gui.screenshot(
71
+ region=generate_region_from_spec(region).to_box() if region else None
72
+ )
73
+ ):
74
+ if not self.case_sensitive:
75
+ text = text.lower()
76
+ if text.strip() == self.text.strip():
77
+ return detected_region
78
+ return None
@@ -2,12 +2,12 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Callable, TypedDict
4
4
 
5
- from pyscreeze import Box
6
5
  from statemachine import State
7
6
 
8
7
  from pyautoscene.utils import is_valid_variable_name
9
8
 
10
- from .references import ReferenceElement, ReferenceImage
9
+ from .references import ReferenceElement
10
+ from .screen import Region
11
11
 
12
12
 
13
13
  class ActionInfo(TypedDict):
@@ -51,11 +51,11 @@ class Scene(State):
51
51
  """Get an action by name."""
52
52
  return self.actions.get(action_name)
53
53
 
54
- def is_on_screen(self, region: Box | None = None) -> bool:
54
+ def is_on_screen(self, region: Region | None = None) -> bool:
55
55
  """Check if any reference element is currently on screen."""
56
56
  # TODO: Refactor after text recognition is implemented
57
- elements = (elem for elem in self.elements if isinstance(elem, ReferenceImage))
58
- return all(elem.is_visible(region) for elem in elements)
57
+ # elements = (elem for elem in self.elements if isinstance(elem, ReferenceImage))
58
+ return all(elem.is_visible(region) for elem in self.elements)
59
59
 
60
60
  def __repr__(self):
61
61
  return f"Scene({self.name!r}, elements={len(self.elements)})"
@@ -0,0 +1,79 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from dataclasses import dataclass
5
+
6
+ import numpy as np
7
+ import pyautogui as gui
8
+ from PIL import Image
9
+ from pyscreeze import Box
10
+
11
+ axis_pattern = re.compile(r"(?P<d>[xy]):\(?(?P<i>\d+)(?:-(?P<j>\d+))?\)?/(?P<n>\d+)")
12
+
13
+
14
+ @dataclass(frozen=True, slots=True)
15
+ class Region:
16
+ left: int
17
+ top: int
18
+ width: int
19
+ height: int
20
+
21
+ def to_box(self) -> Box:
22
+ """Convert to a pyscreeze Box."""
23
+ return Box(self.left, self.top, self.width, self.height)
24
+
25
+ @classmethod
26
+ def from_box(cls, box: Box) -> Region:
27
+ """Create a Region from a pyscreeze Box."""
28
+ return cls(left=box.left, top=box.top, width=box.width, height=box.height)
29
+
30
+
31
+ RegionSpec = Region | str
32
+
33
+
34
+ def generate_region_from_spec(
35
+ spec: RegionSpec, shape: tuple[int, int] | None = None
36
+ ) -> Region:
37
+ if isinstance(spec, Region):
38
+ return spec
39
+ if shape is None:
40
+ img = np.array(gui.screenshot())
41
+ shape = (img.shape[0]), (img.shape[1])
42
+
43
+ default_region = {"left": 0, "top": 0, "width": shape[1], "height": shape[0]}
44
+
45
+ axis_mapping = {"x": ("left", "width", 1), "y": ("top", "height", 0)}
46
+ for axis, i, j, n in axis_pattern.findall(spec):
47
+ alignment, size_attr, dim_index = axis_mapping[axis]
48
+ size = shape[dim_index] // int(n)
49
+ i, j = int(i), int(j) if j else int(i)
50
+ default_region.update({
51
+ alignment: (i - 1) * size,
52
+ size_attr: (j - i + 1) * size,
53
+ })
54
+
55
+ return Region(**default_region)
56
+
57
+
58
+ def locate_on_screen(
59
+ reference: Image.Image | str,
60
+ region: RegionSpec | None = None,
61
+ confidence: float = 0.999,
62
+ grayscale: bool = True,
63
+ limit: int = 1,
64
+ ) -> Region | None:
65
+ """Locate a region on the screen."""
66
+ try:
67
+ location = gui.locateOnScreen(
68
+ reference,
69
+ region=generate_region_from_spec(region).to_box() if region else None,
70
+ grayscale=grayscale,
71
+ confidence=confidence,
72
+ limit=limit,
73
+ )
74
+ if location:
75
+ return Region.from_box(location)
76
+ except gui.ImageNotFoundException:
77
+ return None
78
+ except FileNotFoundError:
79
+ return None
@@ -3,13 +3,13 @@ from __future__ import annotations
3
3
  from typing import Callable
4
4
 
5
5
  import networkx as nx
6
- from pyscreeze import Box
7
6
  from statemachine import State, StateMachine
8
7
  from statemachine.factory import StateMachineMetaclass
9
8
  from statemachine.states import States
10
9
  from statemachine.transition_list import TransitionList
11
10
 
12
11
  from .scene import Scene
12
+ from .screen import Region
13
13
 
14
14
 
15
15
  class SceneRecognitionError(Exception):
@@ -45,7 +45,7 @@ def build_dynamic_state_machine(
45
45
  return session_sm, transitions, leaf_actions
46
46
 
47
47
 
48
- def get_current_scene(scenes: list[Scene], region: Box | None = None) -> Scene:
48
+ def get_current_scene(scenes: list[Scene], region: Region | None = None) -> Scene:
49
49
  """Get the current scene from the list of scenes."""
50
50
  current_scenes = [scene for scene in scenes if scene.is_on_screen(region)]
51
51
  if len(current_scenes) == 1:
@@ -183,32 +183,30 @@ wheels = [
183
183
 
184
184
  [[package]]
185
185
  name = "numpy"
186
- version = "2.3.1"
187
- source = { registry = "https://pypi.org/simple" }
188
- sdist = { url = "https://files.pythonhosted.org/packages/2e/19/d7c972dfe90a353dbd3efbbe1d14a5951de80c99c9dc1b93cd998d51dc0f/numpy-2.3.1.tar.gz", hash = "sha256:1ec9ae20a4226da374362cca3c62cd753faf2f951440b0e3b98e93c235441d2b", size = 20390372, upload-time = "2025-06-21T12:28:33.469Z" }
189
- wheels = [
190
- { url = "https://files.pythonhosted.org/packages/d4/bd/35ad97006d8abff8631293f8ea6adf07b0108ce6fec68da3c3fcca1197f2/numpy-2.3.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:25a1992b0a3fdcdaec9f552ef10d8103186f5397ab45e2d25f8ac51b1a6b97e8", size = 20889381, upload-time = "2025-06-21T12:19:04.103Z" },
191
- { url = "https://files.pythonhosted.org/packages/f1/4f/df5923874d8095b6062495b39729178eef4a922119cee32a12ee1bd4664c/numpy-2.3.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:7dea630156d39b02a63c18f508f85010230409db5b2927ba59c8ba4ab3e8272e", size = 14152726, upload-time = "2025-06-21T12:19:25.599Z" },
192
- { url = "https://files.pythonhosted.org/packages/8c/0f/a1f269b125806212a876f7efb049b06c6f8772cf0121139f97774cd95626/numpy-2.3.1-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:bada6058dd886061f10ea15f230ccf7dfff40572e99fef440a4a857c8728c9c0", size = 5105145, upload-time = "2025-06-21T12:19:34.782Z" },
193
- { url = "https://files.pythonhosted.org/packages/6d/63/a7f7fd5f375b0361682f6ffbf686787e82b7bbd561268e4f30afad2bb3c0/numpy-2.3.1-cp313-cp313-macosx_14_0_x86_64.whl", hash = "sha256:a894f3816eb17b29e4783e5873f92faf55b710c2519e5c351767c51f79d8526d", size = 6639409, upload-time = "2025-06-21T12:19:45.228Z" },
194
- { url = "https://files.pythonhosted.org/packages/bf/0d/1854a4121af895aab383f4aa233748f1df4671ef331d898e32426756a8a6/numpy-2.3.1-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:18703df6c4a4fee55fd3d6e5a253d01c5d33a295409b03fda0c86b3ca2ff41a1", size = 14257630, upload-time = "2025-06-21T12:20:06.544Z" },
195
- { url = "https://files.pythonhosted.org/packages/50/30/af1b277b443f2fb08acf1c55ce9d68ee540043f158630d62cef012750f9f/numpy-2.3.1-cp313-cp313-manylinux_2_28_x86_64.whl", hash = "sha256:5902660491bd7a48b2ec16c23ccb9124b8abfd9583c5fdfa123fe6b421e03de1", size = 16627546, upload-time = "2025-06-21T12:20:31.002Z" },
196
- { url = "https://files.pythonhosted.org/packages/6e/ec/3b68220c277e463095342d254c61be8144c31208db18d3fd8ef02712bcd6/numpy-2.3.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:36890eb9e9d2081137bd78d29050ba63b8dab95dff7912eadf1185e80074b2a0", size = 15562538, upload-time = "2025-06-21T12:20:54.322Z" },
197
- { url = "https://files.pythonhosted.org/packages/77/2b/4014f2bcc4404484021c74d4c5ee8eb3de7e3f7ac75f06672f8dcf85140a/numpy-2.3.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a780033466159c2270531e2b8ac063704592a0bc62ec4a1b991c7c40705eb0e8", size = 18360327, upload-time = "2025-06-21T12:21:21.053Z" },
198
- { url = "https://files.pythonhosted.org/packages/40/8d/2ddd6c9b30fcf920837b8672f6c65590c7d92e43084c25fc65edc22e93ca/numpy-2.3.1-cp313-cp313-win32.whl", hash = "sha256:39bff12c076812595c3a306f22bfe49919c5513aa1e0e70fac756a0be7c2a2b8", size = 6312330, upload-time = "2025-06-21T12:25:07.447Z" },
199
- { url = "https://files.pythonhosted.org/packages/dd/c8/beaba449925988d415efccb45bf977ff8327a02f655090627318f6398c7b/numpy-2.3.1-cp313-cp313-win_amd64.whl", hash = "sha256:8d5ee6eec45f08ce507a6570e06f2f879b374a552087a4179ea7838edbcbfa42", size = 12731565, upload-time = "2025-06-21T12:25:26.444Z" },
200
- { url = "https://files.pythonhosted.org/packages/0b/c3/5c0c575d7ec78c1126998071f58facfc124006635da75b090805e642c62e/numpy-2.3.1-cp313-cp313-win_arm64.whl", hash = "sha256:0c4d9e0a8368db90f93bd192bfa771ace63137c3488d198ee21dfb8e7771916e", size = 10190262, upload-time = "2025-06-21T12:25:42.196Z" },
201
- { url = "https://files.pythonhosted.org/packages/ea/19/a029cd335cf72f79d2644dcfc22d90f09caa86265cbbde3b5702ccef6890/numpy-2.3.1-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:b0b5397374f32ec0649dd98c652a1798192042e715df918c20672c62fb52d4b8", size = 20987593, upload-time = "2025-06-21T12:21:51.664Z" },
202
- { url = "https://files.pythonhosted.org/packages/25/91/8ea8894406209107d9ce19b66314194675d31761fe2cb3c84fe2eeae2f37/numpy-2.3.1-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:c5bdf2015ccfcee8253fb8be695516ac4457c743473a43290fd36eba6a1777eb", size = 14300523, upload-time = "2025-06-21T12:22:13.583Z" },
203
- { url = "https://files.pythonhosted.org/packages/a6/7f/06187b0066eefc9e7ce77d5f2ddb4e314a55220ad62dd0bfc9f2c44bac14/numpy-2.3.1-cp313-cp313t-macosx_14_0_arm64.whl", hash = "sha256:d70f20df7f08b90a2062c1f07737dd340adccf2068d0f1b9b3d56e2038979fee", size = 5227993, upload-time = "2025-06-21T12:22:22.53Z" },
204
- { url = "https://files.pythonhosted.org/packages/e8/ec/a926c293c605fa75e9cfb09f1e4840098ed46d2edaa6e2152ee35dc01ed3/numpy-2.3.1-cp313-cp313t-macosx_14_0_x86_64.whl", hash = "sha256:2fb86b7e58f9ac50e1e9dd1290154107e47d1eef23a0ae9145ded06ea606f992", size = 6736652, upload-time = "2025-06-21T12:22:33.629Z" },
205
- { url = "https://files.pythonhosted.org/packages/e3/62/d68e52fb6fde5586650d4c0ce0b05ff3a48ad4df4ffd1b8866479d1d671d/numpy-2.3.1-cp313-cp313t-manylinux_2_28_aarch64.whl", hash = "sha256:23ab05b2d241f76cb883ce8b9a93a680752fbfcbd51c50eff0b88b979e471d8c", size = 14331561, upload-time = "2025-06-21T12:22:55.056Z" },
206
- { url = "https://files.pythonhosted.org/packages/fc/ec/b74d3f2430960044bdad6900d9f5edc2dc0fb8bf5a0be0f65287bf2cbe27/numpy-2.3.1-cp313-cp313t-manylinux_2_28_x86_64.whl", hash = "sha256:ce2ce9e5de4703a673e705183f64fd5da5bf36e7beddcb63a25ee2286e71ca48", size = 16693349, upload-time = "2025-06-21T12:23:20.53Z" },
207
- { url = "https://files.pythonhosted.org/packages/0d/15/def96774b9d7eb198ddadfcbd20281b20ebb510580419197e225f5c55c3e/numpy-2.3.1-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:c4913079974eeb5c16ccfd2b1f09354b8fed7e0d6f2cab933104a09a6419b1ee", size = 15642053, upload-time = "2025-06-21T12:23:43.697Z" },
208
- { url = "https://files.pythonhosted.org/packages/2b/57/c3203974762a759540c6ae71d0ea2341c1fa41d84e4971a8e76d7141678a/numpy-2.3.1-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:010ce9b4f00d5c036053ca684c77441f2f2c934fd23bee058b4d6f196efd8280", size = 18434184, upload-time = "2025-06-21T12:24:10.708Z" },
209
- { url = "https://files.pythonhosted.org/packages/22/8a/ccdf201457ed8ac6245187850aff4ca56a79edbea4829f4e9f14d46fa9a5/numpy-2.3.1-cp313-cp313t-win32.whl", hash = "sha256:6269b9edfe32912584ec496d91b00b6d34282ca1d07eb10e82dfc780907d6c2e", size = 6440678, upload-time = "2025-06-21T12:24:21.596Z" },
210
- { url = "https://files.pythonhosted.org/packages/f1/7e/7f431d8bd8eb7e03d79294aed238b1b0b174b3148570d03a8a8a8f6a0da9/numpy-2.3.1-cp313-cp313t-win_amd64.whl", hash = "sha256:2a809637460e88a113e186e87f228d74ae2852a2e0c44de275263376f17b5bdc", size = 12870697, upload-time = "2025-06-21T12:24:40.644Z" },
211
- { url = "https://files.pythonhosted.org/packages/d4/ca/af82bf0fad4c3e573c6930ed743b5308492ff19917c7caaf2f9b6f9e2e98/numpy-2.3.1-cp313-cp313t-win_arm64.whl", hash = "sha256:eccb9a159db9aed60800187bc47a6d3451553f0e1b08b068d8b277ddfbb9b244", size = 10260376, upload-time = "2025-06-21T12:24:56.884Z" },
186
+ version = "2.2.6"
187
+ source = { registry = "https://pypi.org/simple" }
188
+ sdist = { url = "https://files.pythonhosted.org/packages/76/21/7d2a95e4bba9dc13d043ee156a356c0a8f0c6309dff6b21b4d71a073b8a8/numpy-2.2.6.tar.gz", hash = "sha256:e29554e2bef54a90aa5cc07da6ce955accb83f21ab5de01a62c8478897b264fd", size = 20276440, upload-time = "2025-05-17T22:38:04.611Z" }
189
+ wheels = [
190
+ { url = "https://files.pythonhosted.org/packages/f9/5c/6657823f4f594f72b5471f1db1ab12e26e890bb2e41897522d134d2a3e81/numpy-2.2.6-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:0811bb762109d9708cca4d0b13c4f67146e3c3b7cf8d34018c722adb2d957c84", size = 20867828, upload-time = "2025-05-17T21:37:56.699Z" },
191
+ { url = "https://files.pythonhosted.org/packages/dc/9e/14520dc3dadf3c803473bd07e9b2bd1b69bc583cb2497b47000fed2fa92f/numpy-2.2.6-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:287cc3162b6f01463ccd86be154f284d0893d2b3ed7292439ea97eafa8170e0b", size = 14143006, upload-time = "2025-05-17T21:38:18.291Z" },
192
+ { url = "https://files.pythonhosted.org/packages/4f/06/7e96c57d90bebdce9918412087fc22ca9851cceaf5567a45c1f404480e9e/numpy-2.2.6-cp313-cp313-macosx_14_0_arm64.whl", hash = "sha256:f1372f041402e37e5e633e586f62aa53de2eac8d98cbfb822806ce4bbefcb74d", size = 5076765, upload-time = "2025-05-17T21:38:27.319Z" },
193
+ { url = "https://files.pythonhosted.org/packages/73/ed/63d920c23b4289fdac96ddbdd6132e9427790977d5457cd132f18e76eae0/numpy-2.2.6-cp313-cp313-macosx_14_0_x86_64.whl", hash = "sha256:55a4d33fa519660d69614a9fad433be87e5252f4b03850642f88993f7b2ca566", size = 6617736, upload-time = "2025-05-17T21:38:38.141Z" },
194
+ { url = "https://files.pythonhosted.org/packages/85/c5/e19c8f99d83fd377ec8c7e0cf627a8049746da54afc24ef0a0cb73d5dfb5/numpy-2.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f92729c95468a2f4f15e9bb94c432a9229d0d50de67304399627a943201baa2f", size = 14010719, upload-time = "2025-05-17T21:38:58.433Z" },
195
+ { url = "https://files.pythonhosted.org/packages/19/49/4df9123aafa7b539317bf6d342cb6d227e49f7a35b99c287a6109b13dd93/numpy-2.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1bc23a79bfabc5d056d106f9befb8d50c31ced2fbc70eedb8155aec74a45798f", size = 16526072, upload-time = "2025-05-17T21:39:22.638Z" },
196
+ { url = "https://files.pythonhosted.org/packages/b2/6c/04b5f47f4f32f7c2b0e7260442a8cbcf8168b0e1a41ff1495da42f42a14f/numpy-2.2.6-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:e3143e4451880bed956e706a3220b4e5cf6172ef05fcc397f6f36a550b1dd868", size = 15503213, upload-time = "2025-05-17T21:39:45.865Z" },
197
+ { url = "https://files.pythonhosted.org/packages/17/0a/5cd92e352c1307640d5b6fec1b2ffb06cd0dabe7d7b8227f97933d378422/numpy-2.2.6-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:b4f13750ce79751586ae2eb824ba7e1e8dba64784086c98cdbbcc6a42112ce0d", size = 18316632, upload-time = "2025-05-17T21:40:13.331Z" },
198
+ { url = "https://files.pythonhosted.org/packages/f0/3b/5cba2b1d88760ef86596ad0f3d484b1cbff7c115ae2429678465057c5155/numpy-2.2.6-cp313-cp313-win32.whl", hash = "sha256:5beb72339d9d4fa36522fc63802f469b13cdbe4fdab4a288f0c441b74272ebfd", size = 6244532, upload-time = "2025-05-17T21:43:46.099Z" },
199
+ { url = "https://files.pythonhosted.org/packages/cb/3b/d58c12eafcb298d4e6d0d40216866ab15f59e55d148a5658bb3132311fcf/numpy-2.2.6-cp313-cp313-win_amd64.whl", hash = "sha256:b0544343a702fa80c95ad5d3d608ea3599dd54d4632df855e4c8d24eb6ecfa1c", size = 12610885, upload-time = "2025-05-17T21:44:05.145Z" },
200
+ { url = "https://files.pythonhosted.org/packages/6b/9e/4bf918b818e516322db999ac25d00c75788ddfd2d2ade4fa66f1f38097e1/numpy-2.2.6-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:0bca768cd85ae743b2affdc762d617eddf3bcf8724435498a1e80132d04879e6", size = 20963467, upload-time = "2025-05-17T21:40:44Z" },
201
+ { url = "https://files.pythonhosted.org/packages/61/66/d2de6b291507517ff2e438e13ff7b1e2cdbdb7cb40b3ed475377aece69f9/numpy-2.2.6-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:fc0c5673685c508a142ca65209b4e79ed6740a4ed6b2267dbba90f34b0b3cfda", size = 14225144, upload-time = "2025-05-17T21:41:05.695Z" },
202
+ { url = "https://files.pythonhosted.org/packages/e4/25/480387655407ead912e28ba3a820bc69af9adf13bcbe40b299d454ec011f/numpy-2.2.6-cp313-cp313t-macosx_14_0_arm64.whl", hash = "sha256:5bd4fc3ac8926b3819797a7c0e2631eb889b4118a9898c84f585a54d475b7e40", size = 5200217, upload-time = "2025-05-17T21:41:15.903Z" },
203
+ { url = "https://files.pythonhosted.org/packages/aa/4a/6e313b5108f53dcbf3aca0c0f3e9c92f4c10ce57a0a721851f9785872895/numpy-2.2.6-cp313-cp313t-macosx_14_0_x86_64.whl", hash = "sha256:fee4236c876c4e8369388054d02d0e9bb84821feb1a64dd59e137e6511a551f8", size = 6712014, upload-time = "2025-05-17T21:41:27.321Z" },
204
+ { url = "https://files.pythonhosted.org/packages/b7/30/172c2d5c4be71fdf476e9de553443cf8e25feddbe185e0bd88b096915bcc/numpy-2.2.6-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e1dda9c7e08dc141e0247a5b8f49cf05984955246a327d4c48bda16821947b2f", size = 14077935, upload-time = "2025-05-17T21:41:49.738Z" },
205
+ { url = "https://files.pythonhosted.org/packages/12/fb/9e743f8d4e4d3c710902cf87af3512082ae3d43b945d5d16563f26ec251d/numpy-2.2.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f447e6acb680fd307f40d3da4852208af94afdfab89cf850986c3ca00562f4fa", size = 16600122, upload-time = "2025-05-17T21:42:14.046Z" },
206
+ { url = "https://files.pythonhosted.org/packages/12/75/ee20da0e58d3a66f204f38916757e01e33a9737d0b22373b3eb5a27358f9/numpy-2.2.6-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:389d771b1623ec92636b0786bc4ae56abafad4a4c513d36a55dce14bd9ce8571", size = 15586143, upload-time = "2025-05-17T21:42:37.464Z" },
207
+ { url = "https://files.pythonhosted.org/packages/76/95/bef5b37f29fc5e739947e9ce5179ad402875633308504a52d188302319c8/numpy-2.2.6-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:8e9ace4a37db23421249ed236fdcdd457d671e25146786dfc96835cd951aa7c1", size = 18385260, upload-time = "2025-05-17T21:43:05.189Z" },
208
+ { url = "https://files.pythonhosted.org/packages/09/04/f2f83279d287407cf36a7a8053a5abe7be3622a4363337338f2585e4afda/numpy-2.2.6-cp313-cp313t-win32.whl", hash = "sha256:038613e9fb8c72b0a41f025a7e4c3f0b7a1b5d768ece4796b674c8f3fe13efff", size = 6377225, upload-time = "2025-05-17T21:43:16.254Z" },
209
+ { url = "https://files.pythonhosted.org/packages/67/0e/35082d13c09c02c011cf21570543d202ad929d961c02a147493cb0c2bdf5/numpy-2.2.6-cp313-cp313t-win_amd64.whl", hash = "sha256:6031dd6dfecc0cf9f668681a37648373bddd6421fff6c66ec1624eed0180ee06", size = 12771374, upload-time = "2025-05-17T21:43:35.479Z" },
212
210
  ]
213
211
 
214
212
  [[package]]
@@ -262,6 +260,23 @@ wheels = [
262
260
  { url = "https://files.pythonhosted.org/packages/a4/7d/f1c30a92854540bf789e9cd5dde7ef49bbe63f855b85a2e6b3db8135c591/opencv_python-4.11.0.86-cp37-abi3-win_amd64.whl", hash = "sha256:085ad9b77c18853ea66283e98affefe2de8cc4c1f43eda4c100cf9b2721142ec", size = 39488044, upload-time = "2025-01-16T13:52:21.928Z" },
263
261
  ]
264
262
 
263
+ [[package]]
264
+ name = "opencv-python-headless"
265
+ version = "4.12.0.88"
266
+ source = { registry = "https://pypi.org/simple" }
267
+ dependencies = [
268
+ { name = "numpy" },
269
+ ]
270
+ sdist = { url = "https://files.pythonhosted.org/packages/a4/63/6861102ec149c3cd298f4d1ea7ce9d6adbc7529221606ff1dab991a19adb/opencv-python-headless-4.12.0.88.tar.gz", hash = "sha256:cfdc017ddf2e59b6c2f53bc12d74b6b0be7ded4ec59083ea70763921af2b6c09", size = 95379675, upload-time = "2025-07-07T09:21:06.815Z" }
271
+ wheels = [
272
+ { url = "https://files.pythonhosted.org/packages/f7/7d/414e243c5c8216a5277afd104a319cc1291c5e23f5eeef512db5629ee7f4/opencv_python_headless-4.12.0.88-cp37-abi3-macosx_13_0_arm64.whl", hash = "sha256:1e58d664809b3350c1123484dd441e1667cd7bed3086db1b9ea1b6f6cb20b50e", size = 37877864, upload-time = "2025-07-07T09:14:41.693Z" },
273
+ { url = "https://files.pythonhosted.org/packages/05/14/7e162714beed1cd5e7b5eb66fcbcba2f065c51b1d9da2463024c84d2f7c0/opencv_python_headless-4.12.0.88-cp37-abi3-macosx_13_0_x86_64.whl", hash = "sha256:365bb2e486b50feffc2d07a405b953a8f3e8eaa63865bc650034e5c71e7a5154", size = 57326608, upload-time = "2025-07-07T09:14:51.885Z" },
274
+ { url = "https://files.pythonhosted.org/packages/69/4e/116720df7f1f7f3b59abc608ca30fbec9d2b3ae810afe4e4d26483d9dfa0/opencv_python_headless-4.12.0.88-cp37-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:aeb4b13ecb8b4a0beb2668ea07928160ea7c2cd2d9b5ef571bbee6bafe9cc8d0", size = 33145800, upload-time = "2025-07-07T09:15:00.367Z" },
275
+ { url = "https://files.pythonhosted.org/packages/89/53/e19c21e0c4eb1275c3e2c97b081103b6dfb3938172264d283a519bf728b9/opencv_python_headless-4.12.0.88-cp37-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:236c8df54a90f4d02076e6f9c1cc763d794542e886c576a6fee46ec8ff75a7a9", size = 54023419, upload-time = "2025-07-07T09:15:10.164Z" },
276
+ { url = "https://files.pythonhosted.org/packages/bf/9c/a76fd5414de6ec9f21f763a600058a0c3e290053cea87e0275692b1375c0/opencv_python_headless-4.12.0.88-cp37-abi3-win32.whl", hash = "sha256:fde2cf5c51e4def5f2132d78e0c08f9c14783cd67356922182c6845b9af87dbd", size = 30225230, upload-time = "2025-07-07T09:15:17.045Z" },
277
+ { url = "https://files.pythonhosted.org/packages/f2/35/0858e9e71b36948eafbc5e835874b63e515179dc3b742cbe3d76bc683439/opencv_python_headless-4.12.0.88-cp37-abi3-win_amd64.whl", hash = "sha256:86b413bdd6c6bf497832e346cd5371995de148e579b9774f8eba686dee3f5528", size = 38923559, upload-time = "2025-07-07T09:15:25.229Z" },
278
+ ]
279
+
265
280
  [[package]]
266
281
  name = "packaging"
267
282
  version = "25.0"
@@ -387,11 +402,9 @@ version = "0.1.0"
387
402
  source = { editable = "." }
388
403
  dependencies = [
389
404
  { name = "networkx" },
390
- { name = "onnxruntime" },
391
405
  { name = "pillow" },
392
406
  { name = "pyautogui" },
393
407
  { name = "python-statemachine", extra = ["diagrams"] },
394
- { name = "rapidocr" },
395
408
  ]
396
409
 
397
410
  [package.dev-dependencies]
@@ -399,15 +412,20 @@ dev = [
399
412
  { name = "pre-commit" },
400
413
  { name = "types-networkx" },
401
414
  ]
415
+ ocr = [
416
+ { name = "onnxruntime" },
417
+ { name = "rapidocr" },
418
+ ]
419
+ opencv = [
420
+ { name = "opencv-python-headless" },
421
+ ]
402
422
 
403
423
  [package.metadata]
404
424
  requires-dist = [
405
425
  { name = "networkx", specifier = ">=3.5" },
406
- { name = "onnxruntime", specifier = ">=1.22.0" },
407
426
  { name = "pillow", specifier = ">=11.3.0" },
408
427
  { name = "pyautogui", specifier = ">=0.9.54" },
409
428
  { name = "python-statemachine", extras = ["diagrams"], git = "https://github.com/fgmacedo/python-statemachine.git?rev=9a089edf61b4afd4abc08968b3cfa508fa332f7c" },
410
- { name = "rapidocr", specifier = ">=3.2.0" },
411
429
  ]
412
430
 
413
431
  [package.metadata.requires-dev]
@@ -415,6 +433,11 @@ dev = [
415
433
  { name = "pre-commit", specifier = ">=4.2.0" },
416
434
  { name = "types-networkx", specifier = ">=3.5.0.20250712" },
417
435
  ]
436
+ ocr = [
437
+ { name = "onnxruntime", specifier = ">=1.22.0" },
438
+ { name = "rapidocr", specifier = ">=3.2.0" },
439
+ ]
440
+ opencv = [{ name = "opencv-python-headless", specifier = ">=4.12.0.88" }]
418
441
 
419
442
  [[package]]
420
443
  name = "pyclipper"
@@ -1,5 +0,0 @@
1
- from .references import ReferenceImage, ReferenceText
2
- from .scene import Scene
3
- from .session import Session
4
-
5
- __all__ = ["Scene", "Session", "ReferenceImage", "ReferenceText"]
@@ -1,38 +0,0 @@
1
- from abc import ABC, abstractmethod
2
-
3
- import pyautogui as gui
4
- from pyscreeze import Box
5
-
6
-
7
- class ReferenceElement(ABC):
8
- """Base class for reference elements used to identify scenes."""
9
-
10
- @abstractmethod
11
- def is_visible(self):
12
- """Detect the presence of the reference element."""
13
- raise NotImplementedError("Subclasses must implement this method")
14
-
15
-
16
- class ReferenceImage(ReferenceElement):
17
- """Reference element that identifies a scene by an image."""
18
-
19
- def __init__(self, image_path: str):
20
- self.image_path = image_path
21
-
22
- def is_visible(self, region: Box | None = None):
23
- """Method to detect the presence of the image in the current screen."""
24
- try:
25
- return gui.locateOnScreen(self.image_path, region=region)
26
- except gui.ImageNotFoundException:
27
- return None
28
-
29
-
30
- class ReferenceText(ReferenceElement):
31
- """Reference element that identifies a scene by text."""
32
-
33
- def __init__(self, text: str):
34
- self.text = text
35
-
36
- def is_visible(self):
37
- """Method to detect the presence of the text in the current screen."""
38
- raise NotImplementedError("Text recognition is not implemented yet.")
File without changes