Re: Has anyone experimented with using Python within LC?

2023-07-21 Thread Geoff Canyon via use-livecode
This stack script hacks in support for arbitrary parameters to be passed in
easily.

You can, of course, do the same by including functions in the python
script, and then calling them in the shell statement. That's how I started
this journey, but it requires escaping things to make them
shell-compatible. This might be especially weird to do because of python's
flexible handling of double and single quotes.

This way the data can be passed in as you intend to use it, the only
limitation being that it all starts as text. Still, it works a treat.

Note: this doesn't check for file existence before writing them, although
it seems unlikely that anyone would have files named
e.g. 89914707287616_data.txt. Also, this doesn't re-use any files, so
repeated calls quickly pile up. This is far from a usable function.

The round-trip cost of doing things this way is maybe something like a
tenth of a second(?) so this is likely only for when you have a lot of
backend processing to do.

local fnb
function pythonFile p
   put the filename of this stack into fp
   set the itemdel to "/"
   if fnb is empty then
  put the long seconds into fnb
  replace "." with empty in fnb
  delete char 1 to 2 of fnb
   end if
   if paramCount() > 1 then
  put "exData = {}" & cr into fileHeader
  repeat with i = 2 to paramCount()
 add 1 to fnb
 put fnb & "_data.txt" into fn
 put fn into item -1 of fp
 put param(i) into url ("file:" & fp)
 put merge("with open('[[fp]]', 'r') as f:[[cr]]") after fileHeader
 put merge("exData[ [[i - 2]] ] = f.read()[[cr]]") after
fileHeader
  end repeat
  put fileHeader & cr before p
   end if
   add 1 to fnb
   put fnb & "_temp.py" into fn
   put fn into item -1 of fp
   put p into url ("file:" & fp)
   return shell(quote & "/Users/gcanyon/opt/anaconda3/bin/python" & quote
&& quote & fp & quote)
end pythonFile

On Thu, Jul 20, 2023 at 6:20 PM Geoff Canyon  wrote:

> I just checked, and this in a stack script works perfectly:
>
> function pythonFile p
>put the filename of this stack into fp
>set the itemdel to "/"
>put the long seconds into fn
>replace "." with "_" in fn
>put "_temp.py" after fn
>put fn into item -1 of fp
>put p into url ("file:" & fp)
>return shell(quote & "" & quote && quote & fp & quote)
> end pythonFile
>
> In the real world you'd probably want to set up a single external file (or
> set of files? if performance is important and the files need to be used
> repeatedly?) and check to make sure you're not accidentally overwriting
> something.
>
> On Thu, Jul 20, 2023 at 4:07 PM Bob Sneidar via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>
>> Interesting. Ostensibly you could use low level file commands to create
>> they python file? Or does the Python script need to be processed by Python
>> first?
>>
>> Bob S
>>
>>
>> > On Jul 20, 2023, at 12:33 PM, Geoff Canyon via use-livecode <
>> use-livecode@lists.runrev.com> wrote:
>> >
>> > I've now figured out that calling a Python file from within LC is as
>> easy
>> > as:
>> >
>> > put shell(quote & "" & quote && quote &
>> > "" & quote)
>> >
>> > Then whatever gets print()'ed in Python gets returned to LC. Has anyone
>> > done work this way and has ideas on best practices for some sort of
>> >
>> > 1. generate python code
>> > 2. write python code to a file
>> > 3. write data to a (separate?) file
>> > 4. call the code
>> > 5. process the results
>> >
>> > ...loop?
>> >
>> > gc
>>
>>
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: What is your best practice for setting a script in a script?

2023-07-21 Thread Bob Sneidar via use-livecode
I wanted to ask why as well. You can put all the scripts necessary in a card, 
and if you need to know the actual object the user interacted with use the 
target command. 

Eg.

Local lTargetID

On mouseUp
   Put the long id of the target into lTargetID
   
   /*
   Your script here
   */
End mouseUp

Bob S


> On Jul 20, 2023, at 5:52 PM, Richard Gaskin via use-livecode 
>  wrote:
> 
> Paul Dupuis wrote:
>> So in the instances where you have a script that creates an object
>> and then sets the script of that object (example below), what is you
>> best practice for having the script in a script and still be readable?
>  
> Why?
>  
> Among other concerns (robustness, debugging, maintenance), setting the script 
> of an object requires turning off script encryption.
>  
> Dick Kriesel wrote:
>> 
> 
> Hi, Paul. The best way to set the script may be not to; that is, instead
>> set the new object’s behavior to a button that contains the readable script.
>  
> ^ this.
>  
> Simple, clean, with-the-grain.
>  
> Know the engine.
> Trust the engine.
> Use the engine.
>  
> --  
> Richard Gaskin
> Fourth World System

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: What is your best practice for setting a script in a script?

2023-07-21 Thread Paul Dupuis via use-livecode
As some people on this list and the forums have explored in the past, I 
have a interest in creating a Livecode application (stack) entirely from 
a (text only) single script. So there are initially no Livecode objects 
to place a behavior script in. There are initially no buttons, fields, 
cards, stacks, or anything else.


