mirror of
https://github.com/wassname/baukit.git
synced 2026-06-27 17:14:53 +08:00
Add event.location property.
This commit is contained in:
@@ -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 = []
|
||||
|
||||
|
||||
@@ -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]])"
|
||||
|
||||
Reference in New Issue
Block a user