Skip to content

Commit ed2e83b

Browse files
committed
build doc test
1 parent c1bcc59 commit ed2e83b

File tree

27 files changed

+756
-68
lines changed

27 files changed

+756
-68
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Callback function documentation
2+
----
3+
4+
在 AutoControl 裡,Callback function 是由 Callback Executor 提供支援,
5+
以下是簡易的使用 Callback Executor 的範例,
6+
7+
.. code-block:: python
8+
from je_auto_control import callback_executor
9+
# trigger_function will first to execute, but return value need to wait everything done
10+
# so this test will first print("test") then print(size_function_return_value)
11+
print(
12+
callback_executor.callback_function(
13+
trigger_function_name="size",
14+
callback_function=print,
15+
callback_param_method="args",
16+
callback_function_param={"": "test"}
17+
)
18+
)
19+
20+
* ( 注意!,如果 callback_executor event_dict 裡面包含的 name: function 需與 executor 一樣,不一樣則是 Bug)
21+
* (當然跟 executor 一樣可以藉由添加外部 function 來擴充,請看下面例子)
22+
23+
-----
24+
25+
在這個範例裡,我們使用 callback_executor 執行定義在 AutoControl 的 size function,
26+
然後執行完 size function 後,會去執行傳遞給 callback_function 的 function,
27+
可以由 callback_param_method 參數來決定要使用的傳遞方法,
28+
如果是 "args" 請傳入 {"any_name_but_not_duplicate": value, ...} 這裡 ... 代表可以複數傳入,
29+
如果是 "kwargs" 請傳入 {"actually_param_name": value, ...} 這裡 ... 代表可以複數傳入,
30+
然後如果要使用回傳值的話,由於回傳值會在所有 function 執行完後才回傳,
31+
實際上 size -> print 順序沒錯,但此例會先看到 print 之後才是 print(size_function_return_value),
32+
因為 size function 只有回傳值本身沒有 print 的動作。
33+
34+
-----
35+
36+
如果我們想要在 callback_executor 裡面添加 function,可以使用如下:
37+
這段程式碼會把所有 time module 的 builtin, function, method, class
38+
載入到 callback executor,然後要使用被載入的 function 需要使用 package_function 名稱,
39+
例如 time.sleep 會變成 time_sleep
40+
41+
----
42+
43+
.. code-block:: python
44+
from je_auto_control import package_manager
45+
package_manager.add_package_to_callback_executor("time")
46+
47+
----
48+
49+
如果你需要查看被更新的 event_dict 可以使用
50+
51+
----
52+
53+
.. code-block:: python
54+
from je_auto_control import callback_executor
55+
print(callback_executor.event_dict)