Yes, one of the values of Livecode is an interactive IDE for UI design 
(and refinement), but for this specific interest, it is all about 
creating the UI - in fact the whole app - from a single script.



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: What is your best practice for setting a script in a script?

2023-07-21 Thread Craig Newman via use-livecode
Paul.

I assume you have a blueprint of what will become a stack with at least one 
card? And that stack will possibly contain other cards, controls, scripts and 
behaviors?

But since all objects have properties, including scripts, and since LC has the 
“create” command, whatever you want to do seems straightforward, if not simple.

You must have the IDE open to even start, of course, so you are already “in” 
LC. Why not just do it the old fashioned way? The end result will be a stack, 
correct? What is the advantage of not starting with a stack?


Craig

> On Jul 21, 2023, at 12:10 PM, Paul Dupuis via use-livecode 
>  wrote:
> 
> As some people on this list and the forums have explored in the past, I have 
> a interest in creating a Livecode application (stack) entirely from a (text 
> only) single script. So there are initially no Livecode objects to place a 
> behavior script in. There are initially no buttons, fields, cards, stacks, or 
> anything else.
> 
> Yes, one of the values of Livecode is an interactive IDE for UI design (and 
> refinement), but for this specific interest, it is all about creating the UI 
> - in fact the whole app - from a single script.
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: What is your best practice for setting a script in a script?

2023-07-21 Thread Geoff Canyon via use-livecode
Way back when (in the metacard era) I wrote code to create an XML
representation of a stack, and build a copy of the stack from that
XML file.

Oh, I just checked and I still have a copy of the file. It almost certainly
does not address all the nuances that have been added since then --
behaviors, widgets, and more -- but if you want a copy you're welcome to it.

gc

On Fri, Jul 21, 2023 at 9:12 AM Paul Dupuis via use-livecode <
use-livecode@lists.runrev.com> wrote:

> As some people on this list and the forums have explored in the past, I
> have a interest in creating a Livecode application (stack) entirely from
> a (text only) single script. So there are initially no Livecode objects
> to place a behavior script in. There are initially no buttons, fields,
> cards, stacks, or anything else.
>
> Yes, one of the values of Livecode is an interactive IDE for UI design
> (and refinement), but for this specific interest, it is all about
> creating the UI - in fact the whole app - from a single script.
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Query Android Version Code

2023-07-21 Thread Dan Friedman via use-livecode
Does anyone know if there is a way to query the “Version Code” that you enter 
in the Application Settings screen?

-Dan
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Speed Improvements

2023-07-21 Thread Bob Sneidar via use-livecode
Hi all. 

I put a compiled version of Forms Generator 8 on a PC recently, and I would 
like to say that the speed improvements are very substantial from what I was 
experiencing in the past. SQL queries as well as file operation seem to be 
almost as fast as on my MacOS laptop. I would not hesitate to distribute a 
Windows app now, whereas before I would have been hard pressed. 

I will say that I streamlined my code to ensure I was not inadvertently 
re-querying for the same data, and the VM I am running it on has been migrated 
to another server, but even still I had tested on new PCs with SSD drives in 
the past and was getting disappointing results, whereas now I can hardly blink 
and a full query dataset is loaded and displayed. 

Kudos to the dev team! 

Bob S


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Question re download timeout setting

2023-07-21 Thread prothero--- via use-livecode
Folks:
Sorry for the trivial question, but..
I have an app on my iphone that I am updating from a several years old app the 
previously worked on an older version of livecode. It needs to access a mysql 
database on the internet. It works fine when there is internet service. 

I test access by downloading a file with a simple text code. If there code is 
returned in the message, I continue accessing the database. However, when there 
is no internet, the "put URL” command seems to hang forever. I’ve looked for a 
way to set the timeout for an internet command, but…. can’t,.

Could you direct me to a simple explanation about how to set a reasonable 
internet not connected message?

Thanks,
Bill
put "https://"&theURL&"/test.html"; into theURL

put URL theURL into tOutput—if the request times out, the output is not 
received.

if tOutput contains "AB7699HEYIMHERE” then   —code received, internet access is 
successful

return true

else

return false

end if


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Question re download timeout setting

2023-07-21 Thread Alex Tweedly via use-livecode


On 22/07/2023 01:02, prothero--- via use-livecode wrote:

Folks:
Sorry for the trivial question, but..
I have an app on my iphone that I am updating from a several years old app the 
previously worked on an older version of livecode. It needs to access a mysql 
database on the internet. It works fine when there is internet service.

I test access by downloading a file with a simple text code. If there code is 
returned in the message, I continue accessing the database. However, when there is 
no internet, the "put URL” command seems to hang forever. I’ve looked for a way 
to set the timeout for an internet command, but…. can’t,.

Could you direct me to a simple explanation about how to set a reasonable 
internet not connected message?


 not thoroughly tested 

You should, I think, be able to do this using tsNetSetTimeouts. But I 
wouldn't :-)


I'd do something like the following - I've tested some, but not all, 
failure cases, but haven't tested a successful url.




local sEventID

-- neverhappens.com is a website - returns "Forbidden"
-- nevehapens.com isn't, so almost immediately returns "can't be reached"
-- I didn't test a properly working case :-)

constant KURL = "http://neverhappens.com";

on mouseup
   load url kURL with message "gotareply"
   send "timetocheck failed" to me in 10 seconds -- or whatever 
timeout you want

   put the result into sEventID
end mouseup

on gotareply pURL, pURLStatus
   cancel sEventID
   timetocheck pURLStatus
end gotareply

on timetocheck pWhat
   local tAnswer
   put "time to check" && pWhat &CR after msg
   if pWhat = "loaded" then
  put URL kURL into tAnswer
  if tAnswer contains "mycode" then
 -- Internet is good
 put "Internet is good" &CR after msg
  end if
   end if
   -- Internet problematic
   put "problem" &CR after msg
   if pWhat = "error" then put libUrlErrorData(kURL) &CR after msg

   unload URL KURL
end timetocheck



Alex.


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Has anyone experimented with using Python within LC?

2023-07-21 Thread Alan Stenhouse via use-livecode
Hi Geoff

Sorry for not replying earlier but looks like you've got it sorted. I did a bit 
on this years ago and am contemplating it again. Just looked for my old stack 
and see this script for running a python script and putting the output into the 
"output" fld:


on runPythonScript pScript
   put the tempname &".py" into tFile
   put pScript into URL ("binfile:" & tFile)
   put shell("" && tFile) into fld "output"
end runPythonScript

Was starting to provide an interface for experiment parameters for the scripts 
I was running (for some Turi ML classifications) but the project paused...

cheers
Alan
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Has anyone experimented with using Python within LC?

2023-07-21 Thread Bob Sneidar via use-livecode
Out of curiosity, what can be done in in Python that cannot be done in LC 
Script? 

Sent from my iPhone

> On Jul 21, 2023, at 18:37, Alan Stenhouse via use-livecode 
>  wrote:
> 
> Hi Geoff
> 
> Sorry for not replying earlier but looks like you've got it sorted. I did a 
> bit on this years ago and am contemplating it again. Just looked for my old 
> stack and see this script for running a python script and putting the output 
> into the "output" fld:
> 
> 
> on runPythonScript pScript
>   put the tempname &".py" into tFile
>   put pScript into URL ("binfile:" & tFile)
>   put shell("" && tFile) into fld "output"
> end runPythonScript
> 
> Was starting to provide an interface for experiment parameters for the 
> scripts I was running (for some Turi ML classifications) but the project 
> paused...
> 
> cheers
> Alan
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Question re download timeout setting

2023-07-21 Thread Bob Sneidar via use-livecode
Use sockets to test the connection. 

Open socket to  
If the result is not empty then…
Close socket 

Sent from my iPhone

> On Jul 21, 2023, at 17:49, Alex Tweedly via use-livecode 
>  wrote:
> 
> 
>> On 22/07/2023 01:02, prothero--- via use-livecode wrote:
>> Folks:
>> Sorry for the trivial question, but..
>> I have an app on my iphone that I am updating from a several years old app 
>> the previously worked on an older version of livecode. It needs to access a 
>> mysql database on the internet. It works fine when there is internet service.
>> 
>> I test access by downloading a file with a simple text code. If there code 
>> is returned in the message, I continue accessing the database. However, when 
>> there is no internet, the "put URL” command seems to hang forever. I’ve 
>> looked for a way to set the timeout for an internet command, but…. can’t,.
>> 
>> Could you direct me to a simple explanation about how to set a reasonable 
>> internet not connected message?
>> 
>  not thoroughly tested 
> 
> You should, I think, be able to do this using tsNetSetTimeouts. But I 
> wouldn't :-)
> 
> I'd do something like the following - I've tested some, but not all, failure 
> cases, but haven't tested a successful url.
> 
> 
>> local sEventID
>> 
>> -- neverhappens.com is a website - returns "Forbidden"
>> -- nevehapens.com isn't, so almost immediately returns "can't be reached"
>> -- I didn't test a properly working case :-)
>> 
>> constant KURL = "http://neverhappens.com";
>> 
>> on mouseup
>>load url kURL with message "gotareply"
>>send "timetocheck failed" to me in 10 seconds -- or whatever timeout 
>> you want
>>put the result into sEventID
>> end mouseup
>> 
>> on gotareply pURL, pURLStatus
>>cancel sEventID
>>timetocheck pURLStatus
>> end gotareply
>> 
>> on timetocheck pWhat
>>local tAnswer
>>put "time to check" && pWhat &CR after msg
>>if pWhat = "loaded" then
>>   put URL kURL into tAnswer
>>   if tAnswer contains "mycode" then
>>  -- Internet is good
>>  put "Internet is good" &CR after msg
>>   end if
>>end if
>>-- Internet problematic
>>put "problem" &CR after msg
>>if pWhat = "error" then put libUrlErrorData(kURL) &CR after msg
>> 
>>unload URL KURL
>> end timetocheck
> 
> 
> Alex.
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode