I used ui on pythonista to make simple apps. I used to use the launcher that switches apps with one flick, so I thought about reproducing it, but I had a hard time because there was not much information in Japanese about touch, so I thought about leaving it as a memorandum.
pythonista 3 ver. 3.2 iphone 11 iOS13.2.3
I'm thinking of creating an app that gets the direction of the flick and selects the app to launch. Therefore, the program is designed to get the direction of the flick. The actual behavior is just like learning when a method is called.
touchTest.py
import scene
import numpy as np
class MyScene(scene.Scene):
def setup(self):
self.backgroud_color = '#3a3aff'
#Start and end of flick vector
self.startpoint = np.array([0, 0])
self.endpoint = np.array([0, 0])
def touch_began(self, touch):
'''Method called when touch is started'''
#Remember the start point of the vector
self.startpoint = np.array([touch.location.x, touch.loctaion.y])
#To confirm the touch, print according to the touched location.
if touch.location.x > self.size[0] / 2: #When the touch is on the right half of the screen
print('Right')
else:
print('Left')
def touch_moved(self, touch):
'''A method that is called repeatedly while touching'''
print('Moving !')
def touch_ended(self, touch):
'''Method called when you speak your finger during touch'''
#Get the end point of a vector and find the flicked vector
self.endpoint = np.array([touch.location.x, touch.loctaion.y])
vec = self.endpoint - self.startpoint
#When the start point of the vector is brought to the origin, the display is changed depending on which quadrant the end point is in.
if vec[0] >= 0 and vec[1] > 0:
print('Up right !')
elif vec[0] < 0 and vec[1] >= 0:
print('Up left')
elif vec[0] <= 0 and vec[1] < 0:
print('Down left')
elif vec[0] > 0 and vec[1] <= 0:
print('Down right')
if __name__ == '__main__':
scene.run(MyScene())
When executed, a blue screen will appear. If you touch or flick and look at the console display, you can see how it works. If the launcher application can be realized, it may be upgraded to Qiita. .. ..
I hope more people will enjoy pythonista as a hobby like myself.