|
Post by ptitjoz on Apr 13, 2023 14:46:16 GMT 1
Hello everyone. Take this little program as an example.
INCLUDE "hug.bac"
Win1 = WINDOW( "test_pyhon_console.bac", 300,300 )
OPEN "carre.py" FOR WRITING AS python WRITELN "from turtle import *" TO python WRITELN "setup(300,300)" TO python WRITELN "title('test python turtle')" TO python WRITELN "pendown()" TO python WRITELN "for i in range(4):" TO python WRITELN " forward(40)" TO python WRITELN " left(90)" TO python WRITELN "penup()" TO python WRITELN "hideturtle()" TO python WRITELN "mainloop() # pour que la fenetre reste ouverte" TO python CLOSE FILE python
SUB SubExe SYSTEM "python3 carre.py" END SUB
BoutonExe = STOCK("gtk-ok", 80,25) ATTACH( Win1, BoutonExe, 10,200) CALLBACK(BoutonExe,SubExe)
BoutonQuitter = STOCK("gtk-quit", 80, 25) ATTACH( Win1, BoutonQuitter, 110,200 ) CALLBACK(BoutonQuitter, QUIT) DISPLAY
I generate a turtle file in python in carre.py file I run the program bacon which works well. The 2 problems I'm having are: - I have to close the turtle window by the cross at the top right and with bacon I don't know how to do it
- I can run the turtle window launch multiple times and that's not the intended purpose.
I searched if there was a "console" widget but couldn't find it. (a bit like canvas)
Do you have any ideas to help me? Thanks in advance
Best Regards
|
|
|
Post by alexfish on Apr 13, 2023 17:45:57 GMT 1
Code works on rpi
IE: I left button click on the X of the drawing
but can try
SUB SubExe SYSTEM "python3 carre.py &" END SUB
Beyond that ?
the default terminal for hug uses xterm if not installed
sudo apt install xterm IF in then can leave code as is
SUB SubExe SYSTEM "python3 carre.py " END SUB
closing the term closes all BR Alex
|
|
|
Post by alexfish on Apr 13, 2023 19:19:58 GMT 1
Hi ptitjoz & All Further to console terminals
' (1) xterm -sb -geometry 132x40 -e '@; read' ' (2) rxvt -geometry 132x40 -e /bin/bash -c '@; read' ' (3) gnome-terminal --geometry 132x40 -e "/bin/bash -c '@; read'" ' (4) lxterminal --geometry=80x20 --command="/bin/bash -c 'time @; read'" ' (5) konsole --noclose --vt_sz 80x25 -e @ ' (6) xfce4-terminal --geometry 132x40 -e "/bin/bash -c '@; read'" ' (7) MacOSX: mrxvt -hold 1 -e @ ' (8) MacOSX: open @
use
.bacon/settings.cfg
BR Alex
|
|
|
Post by ptitjoz on Apr 13, 2023 20:26:13 GMT 1
Thanks for all the advice and research! To clarify my thoughts (as I hardly speak English, it's not easy) I would like when a turtle window is in action not to be able to launch a second execution (hide the Exec button) and to be able to close the turtle window only with a Hug button (and redisplay the Exec button) I don't want the cross closing of the turtle window to close everything... I don't know if I'm more explicit... Sorry
Best regards
|
|
|
Post by alexfish on Apr 13, 2023 20:39:51 GMT 1
Could have fooled me
SUB SubExe HIDE(BoutonExe) SYNC PRINT "hide" B$ = EXEC$("python3 carre.py") SHOW(BoutonExe) PRINT "show" END SUB
that will hold till you close the python window more to follow next post it be a will since we have had this type of request & will run through the options and next time it will be on this thread + can save each bit I say that in terms of "the app is launched by python" so depending on the ruling python 'python or python3 will be the app but note that your bit is specific "python3" here can check with the task manager I think say's he
BR Alex
|
|
|
Post by alexfish on Apr 13, 2023 21:31:56 GMT 1
In First instance :: File handling
can suggest
INCLUDE "hug.bac" HOME$ = GETENVIRON$("HOME") PRINT HOME$ Win1 = WINDOW( "test_pyhon_console.bac", 300,300 )
DISPLAY
more to follow ::
|
|
|
Post by ptitjoz on Apr 13, 2023 21:34:24 GMT 1
Could have fooled me SUB SubExe HIDE(BoutonExe) SYNC PRINT "hide" B$ = EXEC$("python3 carre.py") SHOW(BoutonExe) PRINT "show" END SUB
that will hold till you close the python window more to follow next post it be a will since we have had this type of request & will run through the options and next time it will be on this thread + can save each bit I say that in terms of "the app is launched by python" so depending on the ruling python 'python or python3 will be the app but note that your bit is specific "python3" here can check with the task manager I think say's he BR Alex Thanks alexfish! I just tried it and it gives me satisfaction. I haven't yet mastered the difference between SYSTEM and EXEC$ and I hadn't thought of SYNC. For the moment my situation is unblocked and I can continue on my project. I will check if there are other answers on this post. Best regards
|
|
|
Post by alexfish on Apr 13, 2023 21:40:51 GMT 1
finding the file
INCLUDE "hug.bac" HOME$ = GETENVIRON$("HOME") PRINT HOME$ '===================================== IF FILEEXISTS(HOME$ & "/carre.py") THEN PRINT "carre.py found" ELSE PRINT "carre.py not found" END IF '===================================== ' MAIN Win1 = WINDOW( "test_pyhon_console.bac", 300,300 )
DISPLAY
|
|
|
Post by ptitjoz on Apr 13, 2023 21:57:27 GMT 1
As I do not work in the Home but in sub-folders, I necessarily have a "not found" by this method. I would have to test the full path.
|
|
|
Post by alexfish on Apr 13, 2023 22:53:37 GMT 1
As I do not work in the Home but in sub-folders, I necessarily have a "not found" by this method. I would have to test the full path. this is an example , possible by same token OPEN "carre.py" FOR WRITING AS python bits in root are different but if have the files in path = HOME/dir1/dir2/myfile what you say is correct , but using HOME$ your app will work on any distro where I sit this id home is where pi = usr it could be mac /tommy /rob :: instance /foo/bagh/file /home/pi so to some new bits in bacon LOAD$ and SAVE, but can use any style of course , user:: edit the path to fileINCLUDE "hug.bac" HOME$ = GETENVIRON$("HOME") PRINT HOME$ ' bacon now has LOAD 'file' & SAVE 'file' IF NOT(FILEEXISTS(HOME$ & "/carre.py")) THEN PRINT "make " & HOME$ & "/carre.py" mydata$ = "from turtle import *" & NL$ & \ "from turtle import *" & NL$ & \ "from turtle import *" & NL$ & \ "setup(300,300)" & NL$ & \ "title('test python turtle')" & NL$ & \ "pendown()" & NL$ & \ "for i in range(4):" & NL$ & \ " forward(40)" & NL$ & \ " left(90)" & NL$ & \ "penup()" & NL$ & \ "hideturtle()" & NL$ & \ "mainloop() # pour que la fenetre reste ouverte" PRINT mydata$ SAVE mydata$ TO HOME$ & "/carre.py" ELSE PRINT "Found " & HOME$ & "/carre.py" mydata$ = LOAD$(HOME$ & "/carre.py") PRINT mydata$ END IF
SUB SubExe IF FILEEXISTS(HOME$ & "/carre.py") THEN HIDE(BoutonExe) SYNC PRINT "hide" B$ = EXEC$("python3 " & HOME$ & "/carre.py") SHOW(BoutonExe) PRINT "show" ELSE PRINT HOME$ & "/carre.py" & " not found" END IF END SUB
Win1 = WINDOW( "test_pyhon_console.bac", 300,300 ) BoutonExe = STOCK("gtk-ok", 80,25) ATTACH( Win1, BoutonExe, 10,200) CALLBACK(BoutonExe,SubExe)
BoutonQuitter = STOCK("gtk-quit", 80, 25) ATTACH( Win1, BoutonQuitter, 110,200 ) CALLBACK(BoutonQuitter, QUIT) DISPLAY next will look further into :: Have Fun + BR Alex
|
|
|
Post by alexfish on Apr 14, 2023 0:46:28 GMT 1
Here getting feedback in the python script have put print delete existing file Edit the path to file INCLUDE "hug.bac" HOME$ = GETENVIRON$("HOME") PRINT HOME$ ' bacon now has LOAD 'file' & SAVE 'file' IF NOT(FILEEXISTS(HOME$ & "/carre.py")) THEN PRINT "make " & HOME$ & "/carre.py" mydata$ = "from turtle import *" & NL$ & \ "from turtle import *" & NL$ & \ "from turtle import *" & NL$ & \ "setup(300,300)" & NL$ & \ "title('test python turtle')" & NL$ & \ "pendown()" & NL$ & \ "for i in range(4):" & NL$ & \ " forward(40)" & NL$ & \ " left(90)" & NL$ & \ "penup()" & NL$ & \ "hideturtle()" & NL$ & \ "mainloop() # pour que la fenetre reste ouverte" & NL$ & \ "print('done')" PRINT mydata$ SAVE mydata$ TO HOME$ & "/carre.py" ELSE PRINT "Found " & HOME$ & "/carre.py" mydata$ = LOAD$(HOME$ & "/carre.py") PRINT mydata$ END IF
SUB SubExe IF FILEEXISTS(HOME$ & "/carre.py") THEN HIDE(BoutonExe) SYNC B$ = EXEC$("python3 " & HOME$ & "/carre.py") SHOW(BoutonExe) PRINT "Recieved ", B$ ELSE PRINT HOME$ & "/carre.py" & " not found" END IF END SUB
Win1 = WINDOW( "test_pyhon_console.bac", 300,300 ) BoutonExe = STOCK("gtk-ok", 80,25) ATTACH( Win1, BoutonExe, 10,200) CALLBACK(BoutonExe,SubExe)
BoutonQuitter = STOCK("gtk-quit", 80, 25) ATTACH( Win1, BoutonQuitter, 110,200 ) CALLBACK(BoutonQuitter, QUIT) DISPLAY run the app then close the python app Have Fun + BR Alex Attachments:
|
|
|
Post by alexfish on Apr 14, 2023 11:33:49 GMT 1
SUB AND FUNCTIONS :: EXIT
SUB SubExe2
IF NOT(FILEEXISTS(HOME$ & "/carre.py")) THEN PRINT HOME$ & "/carre.py" & " not found" EXIT END IF HIDE(BoutonExe) SYNC B$ = EXEC$("python3 " & HOME$ & "/carre.py") SHOW(BoutonExe) PRINT "Recieved ", B$ END SUB
Next :: I not done this for a while , and in your case > run Python -> app , possible not best approach since need to find 'pidof' catch the pidof directly after the call 'SYSTEM ("python3 " & HOME$ & "/carre.py &")
SUB SubExe2
IF NOT(FILEEXISTS(HOME$ & "/carre.py")) THEN PRINT HOME$ & "/carre.py" & " not found" EXIT END IF HIDE(BoutonExe) SYNC SYSTEM ("python3 " & HOME$ & "/carre.py &") B$ = EXEC$("pidof -s python3") PRINT "pid of : ", B$ SHOW(BoutonExe) END SUB
but if other prog in use by means of run Python -> app :: the could be many python3's same applies to bash
|
|
|
Post by alexfish on Apr 14, 2023 12:39:34 GMT 1
Add your Button
INCLUDE "hug.bac" HOME$ = GETENVIRON$("HOME") PRINT HOME$ GLOBAL py_pid ' bacon now has LOAD 'file' & SAVE 'file' IF NOT(FILEEXISTS(HOME$ & "/carre.py")) THEN PRINT "make " & HOME$ & "/carre.py" mydata$ = "from turtle import *" & NL$ & \ "setup(300,300)" & NL$ & \ "title('test python turtle')" & NL$ & \ "pendown()" & NL$ & \ "for i in range(4):" & NL$ & \ " forward(40)" & NL$ & \ " left(90)" & NL$ & \ "penup()" & NL$ & \ "hideturtle()" & NL$ & \ "mainloop() # pour que la fenetre reste ouverte"
PRINT mydata$ SAVE mydata$ TO HOME$ & "/carre.py" ELSE PRINT "Found " & HOME$ & "/carre.py" mydata$ = LOAD$(HOME$ & "/carre.py") PRINT mydata$ END IF
SUB SubExe
IF NOT(FILEEXISTS(HOME$ & "/carre.py")) THEN PRINT HOME$ & "/carre.py" & " not found" EXIT END IF
IF py_pid THEN PRINT "carre running" EXIT END IF
SYSTEM ("python3 " & HOME$ & "/carre.py &") B$ = EXEC$("pidof -s python3") py_pid = VAL(B$) PRINT "pid of : ", B$
END SUB
SUB KillApp IF py_pid THEN cmd$ = "kill -9 " & STR$(py_pid) SYSTEM ( cmd$ ) B$ = EXEC$("pidof -s python3") PRINT " pid of ", B$ py_pid = 0 END IF
END SUB
Win1 = WINDOW( "test_pyhon_console.bac", 300,300 ) BoutonExe = STOCK("gtk-ok", 80,25) ATTACH( Win1, BoutonExe, 10,200) CALLBACK(BoutonExe,SubExe)
' want width of widget to expand in a direction use -1 Boutonkill = BUTTON("Kill app", -1,25) ATTACH( Win1, Boutonkill, 3,3) CALLBACK(Boutonkill,KillApp)
BoutonQuitter = STOCK("gtk-quit", 80, 25) ATTACH( Win1, BoutonQuitter, 110,200 ) CALLBACK(BoutonQuitter, QUIT) DISPLAY
have test launching several execs from the bacon gui and all looking good BR Alex Attachments:
|
|
|
Post by ptitjoz on Apr 14, 2023 17:33:26 GMT 1
Hello alexfish Thank you very much for the remarkable work you have done! Regarding your code it works perfectly! I had thought about using kill but that didn't seem like a good method to me. But anyway I would not have been able to program this function. I agree with you I have to make a code that is compatible on any linux system in root or simple user. Small question I thought of putting carre.py in the /tmp folder what do you think? I think this folder is present on all Linux. best regards
|
|
|
Post by alexfish on Apr 14, 2023 18:47:53 GMT 1
Hi ptitjoz & All Well those bits are a matter of choice conclusion: can store bits in root :sudo write sudo cp : for the me : normal place for Alien bits /usr/local/mybits/myfile the 'mybits' : use unlikly name like Jackandjill196740 file options read from root "edit" save to tmp , if not wanting scripts hanging around Remember Bacon has DELETE *file option HaveFun + BR Alex Added:: this is a bit of a Selfie working on Joes HUG3 have add SEDIT bits Bacon hug/sedit python But falls in line with Food for thought, coming soon Attachments:
|
|