Diff for: docs/source/Zh/doc/cli/cli_doc.rst

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CLI documentation
2+
----
3+
4+
----
5+
6+
我們可以使用 CLI 模式去執行 keyword.json 檔案或執行包含 Keyword.json files 的資料夾,
7+
以下這個範例是去執行指定路徑的關鍵字 json 檔
8+
9+
----
10+
11+
.. code-block::
12+
python je_auto_control --execute_file "C:\Users\JeffreyChen\Desktop\Code_Space\AutoControl\test\unit_test\argparse\test1.json"
13+
14+
15+
----
16+
17+
以下這個範例是去執行指定路徑資料夾下所有的 keyword json 檔
18+
19+
----
20+
21+
.. code-block::
22+
python je_auto_control --execute_dir "C:\Users\JeffreyChen\Desktop\Code_Space\AutoControl\test\unit_test\argparse"
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Critical Exit documentation
2+
----
3+
4+
----
5+
6+
* Critical Exit 是提供故障保護的機制。
7+
* Critical Exit 預設是關閉的。
8+
* 如果開啟,預設按鍵是 F7。
9+
* 開啟的方法是 CriticalExit().init_critical_exit()
10+
11+
----
12+
13+
以下這個範例是讓滑鼠不受控制的移動並拋出例外,
14+
當接收到例外,初始化 Critical Exit 並自動按下 F7,
15+
( 注意! 如果修改這個範例必須極度小心。 )
16+
17+
----
18+
19+
.. code-block:: python
20+
import sys
21+
22+
from je_auto_control import AutoControlMouseException
23+
from je_auto_control import CriticalExit
24+
from je_auto_control import press_key
25+
from je_auto_control import set_position
26+
from je_auto_control import size
27+
28+
# print your screen width and height
29+
30+
print(size())
31+
32+
# simulate you can't use your mouse because you use while true to set mouse position
33+
34+
try:
35+
from time import sleep
36+
37+
sleep(3)
38+
while True:
39+
set_position(200, 400)
40+
set_position(400, 600)
41+
raise AutoControlMouseException
42+
except Exception as error:
43+
print(repr(error), file=sys.stderr)
44+
CriticalExit().init_critical_exit()
45+
press_key("f7")
+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
Generate Report documentation
2+
----
3+
4+
Generate Report 可以生成以下格式的報告
5+
* HTML
6+
* JSON
7+
* XML
8+
9+
----
10+
11+
* Generate Report 主要用來記錄與確認有哪些步驟執行,執行是否成功,
12+
* 如果要使用 Generate Report 需要先設定紀錄為 True,使用 test_record_instance.init_record = True
13+
* 下面的範例有搭配 keyword and executor 如果看不懂可以先去看看 executor
14+
15+
以下是產生 HTML 的範例。
16+
17+
----
18+
19+
.. code-block:: python
20+
import sys
21+
22+
from je_auto_control import execute_action
23+
from je_auto_control import test_record_instance
24+
25+
test_list = None
26+
test_record_instance.init_record = True
27+
if sys.platform in ["win32", "cygwin", "msys"]:
28+
test_list = [
29+
["set_record_enable", {"set_enable": True}],
30+
["type_key", {"keycode": 65}],
31+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
32+
["position"],
33+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
34+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
35+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
36+
["generate_html_report"],
37+
]
38+
39+
elif sys.platform in ["linux", "linux2"]:
40+
test_list = [
41+
["set_record_enable", {"set_enable": True}],
42+
["type_key", {"keycode": 38}],
43+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
44+
["position"],
45+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
46+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
47+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
48+
["generate_html_report"],
49+
]
50+
elif sys.platform in ["darwin"]:
51+
test_list = [
52+
["set_record_enable", {"set_enable": True}],
53+
["type_key", {"keycode": 0x00}],
54+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
55+
["position"],
56+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
57+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
58+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
59+
["generate_html_report"],
60+
]
61+
print("\n\n")
62+
execute_action(test_list)
63+
64+
----
65+
66+
以下是產生 JSON 的範例。
67+
68+
----
69+
70+
.. code-block:: python
71+
import sys
72+
73+
from je_auto_control import execute_action
74+
from je_auto_control import test_record_instance
75+
76+
test_list = None
77+
test_record_instance.init_record = True
78+
if sys.platform in ["win32", "cygwin", "msys"]:
79+
test_list = [
80+
["set_record_enable", {"set_enable": True}],
81+
["type_key", {"keycode": 65}],
82+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
83+
["position"],
84+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
85+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
86+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
87+
["generate_json_report"],
88+
]
89+
90+
elif sys.platform in ["linux", "linux2"]:
91+
test_list = [
92+
["set_record_enable", {"set_enable": True}],
93+
["type_key", {"keycode": 38}],
94+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
95+
["position"],
96+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
97+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
98+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
99+
["generate_json_report"],
100+
]
101+
elif sys.platform in ["darwin"]:
102+
test_list = [
103+
["set_record_enable", {"set_enable": True}],
104+
["type_key", {"keycode": 0x00}],
105+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
106+
["position"],
107+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
108+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
109+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
110+
["generate_json_report"],
111+
]
112+
print("\n\n")
113+
execute_action(test_list)
114+
115+
----
116+
117+
以下是產生 XML 的範例。
118+
119+
----
120+
121+
.. code-block:: python
122+
import sys
123+
124+
from je_auto_control import execute_action
125+
from je_auto_control import test_record_instance
126+
127+
test_list = None
128+
test_record_instance.init_record = True
129+
if sys.platform in ["win32", "cygwin", "msys"]:
130+
test_list = [
131+
["set_record_enable", {"set_enable": True}],
132+
["type_key", {"keycode": 65}],
133+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
134+
["position"],
135+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
136+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
137+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
138+
["generate_xml_report"]
139+
]
140+
141+
elif sys.platform in ["linux", "linux2"]:
142+
test_list = [
143+
["set_record_enable", {"set_enable": True}],
144+
["type_key", {"keycode": 38}],
145+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
146+
["position"],
147+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
148+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
149+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
150+
["generate_xml_report"]
151+
]
152+
elif sys.platform in ["darwin"]:
153+
test_list = [
154+
["set_record_enable", {"set_enable": True}],
155+
["type_key", {"keycode": 0x00}],
156+
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
157+
["position"],
158+
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
159+
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
160+
["type_key", {"mouse_keycode": "dwadwawda", "dwadwad": 500, "wdawddwawad": 500}],
161+
["generate_xml_report"]
162+
]
163+
print("\n\n")
164+
execute_action(test_list)

