IDLE Extension - Prompt goes missing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

IDLE Extension - Prompt goes missing

phelix
Hello!

I am trying to write an extension to add autocompletion for "self". It works fine but there is one problem I just can't figure out. Whenever I hit enter at the shell a couple of times the interpreter seems to be crashing. The extension still runs fine but the prompt is not comming back. I tried it in both python 2.62 and 3.2. Here is some example code, any suggestion welcome.

# # to config-extensions.def
# [TestExtension]
# enable=1
# enable_shell=0
# [TestExtension_bindings]
# toggle-test-extension=

debug = 1

if debug:
    import PyShell

UPDATEINTERVAL = 300

class TestExtension():
    def __init__(self, editwin):
        self.s_print("init0\n")
        self.editwin = editwin
        if editwin is None:  # subprocess and test
            return
        self.text = editwin.text

        self.text.after(UPDATEINTERVAL, self.timer_event)
       
        self.s_print("init1")

    def update(self):
        self.s_print("update1")

        #self.remote_control("get_the_calltip", "mint")
        self.remote_control("runcode", "1+1\n")
       
        self.s_print("update2\n")

    def remote_control(self, funcString, *args):
        try:
            rpcclt = self.editwin.flist.pyshell.interp.rpcclt
        except:
            rpcclt = None
        if not rpcclt:
            return(None)
        r = rpcclt.remotecall("exec", funcString,  args , {})
        return(r)

    def s_print(self, stringy):
        "print to shell to debug"
        if debug:
            try:
                PyShell.flist.pyshell.write(stringy)        
            except:
                pass  

    def timer_event(self):
        self.update()
        self.text.after(UPDATEINTERVAL, self.timer_event)


Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

Terry Reedy
On 3/28/2011 10:28 AM, phelix wrote:

> I am trying to write an extension to add autocompletion for "self". It works
> fine but there is one problem I just can't figure out. Whenever I hit enter
> at the shell a couple of times the interpreter seems to be crashing. The
> extension still runs fine but the prompt is not comming back. I tried it in
> both python 2.62 and 3.2. Here is some example code, any suggestion welcome.

I do not know anything about IDLE extensions. Where are they documented
or explained?

--
Terry Jan Reedy

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

Tal Einat
On Wed, Mar 30, 2011 at 10:28 PM, Terry Reedy <[hidden email]> wrote:
On 3/28/2011 10:28 AM, phelix wrote:

I am trying to write an extension to add autocompletion for "self". It works
fine but there is one problem I just can't figure out. Whenever I hit enter
at the shell a couple of times the interpreter seems to be crashing. The
extension still runs fine but the prompt is not comming back. I tried it in
both python 2.62 and 3.2. Here is some example code, any suggestion welcome.

I do not know anything about IDLE extensions. Where are they documented or explained?

See Lib/idlelib/extend.txt for details on extensions.

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

Tal Einat
In reply to this post by phelix
On Mon, Mar 28, 2011 at 4:28 PM, phelix <[hidden email]> wrote:

Hello!

Hi,
 
I am trying to write an extension to add autocompletion for "self".

Have you tried adding this functionality to the existing AutoComplete extension? That could save you a lot of work and would be the best way to do it.
 
It works
fine but there is one problem I just can't figure out. Whenever I hit enter
at the shell a couple of times the interpreter seems to be crashing. The
extension still runs fine but the prompt is not comming back. I tried it in
both python 2.62 and 3.2. Here is some example code, any suggestion welcome.

[snip]

Well, your code is doing a lot of things for which I don't understand the reasons.

The best tip I can give you is to run IDLE from the command line (on Windows, C:\Python32\python.exe C:\Python32\Lib\idlelib\idle.py). Then you can see output and exceptions printed to the command console. You could also print your own debugging info using "print" instead of using that s_print function, and it won't show up in IDLE's shell, just in the command console.

Finally, if you're going for completions in the editor, check out the Rope package which supplies some awesome code-analysis tools.

- Tal

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

phelix
>> I am trying to write an extension to add autocompletion for "self".
>Have you tried adding this functionality to the existing AutoComplete
>extension? That could save you a lot of work and would be the best way to do
>it.
I took a good look at it and also at CodeContext and learned a lot from it. But it was easier to put it into its own extension and seemed cleaner to me. Of course the completions show up in AutoComplete. What it does is that it simply points a global Reference "self" to the classname(s) it finds in the editor above the cursor.

>> It works
>> fine but there is one problem I just can't figure out. Whenever I hit enter
>> at the shell a couple of times the interpreter seems to be crashing. The
>> extension still runs fine but the prompt is not comming back. I tried it in
>> both python 2.62 and 3.2. Here is some example code, any suggestion
>> welcome.
>Well, your code is doing a lot of things for which I don't understand the
>reasons.
I should have been a little more verbose. In the update method there are two example lines for a call I need to do to install the class reference:

        #self.remote_control("get_the_calltip", "mint")  # this strategy would require to alter idle-code
        self.remote_control("runcode", "1+1\n")

