I have an application where tooltips are used to give information on each of a graphical array of objects. I subsequently want to use the content of the tooltip to create any particular object of interest. If the contents of the tooltip can be written to the paste buffer then I should be able to do this easily. But I haven't been able to figure out how to do this...
$\begingroup$ $\endgroup$
2 - $\begingroup$ I'm not sure Mathematica is the best tool for this. Depending on your operation system & the application you are using, there is probably a more direct way to extract the contents of a displayed tooltip, see e.g. this discussion (unless of course your "application" is a Mathematica notebook) $\endgroup$Lukas Lang– Lukas Lang2021-05-04 13:38:58 +00:00Commented May 4, 2021 at 13:38
- $\begingroup$ Thanks for that, but my application is indeed a Mathematica notebook! $\endgroup$robertofbaycot– robertofbaycot2021-05-04 15:00:46 +00:00Commented May 4, 2021 at 15:00
Add a comment |
1 Answer
$\begingroup$ $\endgroup$
2 Since you don't provide the code for your application, let's use this as example:
SeedRandom@1 Graphics[ { AbsolutePointSize@10, Tooltip[Point@#, #] & /@ RandomReal[{0, 1}, {10, 2}] } ] If we now want to be able to copy something to the clipboard, we can use EventHandler and CopyToClipboard
SeedRandom@1 Graphics[ { AbsolutePointSize@10, EventHandler[ Tooltip[Point@#, #], {"MouseClicked" :> CopyToClipboard@#} ] & /@ RandomReal[{0, 1}, {10, 2}] } ] Now, clicking on a point puts its coordinates into the clipboard. Note that it doesn't need to be a Graphics expression, EventHandler can be used anywhere where Tooltip works.
- $\begingroup$ Thanks very much for that - that looks very promising. It will take me a little while to apply it to my application. Unfortunately, my application does not lend itself to giving a brief example - I will see if I can think of something similar to illustrate it. $\endgroup$robertofbaycot– robertofbaycot2021-05-05 11:21:01 +00:00Commented May 5, 2021 at 11:21
- $\begingroup$ This works very well and is simple and versatile. Thank-you very much. One disappointment, which is down to Mathematica, not your Answer, is that Paste[] does not work as expected, so if you write x=Paste[], x is set to Null. This has been noted elsewhere here and here. $\endgroup$robertofbaycot– robertofbaycot2021-05-06 11:28:01 +00:00Commented May 6, 2021 at 11:28