Diff for: docs/source/Zh/doc/image/image_doc.rst

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Image documentation
2+
----
3+
4+
* Image 提供了關於圖像辨識的功能。
5+
* 定位一張圖片在螢幕中的位置。
6+
* 定位多張圖片在螢幕中的位置。
7+
* 定位圖片在螢幕中的位置並點擊。
8+
9+
----
10+
11+
以下範例是定位所有圖片
12+
13+
----
14+
15+
.. code-block:: python
16+
import time
17+
18+
from je_auto_control import locate_all_image
19+
from je_auto_control import screenshot
20+
21+
time.sleep(2)
22+
23+
# detect_threshold 0~1 , 1 is absolute equal
24+
# draw_image, mark the find target
25+
26+
image_data = locate_all_image(screenshot(), detect_threshold=0.9, draw_image=False)
27+
print(image_data)
28+
29+
----
30+
31+
以下範例是定位並點擊'圖片
32+
33+
----
34+
35+
.. code-block:: python
36+
import time
37+
38+
from je_auto_control import locate_and_click
39+
from je_auto_control import screenshot
40+
41+
time.sleep(2)
42+
43+
# detect_threshold 0~1 , 1 is absolute equal
44+
# draw_image, mark the find target
45+
image_data = locate_and_click(screenshot(), "mouse_left", detect_threshold=0.9, draw_image=False)
46+
print(image_data)
47+
48+
----
49+
50+
以下範例是定位圖片
51+
52+
----
53+
54+
.. code-block:: python
55+
import time
56+
57+
from je_auto_control import locate_image_center
58+
from je_auto_control import screenshot
59+
60+
time.sleep(2)
61+
62+
# detect_threshold 0~1 , 1 is absolute equal
63+
# draw_image, mark the find target
64+
65+
image_data = locate_image_center(screenshot(), detect_threshold=0.9, draw_image=False)
66+
print(image_data)
67+

Diff for: docs/source/Zh/doc/installation/installation_doc.rst

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Installation documentation
2+
----
3+
4+
.. code-block:: python
5+
6+
pip install je_auto_control
7+
8+
* Python & pip require version
9+
* Python 3.7 & up
10+
* pip 19.3 & up
11+
12+
* Dev env
13+
* windows 11
14+
* osx 11 big sur
15+
* ubuntu 20.0.4
16+
17+
| 如果想要在樹梅派使用
18+
.. code-block:: python
19+
20+
sudo apt-get install python3
21+
pip3 install je_auto_control
22+
sudo apt-get install libcblas-dev
23+
sudo apt-get install libhdf5-dev
24+
sudo apt-get install libhdf5-serial-dev
25+
sudo apt-get install libatlas-base-dev
26+
sudo apt-get install libjasper-dev
27+
sudo apt-get install libqtgui4
28+
sudo apt-get install libqt4-test
29+
pip3 install -U pillow
30+
pip3 install -U numpy

0 commit comments

Comments
 (0)