With either of them I am having the problem of the disapearing prompt. Something similiar works fine from within the CodeContext extension so probably I am missing something here. I will investigate further.

>The best tip I can give you is to run IDLE from the command line (on
>Windows, C:\Python32\python.exe C:\Python32\Lib\idlelib\idle.py). Then you
>can see output and exceptions printed to the command console. You could also
>print your own debugging info using "print" instead of using that s_print
>function, and it won't show up in IDLE's shell, just in the command console.
I figured this out by coincidence just after I had posted this question. Though it seems very obvious to me know this is a very good hint and should by all means be included in the extend.txt file or on some website about IDLE Development.

=Phelix=
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

phelix
ok, finally I got it.

I fell for a bug that Noam Raphael pointed out and supplied a patch for eight years ago (http://old.nabble.com/Fix-freezes!-td1182996.html). It is still present in Idle 3.2. I guess IDLE development really is slow =) - this must change!

The problem was that my calls desynced the message loop, though they should not have.

I will post my extension here after a little testing, though it will only work with this bug patched.

=Phelix=
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

Tal Einat
In reply to this post by phelix
On Thu, Mar 31, 2011 at 10:01 AM, phelix wrote:

>> I am trying to write an extension to add autocompletion for "self".
>Have you tried adding this functionality to the existing AutoComplete
>extension? That could save you a lot of work and would be the best way to
>do it.
I took a good look at it and also at CodeContext and learned a lot from it.
But it was easier to put it into its own extension and seemed cleaner to me.
Of course the completions show up in AutoComplete. What it does is that it
simply points a global Reference "self" to the classname(s) it finds in the
editor above the cursor.

For your own good and for the good of IDLE, I urge you to try implementing this by improving AutoComplete. Your approach (as I understand it) both requires first fixing a delicate bug regarding IDLE's event handling and messes around with the Shell's namespace. I don't think you will manage to get such a patch accepted.

>The best tip I can give you is to run IDLE from the command line (on
>Windows, C:\Python32\python.exe C:\Python32\Lib\idlelib\idle.py). Then you
>can see output and exceptions printed to the command console. You could also
>print your own debugging info using "print" instead of using that s_print
>function, and it won't show up in IDLE's shell, just in the command console.
I figured this out by coincidence just after I had posted this question.
Though it seems very obvious to me know this is a very good hint and should
by all means be included in the extend.txt file or on some website about
IDLE Development.

Good point.

If you submit a patch which updates extend.txt appropriately, I'll review it.

- Tal

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

Terry Reedy
In reply to this post by Tal Einat
On 3/31/2011 2:13 AM, Tal Einat wrote:

> See Lib/idlelib/extend.txt for details on extensions.

Thank you. I read it but did not find it completely clear.
If I figure out what I have missed, I will try to suggest a patch ;-).
I need to look at examples more, first.

--
Terry Jan Reedy

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

Terry Reedy
In reply to this post by phelix
On 3/31/2011 10:10 AM, phelix wrote:
>
> ok, finally I got it.
>
> I fell for a bug that Noam Raphael pointed out and supplied a patch for
> eight years ago (http://old.nabble.com/Fix-freezes!-td1182996.html). It is
> still present in Idle 3.2. I guess IDLE development really is slow =) - this
> must change!

That refers to an issue in the IDLEfork tracker filed after the last
independent release of IDLEfork. I am not sure when IDLEfork was merged
into trunk, but I suspect that a few legitimate bug reports were not
copied over. This one, by Bruce Sherwood, may or may not be on the
current tracker, but it is on my personal todo list:

"Not sure whether this should be a bug report or a feature
request, but it would be really nice if a file save would by
default supply the important .py extension. Without it,
colorizing doesn't work, which is confusing to people.
And of course there are other good reasons for wanting
the .py extension on Python files."

--
Terry Jan Reedy

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: IDLE Extension - Prompt goes missing

Tal Einat
In reply to this post by Terry Reedy
On Fri, Apr 1, 2011 at 7:28 AM, Terry Reedy wrote:
On 3/31/2011 2:13 AM, Tal Einat wrote:

See Lib/idlelib/extend.txt for details on extensions.

Thank you. I read it but did not find it completely clear.
If I figure out what I have missed, I will try to suggest a patch ;-).
I need to look at examples more, first.

Note that installing a new extension (e.g. from PyPI) is a hassle, so new extensions die quickly if they aren't integrated into IDLE.

I think extensions would be much more useful given a config dialog for configuring each extension separately. My patch for this has been sitting around for years: issue3068.

Admittedly I was given the go-ahead to make such changes to IDLE directly and commit them, but unfortunately I haven't found the time required for this since.

- Tal

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev