Skip to content

Commit c442dbe

Browse files
committed
Provide x,y position of the last touch event directly
1 parent 8e85ec9 commit c442dbe

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

examples/drawing/draw_tool.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ def on_touch_start(self, evt):
134134
return
135135

136136
# get position
137-
touch = evt.touches[0]
138-
x, y = touch.x_pos, touch.y_pos
137+
x, y = evt.x_pos, evt.y_pos
139138
length = pero.distance(self._center, (x, y))
140139

141140
# start measure
@@ -170,8 +169,7 @@ def on_touch_move(self, evt):
170169
return
171170

172171
# get position
173-
touch = evt.touches[0]
174-
x, y = touch.x_pos, touch.y_pos
172+
x, y = evt.x_pos, evt.y_pos
175173

176174
# measure angle
177175
if self._is_measure:

pero/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) Martin Strohalm. All rights reserved.
33

44
# set version
5-
version = (0, 19, 0)
5+
version = (0, 20, 0)
66

77
# import main objects
88
from . enums import *

pero/events/touch.py

+30
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class TouchEvt(ViewEvt):
6363
6464
Attributes:
6565
66+
x_pos: int or float
67+
Last touch logical x-coordinate in device units.
68+
69+
y_pos: int or float
70+
Last touch logical y-coordinate in device units.
71+
6672
touches: (pero.Touch,)
6773
Collection of individual touches.
6874
@@ -95,6 +101,30 @@ def __init__(self, **kwargs):
95101
super().__init__(**kwargs)
96102

97103

104+
@property
105+
def x_pos(self):
106+
"""Gets x-coordinate of the last touch in device units."""
107+
108+
# check touches
109+
if not self.touches:
110+
return None
111+
112+
# return last
113+
return self.touches[-1].x_pos
114+
115+
116+
@property
117+
def y_pos(self):
118+
"""Gets y-coordinate of the last touch in device units."""
119+
120+
# check touches
121+
if not self.touches:
122+
return None
123+
124+
# return last
125+
return self.touches[-1].y_pos
126+
127+
98128
@classmethod
99129
def from_evt(cls, evt):
100130
"""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
# get version
6-
version = "0.19.0"
6+
version = "0.20.0"
77

88
# get description
99
with open("README.md", "r", encoding="utf8") as fh:

0 commit comments

Comments
 (0)