Modifying what MouseText returns
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Modifying what MouseText returns
I have written a fairly decent Bible study application with LiveCode using SQL data sources and a heavily scripted single card stack.
When the mouse moves over a reference like Joh_3:16, the MouseText return Joh_3 or John chapter 3.
Is there a way to change word boundaries to use spaces or commas so that MouseText would return the whole Joh_3:16 reference? So far, I've not been able to find it.
Currently, the user can click on the reference to go to John chapter 3 but it would be nicer to get to the verse and also display the verse in a small modeless stack window.
Thanks for any help.
mat2020
When the mouse moves over a reference like Joh_3:16, the MouseText return Joh_3 or John chapter 3.
Is there a way to change word boundaries to use spaces or commas so that MouseText would return the whole Joh_3:16 reference? So far, I've not been able to find it.
Currently, the user can click on the reference to go to John chapter 3 but it would be nicer to get to the verse and also display the verse in a small modeless stack window.
Thanks for any help.
mat2020
Re: Modifying what MouseText returns
Hi.
In LiveCode, you can do anything.
The mouseText has limitations in that it does not "read" across spaces or punctuation. It really cannot grok the "format" of the text that you are interested in.
Ah, but the mouseChunk does not return text, it returns something much more powerful. Make two fields. In the first field, put some random text, but embed a chapter reference, like your "joh_3:16". Make field 2 at least three lines tall.
In the field script:
This is as wordy as you can get, but I wanted to show you how it works. The mouseChunk also is limited by punctuation (the colon) but we dont care. We already have the "location" of the text of interest, and can kludge a routine that will extract the whole.
Now then, try to reduce this to its essentials. Should be no more than about eight lines of code.
Craig
In LiveCode, you can do anything.
The mouseText has limitations in that it does not "read" across spaces or punctuation. It really cannot grok the "format" of the text that you are interested in.
Ah, but the mouseChunk does not return text, it returns something much more powerful. Make two fields. In the first field, put some random text, but embed a chapter reference, like your "joh_3:16". Make field 2 at least three lines tall.
In the field script:
Code: Select all
on mouseWithin
put the mouseChunk into fld 2
get the mouseChunk
put word 2 of it into startChar
put word 4 of it into endChar
put char startChar to endChar of me into bibleRef
if bibleRef contains "_" and char endChar + 1 of me = ":" then
put ":" after bibleRef
repeat with y = 2 to 3
if char endChar + y of me is an integer then put char endChar + y of me after bibleRef
end repeat
put bibleRef into line 3 of fld 2
end if
end mouseWithin
Now then, try to reduce this to its essentials. Should be no more than about eight lines of code.
Craig
Last edited by dunbarx on Wed May 27, 2020 11:38 pm, edited 1 time in total.
Re: Modifying what MouseText returns
Craig,
Thank you so much for this script. I figured LiveCode could do it. I will work on incorporating this.
Thanks again,
mat2020
Thank you so much for this script. I figured LiveCode could do it. I will work on incorporating this.
Thanks again,
mat2020
Re: Modifying what MouseText returns
LC greatest "basic" strength is text wrangling. Sure there are single commands that can download the entirety of the internet, but for me, the real fun is kludging.
I originally started that handler with "mouseMove", which works, but thought that mouseWithin was more local, and therefore more appropriate.
I am no scholar, but am I correct is thinking that there are no three digit verses in the bible, no "Revelations 4:243"? if there are, the repeat variable "y" needs another run. But that means you should to escape the loop if the "next" char is NOT an integer.
I still expect a much tightened handler from you...
Craig
EDIT: Paragraph 3 above. Brain fart modified...
I originally started that handler with "mouseMove", which works, but thought that mouseWithin was more local, and therefore more appropriate.
I am no scholar, but am I correct is thinking that there are no three digit verses in the bible, no "Revelations 4:243"? if there are, the repeat variable "y" needs another run. But that means you should to escape the loop if the "next" char is NOT an integer.
I still expect a much tightened handler from you...
Craig
EDIT: Paragraph 3 above. Brain fart modified...
Re: Modifying what MouseText returns
Well, it just shows what you can think of in the middle of the night.
Put this into the field script:
This one is less prolix.
I used "_" (ASCII 95) as the marker, but you could use the colon as well. Likely the colon is not as unique in your text.
Craig
Put this into the field script:
Code: Select all
on mouseWithin
if the mouseText contains "_" then answer word (the number of words of char 1 to (word 4 of the mouseChunk) of me) of me
end mouseWithin
I used "_" (ASCII 95) as the marker, but you could use the colon as well. Likely the colon is not as unique in your text.
Craig
Re: Modifying what MouseText returns
Hi Matt,
Another way to do it would be to build links for each Bible refs.
You can have a look for a Use case "Bible parsing - buil hyperlinks" ( bottom of page)
Of course, you don't have to do it my way, but the final result is quite nice actually;
the user knows what to select...
And as a side effect, there will be less code in your final app, as you could build your links
during development.
Hope this gives you some ideas,
Thierry
Last edited by Thierry on Thu Nov 17, 2022 12:10 pm, edited 1 time in total.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Modifying what MouseText returns
Hi.
Did you include the "_" just to have a fairly unique character with which to isolate the references? The only reason I ask is that it looks odd.
Why not put an invisible character into that slot? Maybe numToChar(3). Then your reference will look more normal, and you simply change to:
Craig
Did you include the "_" just to have a fairly unique character with which to isolate the references? The only reason I ask is that it looks odd.
Why not put an invisible character into that slot? Maybe numToChar(3). Then your reference will look more normal, and you simply change to:
Code: Select all
on mouseWithin
if the mouseText contains numToChar(3) then
answer word (the number of words of char 1 to (word 4 of the mouseChunk) of me) of me
end if
end mouseWithin
Re: Modifying what MouseText returns
I used the underscore so the I could easily get the Book and the Chapter using the MouseText. It was the colon then verse that threw me.
I wrote a completely text version Bible study using AutoHotkey where all the Bibles, Commentaries, Dictionaries, Reading Plans and Devotionals are kept in separate Windows INI files. It turns out with today's computers that doing sequential searches and retrievals from the INI format is pretty darn fast. About 3 seconds for any Bible search. All the Bible references in these files are in the format Book_Chapter:Verse which allows the program to double click the mouse to select a whole reference. Then I could do whatever with it.
The LiveCode program uses SQLite databases that have embedded HTML formatting which I massage a little bit on the colors and fonts.
Here is a link that shows the two programs. The LiveBible program is completely controllable via single letter commands and arrow keys.
You can take the spaces out of this web address then click on the Software page to see some screen shots.
LiveBible is the second entry on that page.
michaels - bible - notes .weebly .com
Mike (mat2020)
I wrote a completely text version Bible study using AutoHotkey where all the Bibles, Commentaries, Dictionaries, Reading Plans and Devotionals are kept in separate Windows INI files. It turns out with today's computers that doing sequential searches and retrievals from the INI format is pretty darn fast. About 3 seconds for any Bible search. All the Bible references in these files are in the format Book_Chapter:Verse which allows the program to double click the mouse to select a whole reference. Then I could do whatever with it.
The LiveCode program uses SQLite databases that have embedded HTML formatting which I massage a little bit on the colors and fonts.
Here is a link that shows the two programs. The LiveBible program is completely controllable via single letter commands and arrow keys.
You can take the spaces out of this web address then click on the Software page to see some screen shots.
LiveBible is the second entry on that page.
michaels - bible - notes .weebly .com
Mike (mat2020)
Re: Modifying what MouseText returns
Thierry,Thierry wrote: ↑Thu May 28, 2020 10:07 am
Hi Matt,
Another way to do it would be to build links for each Bible refs.
and look for a Use case "Bible parsing - buil hyperlinks" ( bottom of page)
Of course, you don't have to do it my way, but the final result is quite nice actually;
the user knows what to select...
And as a side effect, there will be less code in your final app, as you could build your links
during development.
Hope this gives you some ideas,
Thierry
Thanks for that link. It is quite an interesting piece of code.
Mike (mat2020)
Re: Modifying what MouseText returns
Yep, a colon is punctuation, and the mouseText will not "see" a string that contains punctuation as a single word. It will see the colon as its own word. The mouseChunk will not even do that. It returns empty if you hover over punctuation.It was the colon then verse that threw me.
This is expected behavior. Hence the Kludge.
Craig