Add event.location property.

This commit is contained in:
David Bau
2022-07-21 13:38:16 -04:00
parent 07aea7ba81
commit 5e2dc48ef7
2 changed files with 13 additions and 3 deletions
+10
View File
@@ -484,6 +484,16 @@ class Event(object):
def __repr__(self):
return f'Event({self.value}, {self.name})'
@property
def location(self):
'''
Returns the location of the event, as translated by the
target object's event_location method, if any.
'''
if self.target and hasattr(self.target, 'event_location'):
return self.target.event_location(self)
return None
entered_handler_stack = []
+3 -3
View File
@@ -493,7 +493,7 @@
},
{
"cell_type": "markdown",
"id": "d58975ba",
"id": "0e1adc74",
"metadata": {},
"source": [
"## Handling PlotWidget clicks\n",
@@ -504,14 +504,14 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ba3cbe25",
"id": "439c2809",
"metadata": {},
"outputs": [],
"source": [
"from baukit import Textbox\n",
"coord_b = Textbox()\n",
"def handle_click(e):\n",
" loc = pw.event_location(e)\n",
" loc = e.target.event_location(e)\n",
" coord_b.value = f'x,y=({loc.x:.2f}, {loc.y:.2f}) inside={loc.inside}'\n",
"pw.on('click', handle_click)\n",
"show(show.TIGHT, [['Click the previous plot to see coordinates here:', coord_b]])"