Skip to content

Commit

Permalink
zxtouch v0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan32546 committed Jan 16, 2021
1 parent 59c7946 commit 56c5fae
Show file tree
Hide file tree
Showing 91 changed files with 1,589 additions and 296 deletions.
Binary file modified Example-Scripts/.DS_Store
Binary file not shown.
File renamed without changes.
5 changes: 5 additions & 0 deletions Example-Scripts/Alert Box.bdl/alertbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from zxtouch.client import zxtouch

device = zxtouch("127.0.0.1")
device.show_alert_box("ZXTouch Demo", "This is an AlertBox and will disappear in 3 seconds", 3)
device.disconnect()
1 change: 0 additions & 1 deletion Example-Scripts/Alert Box.bdl/alertbox.raw

This file was deleted.

2 changes: 1 addition & 1 deletion Example-Scripts/Alert Box.bdl/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>Entry</key>
<string>alertbox.raw</string>
<string>alertbox.py</string>
<key>FrontApp</key>
<string>com.apple.springboard</string>
<key>Orientation</key>
Expand Down
40 changes: 12 additions & 28 deletions Example-Scripts/Color Picker.bdl/color_picker.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
import socket
from zxtouch.client import zxtouch
from zxtouch.toasttypes import *
import time

def pick_color(x, y):
x = str(x)
y = str(y)
s.send(("223;;Pick color of coordinate (" + x + ", " + y + ");;1.5\r\n").encode())
print(s.recv(1024))
time.sleep(1.5)
s.send(("23" + x + ";;" + y).encode())
data_arr = s.recv(1024).decode().split(";;")
if int(data_arr[0]) == 0:
s.send(("224;;(" + x + ", " + y + ") in RGB: (" + data_arr[1] + ", " + data_arr[2] + ", " + data_arr[3].replace("\r\n", "") + ");;2\r\n").encode())
else:
s.send(("221;;Failed. Reason: " + data_arr[1].replace("\r\n", "") + ";;2\r\n").encode())
print(s.recv(1024))

s = socket.socket()
s.connect(("127.0.0.1", 6000)) # connect to the tweak
time.sleep(0.1) # please sleep after connection.

s.send("223;;Return to home screen;;2\r\n".encode())
print(s.recv(1024))
time.sleep(2)
pick_color(100, 100)
time.sleep(2)
pick_color(200, 200)


s.close()
device = zxtouch("127.0.0.1")
device.show_toast(TOAST_MESSAGE, "Picking color from 100, 100 after 1.5 seconds...", 1.5)
time.sleep(1.5)
result_tuple = device.pick_color(100, 100)
if not result_tuple[0]:
device.show_toast(TOAST_MESSAGE, "Error while getting color. Error info: " + result_tuple[1], 1.5)
else:
result_dict = result_tuple[1]
device.show_toast(TOAST_MESSAGE, "Red: " + result_dict["red"] + ". Green: " + result_dict["green"] + ". Blue: " + result_dict["blue"], 1.5)
device.disconnect()
Binary file added Example-Scripts/Device Info.bdl/.DS_Store
Binary file not shown.
55 changes: 55 additions & 0 deletions Example-Scripts/Device Info.bdl/device_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from zxtouch.client import zxtouch
from zxtouch.toasttypes import *
import time

device = zxtouch("127.0.0.1")


# screen size
result_tuple = device.get_screen_size()
if not result_tuple[0]:
device.show_toast(TOAST_ERROR, "Cannot get screen size. Error " + result_tuple[1], 2)
device.disconnect()
exit(0)

device.show_toast(TOAST_SUCCESS, "Screen width: " + str(int(float(result_tuple[1]["width"]))) + ". Height: " + str(int(float(result_tuple[1]["height"]))), 2)
time.sleep(2)

# screen orientation and scale
result_tuple = device.get_screen_orientation()
if not result_tuple[0]:
device.show_toast(TOAST_ERROR, "Cannot get screen orientation. Error " + result_tuple[1], 2)
device.disconnect()
exit(0)

result_tuple_scale = device.get_screen_scale()
if not result_tuple_scale[0]:
device.show_toast(TOAST_ERROR, "Cannot get screen scale. Error " + result_tuple[1], 2)
device.disconnect()
exit(0)

device.show_toast(TOAST_SUCCESS, "Screen orientation: " + str(int(float(result_tuple[1][0]))) + ". Screen scale: " + str(int(float(result_tuple_scale[1][0]))), 2)
time.sleep(2)

# device info
result_tuple = device.get_device_info()
if not result_tuple[0]:
device.show_toast(TOAST_ERROR, "Cannot get device info. Error " + result_tuple[1], 2)
device.disconnect()
exit(0)

