Livecode and Python?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 49
- Joined: Mon Apr 03, 2017 3:55 pm
- Location: Nova Scotia, Canada
Livecode and Python?
Hi all. I've got a request to see if I can build a front end in LiveCode that can pass lines of JSON to an emulator that's built in Python. Is that even a thing that can be done? Anyone have any experience in such alchemy?
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.
Re: Livecode and Python?
I’m no expert - but would presume the python app has some sort of interface to accept external data - REST API? CLI? File based? Something else?
If it’s one of the first 3 for sure you can do this in livecode. That would be my starting point anyway…
Let us know how you get on!
Stam
If it’s one of the first 3 for sure you can do this in livecode. That would be my starting point anyway…
Let us know how you get on!
Stam
-
- Posts: 49
- Joined: Mon Apr 03, 2017 3:55 pm
- Location: Nova Scotia, Canada
Re: Livecode and Python?
Thanks Stam. That gives me somewhere to start.
Cheers
M-A
Cheers
M-A
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.
Re: Livecode and Python?
This is easy with LiveCode...as usual!
Here is a fully working simple example.
put this in a button
then save this below as add.py into the same folder as your livecode file
now go here and look at this tutorial
https://www.tutorialspoint.com/python/p ... uments.htm
Have fun
Here is a fully working simple example.
put this in a button
Code: Select all
on mouseUp pMouseButton
--place python file in same folder as the LIveCode file
getStackPath
-- name of the python file to interface with
put "add.py" into tPythonFile
--data to be sent to the python file script
put 5 into p1
put 23 into p2
-- we don't want the consule window so hide it
set the hideConsoleWindows to true
-- shell out to the command line and pass the variabled to the python script
-- then pass the print function result into a variable in LiveCode
put shell("py " && tPythonFile && p1 && p2) into tResult
--tResult contains the returned print output from python
answer tResult
end mouseUp
command getStackPath
-- returns the path for this stack and places the
-- result in the variable tStackFolder
local tStackFile, tStackFolder
put the effective filename of this stack into tStackFile
set the itemDelimiter to "/"
put item 1 to -2 of tStackFile into tStackFolder
set the defaultFolder to tStackFolder
end getStackPath
then save this below as add.py into the same folder as your livecode file
Code: Select all
import sys
pNum1 = sys.argv[1]
pNum2 = sys.argv[2]
sum= int(pNum1) + int(pNum2)
print(sum)
now go here and look at this tutorial
https://www.tutorialspoint.com/python/p ... uments.htm
Have fun
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
-
- Posts: 49
- Joined: Mon Apr 03, 2017 3:55 pm
- Location: Nova Scotia, Canada
Re: Livecode and Python?
Hey, thank you very much Andy! Greatly appreciated!
M-A
M-A
Hypertalk developer on and off since the days of SuperCard. Currently using LC to do rapid prototyping for a new kids' toy.
Re: Livecode and Python?
Great, I've just tested it in a terminal and its super cool that it can work in this way !!
I'm wondering, what are some method names in order to pass some values to a python or julia or some other language
without opening a console ahead ?
*Can livecode do so [without opening a terminal before] ...with all other language/programs (ie julia, lua, etc) ?
- or is it something that needs specific features coded for each of those application - that is not part of livecode ?
**just learning dev by myself!
Thanks for any lights...
I'm wondering, what are some method names in order to pass some values to a python or julia or some other language
without opening a console ahead ?
*Can livecode do so [without opening a terminal before] ...with all other language/programs (ie julia, lua, etc) ?
- or is it something that needs specific features coded for each of those application - that is not part of livecode ?
**just learning dev by myself!
Thanks for any lights...
Re: Livecode and Python?
Not sure if I'm answering your question or if you knew this already, but there is the do as alternateLanguage command (details in dictionary)
- On www: do <script> as "javascript"
- On macOS: do <script> as "AppleScript" (one caveat that was recently discussed is that file paths in AppleScript need to be absolute, not relative file paths, but otherwise works very well and gives you hooks into system wide APIs that can be driven with AppleScript)
- On Win: do <script> as "VBScript" (or to be specific, according to the dictionary: On Windows systems, the alternateLanguage is an "active scripting" language (such as VBScript) supported by the Windows Scripting Host. Not sure what "active scripting languages" are available...
Re: Livecode and Python?
Thanks Stam for sharing this knowledge about Mac/Win possible use of the "do as alternateLanguage"
and no, I didnt know about still...
* I will look for what "alternateLanguage" command has available for the Linux/Ubuntu and what language it would target.
I m keeping open to some other commands for other languages beside...
Thanks a lot anyway !
and no, I didnt know about still...
* I will look for what "alternateLanguage" command has available for the Linux/Ubuntu and what language it would target.
I m keeping open to some other commands for other languages beside...
Thanks a lot anyway !
Re: Livecode and Python?
sadly I think this is Mac/Win/Web only:
Dictionary entry on Do as alternanteLanguage wrote:On other platforms, the alternateLanguage is not supported, and the do as alternateLanguage command will set the result to "alternate language not found"
Re: Livecode and Python?
Aoutch !
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Livecode and Python?
If you've got this working in a terminal window on linux and are just looking to do the same with the shell() function without having LC open a terminal window then you want the hideConsoleWindows command. The LC dictionary is wrong - ignore its note about the fact that the hideConsoleWindows command only works on Windows.Great, I've just tested it in a terminal and its super cool that it can work in this way !!
I'm wondering, what are some method names in order to pass some values to a python or julia or some other language
without opening a console ahead ?
Code: Select all
set the hideConsoleWindows to true
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev