Page 1 of 2
Displaying htmltext outside of xtalk
Posted: Fri Aug 16, 2024 12:09 pm
by Skids
I'm thinking about the best way of adding documentation to a CustomControl.
I wonder if it is possible to take some htmltext that is stored within the CustomControl and have it displayed in the computers default web browser. So I'm asking how to create a html file without actually saving the file to the hard drive?
S
Re: Displaying htmltext outside of xtalk
Posted: Fri Aug 16, 2024 4:25 pm
by tperry2x
To read html data, the browser will either want to read from a file or from an online URL.
Can I ask why you didn't want to write the html file to disk?
Re: Displaying htmltext outside of xtalk
Posted: Fri Aug 16, 2024 4:32 pm
by Skids
Can I ask why you didn't want to write the html file to disk?
Because it does not seem very elegant which of course is me trying to gold plate the solution.
My thinking is to include a custom property in the group of a custom control to store the instructions as htmltext formatted text and have them displayed in a web browser. I guess the next best thing is to save the text to a file and use the launch command but that may cause SIP issues.
Re: Displaying htmltext outside of xtalk
Posted: Fri Aug 16, 2024 4:47 pm
by FourthWorld
Adding a substack with a field to display the text would be simple enough, and may add less to the file size because field text style info is stored as binary data rather than serialized with XML tag pairs
Re: Displaying htmltext outside of xtalk
Posted: Fri Aug 16, 2024 9:34 pm
by OpenXTalkPaul
Skids wrote: ↑Fri Aug 16, 2024 4:32 pm
Can I ask why you didn't want to write the html file to disk?
Because it does not seem very elegant which of course is me trying to gold plate the solution.
My thinking is to include a custom property in the group of a custom control to store the instructions as htmltext formatted text and have them displayed in a web browser. I guess the next best thing is to save the text to a file and use the launch command but that may cause SIP issues.
Well you could use the mark-down format for the documentation system that's already in place for Extensions (that's for script extensions and for extension builder modules). It's mark-down based, has a system of key/values for common info ("Author:", "Parameters:", "OS:", etc.) already worked out, and it can be parsed from inline comments in scripts so you can document your scripts as you're writing them.
Or if you want to do your own thing and keep that sort of with your custom control group or objects, you could store instructions as Text, styled RTFText, or styled as HTMLtext formatted text in a custom property, perhaps named "customControlInstructions" that is attached to the group/object itself, then place that into a field or whatever for display when the user asks to see it. Then your control could have a line of script like this:
Code: Select all
if the optionKey is down then Answer information && the customControlInstructions of me
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 6:44 am
by Skids
Well you could use the mark-down format for the documentation system that's already in place for Extensions (that's for script extensions and for extension builder modules).
Thats an interesting idea. Would it be possible to get the mark-down text show in the dictionary as an entry as it does for extension builder modules?
Or if you want to do your own thing and keep that sort of with your custom control group or objects, you could store instructions as Text, styled RTFText, or styled as HTMLtext formatted text in a custom property, perhaps named "customControlInstructions" that is attached to the group/object itself, then place that into a field or whatever for display when the user asks to see it. Then your control could have a line of script like this:
Code: Select all
Code: Select all
if the optionKey is down then Answer information && the customControlInstructions of me
I had a brief attempt at this but only with plain text which did not look very good. I will take another look to see if the answer dialog is capable of displaying styled text.
At the moment the instructions may be viewed by Ctrl Clicking on the controls icon in my tools palette but it would be good if they travelled with the control in some way or appeared as an entry in the dictionary.
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 7:56 am
by richmond62
Because it does not seem very elegant
You should see me now in front of my computer with a fan going like the clappers and 40 degrees Celsius outside: nothing round these parts
seems very elegant at the moment.
Always wondered what the word 'elegant' means in the context of computer code.
Why do I wonder if htmlText from 'somewhere' inside a stack cannot be held in the clipboard of an operating system and then copied into a browser?
So: problem #1:
Does the OXT clipboard only work inside the IDE, or does it extend beyond it?
-

- Screenshot 2024-08-17 at 11.03.15.png (262.33 KiB) Viewed 2461 times
-
Well that didn't work.
Let's try something else.
-

- Screenshot 2024-08-17 at 11.07.35.png (234.02 KiB) Viewed 2457 times
-
Only as good as far as it goes, as
does NOT put anything into my MacOS 12 clipboard.
THIS works:
Code: Select all
on mouseUp
put the htmlText of fld "ff" into fld "f2"
select the text of fld "f2"
copy
end mouseup
And I can paste it into a text editor:
-

- Screenshot 2024-08-17 at 11.14.18.png (48.35 KiB) Viewed 2455 times
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 8:17 am
by richmond62
HOWEVER:
#1 I cannot then open that in a browser and see anything but raw HTML code.
#2 I cannot paste directly into a web browser.
Trying to understand this:
https://livecode.com/use-the-web-browser/
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 8:23 am
by richmond62
This question is ever so slightly off topic (or not):
HOW do you paste HTML code into a web browser window?
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 8:27 am
by richmond62
I must be a bit stupid (OK, OK: don't answer that), but in:
Code: Select all
revBrowserSet *browser Instance id here*, "url", ("file://")
I cannot understand
*browser Instance id here*.
Hmm:
-

- Screenshot 2024-08-17 at 11.28.26.png (147.25 KiB) Viewed 2451 times
-
The 'chewy bit' seems to be that one can open a file, but it is NOT clear if one can open some code from inwith one's stack.
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 8:41 am
by richmond62
NOT a wholly origianl idea:
https://use-livecode.runrev.narkive.com ... browserset
I thought put revBrowserSet gBrowserID,”htmlText”,theContentsOfgFile might work, but it doesn’t.
As for the CEF browser I seem to remember reading something about it's the
way of the future but it is a work in progress.
9 years ago.
AND, needless-to-say:
http://quality.runrev.com/show_bug.cgi?id=13831 has mysteriously vanished.

Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 9:00 am
by richmond62
Why is this throwing 'a bluey'?
-

- Screenshot 2024-08-17 at 11.58.31.png (160.48 KiB) Viewed 2441 times
-
https://livecode.fandom.com/wiki/RevBrowserSet
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 10:38 am
by richmond62
OK: changing
https://quality.runrev.com/show_bug.cgi?id=13831
to
https://quality.livecode.com/show_bug.cgi?id=13831
won't let me in as I don't have a current licence.
Of course (!) there is probably a way with someone with a current LC licence to export the whole bug database in a way that is is accessible to all.
Shouldn't a bug database that contains bug reports re open source software also be open?
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 11:33 am
by richmond62

- Screenshot 2024-08-17 at 14.32.43.png (589.17 KiB) Viewed 2423 times
Re: Displaying htmltext outside of xtalk
Posted: Sat Aug 17, 2024 6:07 pm
by FourthWorld
richmond62 wrote: ↑Sat Aug 17, 2024 8:23 am
This question is ever so slightly off topic (or not):
HOW do you paste HTML code into a web browser window?
Where would it go?
I can't recommend strongly enough the joys of discovery to be found with even a cheap managed hosting account to learn how the web works.
Start with a simple hand-coded HTML file displaying "Hello World". Then add a little JS with alert and prompt to get the feel of how answer and ask work in that world. Then make an editable field with a submit button, and a CGI on the server to store it.
The web is a marvelous resource and ecosystem.
It is for the 21st century what HC was for 1987: a scriptable rich-media engine preinstalled on every GUI device.
Add a $5/mo managed hosting account and the world is your oyster.
Re: Displaying htmltext outside of xtalk
Posted: Sun Aug 18, 2024 7:45 am
by tperry2x
I know of a couple of ways to do this:

- browser-oxt.png (10.15 KiB) Viewed 2310 times
The first button just opens whatever your default browser is, and goes to a URL.
The second button writes and html file and opens it in your default browser.

- browser.png (22.71 KiB) Viewed 2310 times
But I know Skids didn't want to generate a file. Most browsers won't navigate to a page from having HTML code pasted into them from the clipboard, as this is seen as code injection. Far better to load from a file if at all possible.
Skids did also mention "outside of xtalk" in the title, so to me - that's in your default browser, rather than inside a htmlfield inside of the IDE or in a revBrowser widget-container-instance thing.
You could also set your xTalk script to delete the file in the background once the page is loaded:
Code: Select all
on mousedown
put the temporary folder into tTmpFolder
put tTmpFolder & slash & "hPassedURLdata.htm" into tWebFile
put "<h1>Here's some text</h1><p>This is some text, you could pass this to the browser from script</p>" into tDataToWrite
delete file tWebFile
open file tWebFile
write tDataToWrite to file tWebFile
close file tWebFile
-- go to a URL
revGoURL "file://" & tWebFile
set the tCleanupThis of me to tWebFile
send tCleanupData to me in 10 seconds -- give time for the browser to launch, and load a file.... on slow systems
end mousedown
on tCleanupData
put the tCleanupThis of me into tFilename
if there is a file tFilename then
delete file tFilename -- the file is now gone
end if
end tCleanupData
This would then delete the file after it's loaded by the browser - no file exists on disk after that, and works on all platforms.
(if you try and reload the page after my 10 second delay, the file will be gone and you'll get:)

- gone.png (19.96 KiB) Viewed 2299 times
Re: Displaying htmltext outside of xtalk
Posted: Sun Aug 18, 2024 2:05 pm
by Skids
Skids did also mention "outside of xtalk" in the title, so to me - that's in your default browser, rather than inside a htmlfield inside of the IDE or in a revBrowser widget-container-instance thing.
Yes thats exactly what I meant
You could also set your xTalk script to delete the file in the background once the page is loaded:
This is what I concluded. I will give it a try once I get back from sailing. I'm thinking of a handler named showInstructions or similar that opens the html formatted text that is stored in a custom property in the default browser. Thanks for writing it for me!
Another idea is to have the instruction text added to the dictionary but I suspect that this involves another file written in the correct format that is read when OpenXtalk loads. Again I shall investigate later.
Simon
Re: Displaying htmltext outside of xtalk
Posted: Sun Aug 18, 2024 4:10 pm
by FourthWorld
If the text is instructional material explaining how to use a tool in the IDE, what benefit leaving the IDE to display it?
OXT is very good at delivering rich media presentations. Simple text displays well. It can even include embedded images.
Re: Displaying htmltext outside of xtalk
Posted: Sun Aug 18, 2024 6:08 pm
by Skids
If the text is instructional material explaining how to use a tool in the IDE, what benefit leaving the IDE to display it?
Good question and I am open to suggestions. As you may know I am working on a palette stack to hold a collection of custom controls (built from script). The palette is capable of displaying instructions as shown in this example:

- Screenshot 2024-08-18 at 18.59.40.png (203.4 KiB) Viewed 2226 times
Working on the idea that a custom control should be self contained I am planning to include the instructions in a custom property and I was investigating how the text could be displayed. I'll probably just tell the end user to display the custom property in a field or possible have the control create a new stack on the fly and display the text there.
Thoughts?
Simon
Re: Displaying htmltext outside of xtalk
Posted: Sun Aug 18, 2024 6:48 pm
by FourthWorld
Skids wrote: ↑Sun Aug 18, 2024 6:08 pm
Thoughts?
Maybe just include a substack with a field?
viewtopic.php?p=10394#p10394