device.show_toast(TOAST_SUCCESS, "Name: " + result_tuple[1]["name"] + ". Model: " + result_tuple[1]["model"] + ". System: iOS " + result_tuple[1]["system_version"], 2)
time.sleep(2)

# battery info
result_tuple = device.get_battery_info()
if not result_tuple[0]:
device.show_toast(TOAST_ERROR, "Cannot get battery info. Error " + result_tuple[1], 2)
device.disconnect()
exit(0)

device.show_toast(TOAST_SUCCESS, "Battery Level: " + result_tuple[1]["battery_level"] + "%. Battery state: " + result_tuple[1]["battery_state_string"], 2)
time.sleep(2)

device.show_toast(TOAST_WARNING, "If you need more, please contact me on Github or Discord", 3)
time.sleep(3)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>Entry</key>
<string>opensettings.raw</string>
<string>device_info.py</string>
<key>FrontApp</key>
<string>com.apple.Preferences</string>
<string></string>
<key>Orientation</key>
<string>1</string>
</dict>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 12 additions & 25 deletions Example-Scripts/Image Matching.bdl/im.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import socket
from zxtouch.client import zxtouch
from zxtouch.toasttypes import *
import time

s = socket.socket()
s.connect(("127.0.0.1", 6000)) # connect to the tweak
time.sleep(0.1) # please sleep after connection.

s.send("223;;Opening Settings;;2\r\n".encode())
print(s.recv(1024))
time.sleep(0.1)
s.send("11com.apple.Preferences\r\n".encode())
print(s.recv(1024))
time.sleep(2)
s.send("224;;Start image matching and searching for the VPN icon;;1\r\n".encode())
print(s.recv(1024))
time.sleep(1)
s.send("222;;Please do not touch your screen until it finishes...;;20\r\n".encode())
print(s.recv(1024))
s.send("21/Library/Application Support/zxtouch/vpn.jpg;;8;;0.8;;0.8\r\n".encode())
data_arr = s.recv(1024).decode().split(";;")

if int(data_arr[0]) == 0 and float(data_arr[1]) != 0 or float(data_arr[2]) != 0 or float(data_arr[3]) != 0 or float(data_arr[4]) != 0:
s.send(("224;;Icon found!Coordinates - X: \r\n" + data_arr[1] + ". Y: " + data_arr[2] + ";;3").encode())
device = zxtouch("127.0.0.1")
device.show_toast(TOAST_WARNING, "Start matching \"examples\" string on this page", 1.5, TOAST_BUTTOM)
time.sleep(1.5)
result_tuple = device.image_match("/var/mobile/Library/ZXTouch/scripts/examples/Image Matching.bdl/examples_folder.jpg")
if not result_tuple[0]:
device.show_toast(TOAST_ERROR, "Error happened while matching. Error: " + result_tuple[1], 1.5, TOAST_BUTTOM)
else:
s.send("221;;Match Failed;;1\r\n".encode())

print(s.recv(1024))
s.close()
result_dict = result_tuple[1]
if float(result_dict["width"]) != 0 and float(result_dict["height"]) != 0:
device.show_toast(TOAST_SUCCESS, "X: " + result_dict["x"] + ". Y: " + result_dict["y"] + ". Width: " + result_dict["width"] + ". Height: " + result_dict["height"], 1.5, TOAST_BUTTOM)
device.disconnect()
2 changes: 1 addition & 1 deletion Example-Scripts/Image Matching.bdl/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>Entry</key>
<string>im.py</string>
<key>FrontApp</key>
<string>com.apple.Preferences</string>
<string>com.zjx.zxtouch</string>
<key>Orientation</key>
<string>1</string>
</dict>
Expand Down
2 changes: 0 additions & 2 deletions Example-Scripts/Open Settings.bdl/opensettings.raw

This file was deleted.

50 changes: 0 additions & 50 deletions Example-Scripts/Text Input and MORE!.bdl/keyboard-test.py

This file was deleted.

Binary file not shown.
33 changes: 33 additions & 0 deletions Example-Scripts/Text Input and MORE.bdl/keyboard-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from zxtouch.client import zxtouch
from zxtouch.toasttypes import *
import time

device = zxtouch("127.0.0.1")
device.show_toast(TOAST_MESSAGE, "Opening Notes...", 2)
time.sleep(2)
device.show_toast(TOAST_MESSAGE, "Please select an input field! 3...", 1)
time.sleep(1)

device.show_toast(TOAST_MESSAGE, "Please select an input field! 2...", 1)
time.sleep(1)

device.show_toast(TOAST_MESSAGE, "Please select an input field! 1...", 1)
time.sleep(1)

device.show_toast(TOAST_MESSAGE, "Inserting text...", 1.5)
device.insert_text("This text is generated by zxtouch!")
time.sleep(1.5)

