How to use send_touch method in ATX

Best Python code snippet using ATX Github


Full Screen

...18 self.open_minicap_stream()19 self._display = self.display20 self.open_rotation_watcher(on_rotation_change=on_rotation_change)21 self.open_minitouch_stream()22 def send_touch(self, cmd):23 self._MinitouchStreamMixin__touch_queue.put(cmd)24 def input(self, char):25'input', 'text', char)26def get_adb(host, port, serial):27 client = Client(host, port)28 if serial is None:29 serial = list(client.devices().keys())[0]30 return AdbWrapper(client, serial)31__dir__ = os.path.dirname(os.path.abspath(__file__))32def screen_with_controls(host, port, serial, scale=0.5):33 from PIL import Image, ImageTk34 import Tkinter as tk35 import tkFileDialog36 adb = get_adb(host, port, serial)37 class Screen(object):38 def __init__(self):39 self.root = tk.Tk()40 self.root.title('Sync Screen')41 # self.image =, 'static', 'screen.png'))42 self.image = None43 self.tkimage = None44 self.canvas_image = None45 self.make_toolbar()46 self.make_canvas()47 def make_toolbar(self):48 # tools: capture, power, home, menu, back, volume_up, volume_down, turn_screen, keymapping_settings49 toolbar = tk.Frame(self.root)50 self.icons = [] # need to keep a reference for tk images. wtf.51 def capture():52 if self.image is None:53 print 'Not initialized, try later.'54 return55 d = tkFileDialog.asksaveasfilename(filetypes=(('Images', '*.png;*.jpg;'),), initialfile='screen.png')56 if not d: # canceled57 return58 if not d.endswith('.png') and not d.endswith('.jpg'):59 d += '.png'60 print 'Save to', d61 icon = ImageTk.PhotoImage(file=os.path.join(__dir__, 'static', 'icons', 'save.ico'))63 tk.Button(toolbar, image=icon, command=capture).pack(side=tk.LEFT, padx=2, pady=2)64 self.icons.append(icon)65 # def rotate():66 # print 'rotate screen (Not Implemented yet.)'67 # icon = ImageTk.PhotoImage(file=os.path.join(__dir__, 'static', 'icons', 'rotate.ico'))68 # tk.Button(toolbar, image=icon, command=rotate).pack(side=tk.LEFT, padx=2, pady=2)69 # self.icons.append(icon)70 for key in ('power', 'home', 'menu', 'back', 'volume_up', 'volume_down'):71 icon = ImageTk.PhotoImage(file=os.path.join(__dir__, 'static', 'icons', '%s.ico' % key))72 self.icons.append(icon)73 b = tk.Button(toolbar, image=icon, command=lambda k=key:adb.keyevent('KEYCODE_%s' % k.upper()))74 b.pack(side=tk.LEFT, padx=2, pady=2)75 toolbar.pack(side=tk.TOP, fill=tk.X)76 def make_canvas(self):77 # screen canvas, bind mouse input & keyboard input78 self.canvas = tk.Canvas(self.root, bg='black', bd=0, highlightthickness=0)79 self.canvas.pack()80 def screen2touch(x, y):81 '''convert touch position'''82 w, h, o = adb._display83 if o == 0:84 return x, y85 elif o == 1: # landscape-right86 return w-y, x87 elif o == 2: # upsidedown88 return w-x, h-y89 elif o == 3: # landscape-left90 return y, h-x91 return x, y92 93 def on_mouse_down(event):94 self.canvas.focus_set()95 x, y = int(event.x/scale), int(event.y/scale)96 x, y = screen2touch(x, y)97 adb.send_touch('d 0 %d %d 30\nc\n' % (x, y))98 def on_mouse_up(event):99 adb.send_touch('u 0\nc\n')100 def on_mouse_drag(event):101 x, y = int(event.x/scale), int(event.y/scale)102 x, y = screen2touch(x, y)103 adb.send_touch('m 0 %d %d 30\nc\n' % (x, y))104 self.canvas.bind('<ButtonPress-1>', on_mouse_down)105 self.canvas.bind('<ButtonRelease-1>', on_mouse_up)106 self.canvas.bind('<B1-Motion>', on_mouse_drag)107 keymap = {'\r':'KEYCODE_ENTER', ' ':'KEYCODE_SPACE', '\x08':'KEYCODE_DEL', }108 def on_key(event):109 c = event.char110 # print 'key pressed', repr(c), type(c)111 if c in 'adbcdefghijklmnopqrstuvwxyz0123456789':112 adb.input(c)113 return 'break'114 if c in keymap:115 adb.keyevent(keymap[c])116 return 'break'117 self.canvas.bind('<Key>', on_key)...

Full Screen

Full Screen Github


Full Screen

...36 send_values(soundtouch_id,'Off')37 else:38 print("Soundtouch run !")39 send_values(soundtouch_id,'On')40def send_touch(button):41 if(button == 'POWER_ON' and get_soudtouch_state() == 'On'):42 return43 if(button == 'POWER_OFF' and get_soudtouch_state() == 'Off'):44 return45 if(button == 'POWER_OFF' or button == 'POWER_ON'):46 button = 'POWER'47 url = 'http://'+soundtouch_ip+'/key'48 #appui49 dataXml = '<?xml version="1.0" encoding="UTF-8" ?><key state="press" sender="Gabbo">'+button+'</key>'50, data=dataXml)51################# Call52if(len(sys.argv) > 1 and sys.argv[1] == "send_touch"):53 send_touch(sys.argv[2])54elif(len(sys.argv) == 1):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?