IDLE question

B

bobueland

IDLE doesn't seem to honor PYTHONSTARTUP environment variable nor
sitecustomize.py

How do you then customize in IDLE?

(basically I want to execute the statement
from btools import *
each time I restart IDLEs Python Shell)
 
B

bobueland

Okey I tried what you recommended

My C:\Python24\sitecustomize.py looks like this:

# sitecustomize.py
import os
from btools import *

When I enter
C:\Python24>C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.py -r
C:\Python24\sitecustomize.py

in commad propmt IDLE starts up and automatically imports 'os' and all
names from my btools folder. So far so good. But when I hit Ctrl+F6 and
restart Python Shell both 'os' and names from btools are gone!

When I work with IDLE I typically start a new file (File/New Window)
and when I have written the code I hit (Ctrl+S) to Save and F5 to run.
This restarts Python Shell and my names from btools are gone. It's no
solution if I'm forced to go back to command prompt and enter the long
sequance again.

Bob
 
C

Claudio Grondi

IDLE doesn't seem to honor PYTHONSTARTUP environment variable nor
sitecustomize.py

How do you then customize in IDLE?

(basically I want to execute the statement
from btools import *
each time I restart IDLEs Python Shell)
Following works for me:

C:\Python24\pythonw.exe E:\Python24\Lib\idlelib\idle.py -r
E:\Python24\sitecustomize.py

or

C:\Python24\pythonw.exe E:\Python24\Lib\idlelib\idle.py -c "import os;
from path import path"

content of my sitecustomize.py is:
"
import os
from path import path
"

and both ways of invoking IDLE have the same effect (apparently of faking
execution of not shown input line) of making the modules os and the class
path available at start of IDLE.

My question in this context:
Can the PyShell.py file in C:\Python24\Lib\idlelib directory be edited
somehow to achieve same effect?

Claudio
 
B

bobueland

I did as you suggested, however

after I make a new File (File/New Window) and save and then run (F5) I
get the following alert

The Python Shell is already executing a command; please waith until it
is finished

I also get the error message

Traceback (most recent call last):
File "<pyshell#1>", line 1, in -toplevel-
import os; from path import path
ImportError: No module named path
Bob
 
C

Claudio Grondi

now a patch fixing it I have no good feeling about, but it works:

in PyShell.py in
def restart_subprocess(self):

insert in section:
"
console.showprompt()
# restart subprocess debugger

# (-Patch)
# making additional modules available in IDLE directly after
re-start of it:
self.runsource("import os; from path import path")
# (Patch-)

if debug:
"
This will provide the modules also after restart.

Hope this will not crash elsewhere because of unexpected effects of
inserting the runsource() method at that point in the code without any other
commands which are maybe necessary to keep IDLE consistent.

So IDLE experts, HELP PLEASE !!!

Claudio
 
B

bobueland

This works!

Thanks Claudio

For complete happiness I would also like to know what's hapening. Is
there anywhere I can read about PyShell.py.

Bob
 
C

Claudio Grondi

I did as you suggested, however

after I make a new File (File/New Window) and save and then run (F5) I
get the following alert

The Python Shell is already executing a command; please waith until it
is finished

I also get the error message

Traceback (most recent call last):
File "<pyshell#1>", line 1, in -toplevel-
import os; from path import path
ImportError: No module named path

Bob
Sure you have to replace "import os; from path import path"
with " from btools import *", than you avoid the error message
but not the problem you have got with the message box.
A "solution" to the problem with the message box may be as follows:

"
console.showprompt()
# restart subprocess debugger

# (-Patch)
# making additional modules available in IDLE directly after
re-start of it:
self.runsource("import os; from path import path")
time.sleep(0.1)
# (Patch-)

if debug:
"
If 0.1 doesn't work on your system, just increase the value, but this will
delay the response.
e.g. 0.001 doesn't work for me, but 0.1 does (Intel Pentium 4 running at 2.8
GHz).

Claudio
 
C

Claudio Grondi

Here a correction of the code snippet:

console.text.mark_gravity("restart", "left")
# (-Patch)
# making additional modules available in IDLE directly after
re-start of it:
self.runsource("import os; from path import path")
time.sleep(0.1)
# (Patch-)
console.showprompt()

# restart subprocess debugger

I have no slightest idea why does it make a difference.
What would make much more sense for me is to wait until
self.tkconsole.executing
is False
but this resulted in an endless loop ...

Claudio
 
C

Claudio Grondi

This works!

Thanks Claudio
I am glad, that the time I put into it was not wasted.
For complete happiness I would also like to know what's hapening.
Is there anywhere I can read about PyShell.py.

Not that I would know about (except reading the source code).

Maybe this below is the right place to ask further questions (2004 there was
a discussion about IDLE):
http://mail.python.org/mailman/listinfo/tutor
but I have to admit, I haven't used this forum myself yet.

From my experience with learning Python I suppose, that it will be not very
easy to fully understand what is going on in IDLE (i.e. in PyShell.py)
because this probably requires full understanding of the Tkinter interface
and some insight into deep Python internals. Perhaps this is the reason why
noone knowledgable in this area has responded here expecting from a response
more trouble than success?

Claudio
 
B

bobueland

I made bat file called startidle.bat which I put in C:\Python24
directory. This is how it looks

@echo off
start C:\Python24\pythonw.exe C:\Python24\Lib\idlelib\idle.py -r
C:\Python24\sitecustomize.py
exit

Now I put a shortcut of startidle.bat in Quick Launch. The only thing I
have to do now is to click on the shortcut icon in the Quick Launch and
I'm up and running.

Alla Tua Salute Claudio

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Python IDLE 2
Running Idle on Windows 7 0
Buffering in Wing and IDLE 3 3
timeit module in IDLE 0
IDLE not setting current directory in its path 6
IDLE 6
IDLE gripe and question 3
Tkinter, IDLE keeps crashing 5

Members online

No members online now.

Forum statistics

Threads
473,801
Messages
2,569,658
Members
45,423
Latest member
NancyEades

Latest Threads

Top