device.show_toast(TOAST_WARNING, "Hiding the keyboard...", 1.5)
device.hide_keyboard()
time.sleep(1.5)

device.show_toast(TOAST_WARNING, "Move cursor to the left by 3 position", 1.5)
device.move_cursor(-3)
time.sleep(1.5)

device.show_toast(TOAST_WARNING, "Delete 3 characters...", 1.5)
device.insert_text("\b\b\b")
time.sleep(1.5)

device.disconnect()
29 changes: 16 additions & 13 deletions Example-Scripts/Toast.bdl/toast.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import socket


from zxtouch.client import zxtouch
from zxtouch.toasttypes import *
import time

s = socket.socket()
s.connect(("127.0.0.1", 6000)) # connect to the tweak
time.sleep(0.1) # please sleep after connection.
device = zxtouch("127.0.0.1")

s.send("221;;This is an error message toast;;1.5\r\n".encode())
print(s.recv(1024))
device.show_toast(TOAST_SUCCESS, "This is an success message toast", 1.5)
time.sleep(1.5)
s.send("222;;This is a warning message toast;;1.5\r\n".encode())
print(s.recv(1024))

device.show_toast(TOAST_ERROR, "This is an error message toast", 1.5)
time.sleep(1.5)
s.send("223;;This is a normal message toast;;1.5\r\n".encode())
print(s.recv(1024))

device.show_toast(TOAST_WARNING, "This is an warning message toast", 1.5)
time.sleep(1.5)
s.send("224;;This is a success message toast;;1.5\r\n".encode())
print(s.recv(1024))

s.close()
device.show_toast(TOAST_MESSAGE, "This is an normal message toast", 1.5)
time.sleep(1.5)

device.show_toast(TOAST_ERROR, "Toast can also be shown at bottom", 3, TOAST_BUTTOM)

device.disconnect()
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
12ZXTouch;;Hi, I am played from raw file! You can check my content at zxtouch.;;999
181172864
1011071260210586
186152
Expand Down
12 changes: 12 additions & 0 deletions Example-Scripts/Touch Simulation From Raw Data.bdl/info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Entry</key>
<string>210102110339.raw</string>
<key>FrontApp</key>
<string>com.apple.springboard</string>
<key>Orientation</key>
<string>1</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Example-Scripts/Touch Simulation.bdl/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>Entry</key>
<string>210102110339.raw</string>
<string>simulate_touch.py</string>
<key>FrontApp</key>
<string>com.apple.springboard</string>
<string>com.zjx.zxtouch</string>
<key>Orientation</key>
<string>1</string>
</dict>
Expand Down
34 changes: 34 additions & 0 deletions Example-Scripts/Touch Simulation.bdl/simulate_touch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


from zxtouch.client import zxtouch
from zxtouch.toasttypes import *
import time
from zxtouch.touchtypes import *

device = zxtouch("127.0.0.1")

device.show_toast(TOAST_WARNING, "Touching point (400, 400)", 1.5)
device.touch(TOUCH_DOWN, 1, 400, 400)
time.sleep(1.5)

device.show_toast(TOAST_WARNING, "Moving to point (400, 600)", 1.5)
device.touch(TOUCH_MOVE, 1, 400, 600)
time.sleep(1.5)

device.show_toast(TOAST_WARNING, "Touch up", 1.5)
device.touch(TOUCH_UP, 1, 400, 600)
time.sleep(1.5)

device.show_toast(TOAST_WARNING, "Touching point (100, 100)", 1.5)
device.touch(TOUCH_DOWN, 1, 100, 100)
time.sleep(0.1)
device.touch(TOUCH_UP, 1, 100, 100)
time.sleep(1.4)

device.show_toast(TOAST_WARNING, "Multitouching...Point (300, 300) and (500, 500)", 2.5)
device.touch_with_list([{"type": TOUCH_DOWN, "finger_index": 1, "x": 300, "y": 300}, {"type": TOUCH_DOWN, "finger_index": 2, "x": 500, "y": 500}])
time.sleep(1)
device.touch_with_list([{"type": TOUCH_UP, "finger_index": 1, "x": 300, "y": 300}, {"type": TOUCH_UP, "finger_index": 2, "x": 500, "y": 500}])


device.disconnect()
Empty file.
10 changes: 10 additions & 0 deletions layout/usr/lib/python3.7/site-packages/zxtouch/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TOAST_POSITION_TOP = 0
TOAST_POSITION_BOTTOM = 1
TOAST_POSITION_LEFT = 2
TOAST_POSITION_RIGHT = 3

TOAST_HIDE = 0
TOAST_ERROR = 1
TOAST_WARNING = 2
TOAST_NORMAL = 3
TOAST_SUCCESS = 4
Loading

0 comments on commit 56c5fae

Please sign in to comment.