Reputation: 33
I've been spending the last week or so creating a simple touch friendly GUI in python3.4 (on the raspberry pi). Now I setup python to run my script on launch, but I ran into the problem, that I couldn't open other programs from within my program (such as the web browser or calculator). However if I use IDLE to execute the script and not the standard python program in the terminal, opening other programs from my scrip works! I already created a .sh file that runs when the Linux Gui starts, which opens up my script in IDLE, however it only opens the file and doesn't execute it.
So now here is my question: Can I create a .sh script, which opens IDLE and runs a python script in the IDLE console (I already tried the exec command when launching idle with no results)
Right now this is my command, which should execute the loaded file, but only loads it for some reaseon:
sudo idle3 -c exec(open('/path/to/my/file.py').read())
Any help is appreciated :)
Upvotes: 1
Views: 1528
Reputation: 3159
You have a few options, of which the best one is to use the -r
option. From man idle
:
-r file
Run script from file.
This will however only open the interpreter window. Since you also want the editor, this will do pretty much exactly what you describe:
idle3 '/path.to/file.py' & idle3 -r '/path.to/file.py'
The startup command you need is then:
/bin/bash -c "idle3 '/path/to/file.py' & idle3 -r '/path/to/file.py'"
The command you tried will not work, since here, we can read:
Only process 0 may call idle(). Any user process, even a process with superuser permission, will receive EPERM.
Therefore, we depend on cli options of idle
, which luckily provide an option :)
Another option would be to open the file with idle3
wait for the window to appear and simulate F5:
/bin/bash -c "idle3 '/path/to/file.py' & sleep 3 && xdotool key F5"
This would need xdotool to be installed on your system.
An advanced version of this wrapper would open the file with idle
, subsequently check if the new window exists, is focussed and simulate F5 with xdotool
.
These would however be the dirty options, which we luckily don't need :).
Upvotes: 1