[old] Python Autocompletion

Tips and tricks to get the most out of using Editra

[old] Python Autocompletion

Postby cody » Sat Jun 02, 2007 5:30 am

The namespace dictionary used for looking up calltips and autocomplete options is updated when the document is loaded, saved, and after each new line inserted into the document. If you are not seeing autocomplete or calltip options where you think you should try hitting enter in the document to refresh the namespace dictionary.

If the tips still dont show up there may have been a compilation/parse error in one of the imports in the document.
Last edited by cody on Mon Oct 13, 2008 5:25 pm, edited 1 time in total.
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

auto completion still not working?

Postby cleverlion » Sun Nov 11, 2007 5:01 pm

Hi Cody,

I'm using MacOS 10.4, and I built Editra from source (svn revision 49832) yet auto-completion still doesn't seem to work with python or any files. Maybe I'm doing something wrong. Where could I check for error messages (import failures, etc.)?

A couple of other questions:
* How can I execute a python script and preferably get stdout and stderr in the bottom panel? Maybe there's a pluggin for this?
* Is there a setting to remember previously loaded files on startup?

EDIT: I found the Editra->Preferences->"Load Last Session" option.

Thanks,
FVL
cleverlion
User
 
Posts: 6
Joined: Sun Nov 11, 2007 7:24 am

Postby cody » Sun Nov 11, 2007 10:06 pm

Hello,

Currently the auto-completion is only for python.

I am re-working the python auto-completion right now and it works quite well now even for items in the local namespaces (i.e self). It should show a list of possible completions when you type a '.' after an object.
Code: Select all
import os
os.


Should show a list of all the things in the os module.this of course will not work for everything but with the recent svn it should work for most.

Calltips are shown when you type a '('.
Code: Select all
import os
os.chdir(

Should show the docstring and function signature for the function

The builtins should work regardless of any syntax errors in the document so if you cant type something like
Code: Select all
str(
1.


and see any kind of tips being provided then there is definitely something wrong.

First I would check the obvious

1) Is the document in the editor recognized as python. To check this open the Settings=>Lexers menu and see that there is a check mark next to Python.

2) Is autocompletion turned on in the Preferences dialog (Preferences=>Document=>Code).

If these are both ok then you can turn on the debug logging and see if any thing is being reported to the Console. Preferences=>General=>Editor Mode, Change to DEBUG and open Console.app to see the debug messages.

* How can I execute a python script and preferably get stdout and stderr in the bottom panel? Maybe there's a pluggin for this?

Currently there is nothing like this available but it is on the list of things I want to support.

Regards,

Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Postby cleverlion » Mon Nov 12, 2007 12:43 am

Hi Cody,

Thanks for the response. Python is selected under lexars and autocomplete is turned on. Here's the output I'm getting in the console:
Code: Select all
~/editra_dev/Editra/Editra gui_main.py
[16:37:51] [main_info] Initializing Application...
[16:37:51] [app][info] Editra is Initializing
[16:37:52] [app][info] Registering Editra's ArtProvider
[16:37:53] [docpositionmgr] successfully loaded book
[16:37:53] [styles][init] Loaded custom style sheet /Users/lionetti/editra_dev/Editra/styles/default.ess
[16:37:53] [stc_evt] Syntax Highlighting Turned On
[16:37:53] [stc_evt] Code Folding Turned On
[16:37:53] [stc_evt] Bracket Highlighting Turned On
[16:37:53] [stc_evt] Showing Line Numbers
[16:37:53] [nb_evt] Page Creation ID: -208
[16:37:53] [nb_evt] Page Changed to 0
[16:37:53] [nb_evt] Control Changing from Page: -1 to Page: 0
[16:37:53] [nb_info] It has file named:
[16:37:53] [main][info] Loading MainWindow Plugins
[16:37:53] [calc] Installing calculator plugin
[16:37:53] [filebrowser] Installing filebrowser plugin
[16:37:53] [main][info] Loading Generator plugins
[16:37:53] [mainw][info] CMD Open File: /Volumes/LACIE/cont_no_mgl/pcty/client/wxForms/gui_main.py
[16:37:53] [txtdecoder] Decoded text as utf-8
[16:37:53] [nb_evt] Opened Page: ID = 0
[16:37:54] [nb_info] Current Page = 0
[16:37:54] [main_info] Starting MainLoop...
[16:38:17] [app][info] Going to sleep
[16:38:26] [app][info] I'm Awake!!
CGContextRestoreGState: invalid context
[16:38:32] [app][info] Going to sleep
[16:38:34] [app][info] I'm Awake!!
CGContextRestoreGState: invalid context
CGContextRestoreGState: invalid context


This "invalid context" business sounds a little alarming. Any ideas?

Thanks,
FVL

P.S. Editra is very impressive.
cleverlion
User
 
Posts: 6
Joined: Sun Nov 11, 2007 7:24 am

Postby cody » Mon Nov 12, 2007 8:16 am

cleverlion wrote:This "invalid context" business sounds a little alarming. Any ideas?

There doesn't appear to be any errors in the log output. The "invalid context" are just warnings that can safely be ignored.

It is very strange this does not work on you machine, I am also using OSX 10.4 (intel) and have no issues with this.

Anyway, I made a number of improvements to the parser today and have checked them in under r49847. Try to update and see if it helps. The debugging from the parser is now also visible in the default debug output. There will likely be a number of error messages as the parser isn't perfect, but at least if you see lots of extra message out put when you type a '.' or a '(' you can tell it is at least trying to get completions. They log out put from the parser will be marked with lines like this ('[pycomp] something...').

If it still isn't doing anything after the update I would have to say I am a little stumped and will have to think abit about what else could be at play here.

cleverlion wrote:P.S. Editra is very impressive.


Thanks :D
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Postby cleverlion » Mon Nov 12, 2007 5:19 pm

Hi Cody,

Here's my latest output:

Code: Select all
[08:28:54] [main_info] Initializing Application...
[08:28:54] [app][info] Editra is Initializing
[08:28:55] [app][info] Registering Editra's ArtProvider
[08:28:55] [docpositionmgr] successfully loaded book
[08:28:56] [styles][init] Loaded custom style sheet /Users/me/editra_dev/Editra/styles/default.ess
[08:28:56] [stc_evt] Syntax Highlighting Turned On
[08:28:56] [stc_evt] Code Folding Turned On
[08:28:56] [stc_evt] Bracket Highlighting Turned On
[08:28:56] [stc_evt] Showing Line Numbers
[08:28:56] [nb_evt] Page Creation ID: -208
[08:28:56] [nb_evt] Page Changed to 0
[08:28:56] [nb_evt] Control Changing from Page: -1 to Page: 0
[08:28:56] [nb_info] It has file named:
[08:28:56] [main][info] Loading MainWindow Plugins
[08:28:56] [calc] Installing calculator plugin
[08:28:56] [filebrowser] Installing filebrowser plugin
[08:28:57] [main][info] Loading Generator plugins
[08:28:57] [txtdecoder] Decoded text as utf-8
[08:28:57] [nb_evt] Opened Page: ID = 0
[08:28:57] [nb_info] Current Page = 0
[08:28:57] [main_info] Starting MainLoop...
CGContextRestoreGState: invalid context
[08:29:02] [pycomp][err] Pyparser.parse: tokenize.TokenError, ('EOF in multi-line statement', (22, 0))
[08:29:02] [pycomp] Generated source: """"""
[08:29:02] class _PyCmplNoType:
[08:29:02]     def __getattr__(self,name):
[08:29:02]         return None
[08:29:02] [pycomp] get_completions('str(','')
[08:29:02] [pycomp][err] get_completions: 'module' object has no attribute 'ps2' [stmt='str(']
[08:29:09] [app][info] Going to sleep


I guess: <i>get_completions: 'module' object has no attribute 'ps2' [stmt='str(']</i> is the problem. Although I'm not sure off-hand what it means.

-FVL
cleverlion
User
 
Posts: 6
Joined: Sun Nov 11, 2007 7:24 am

Postby cody » Mon Nov 12, 2007 10:18 pm

Ah,

Thanks, I don't think I would have caught this. One of the tools I am using for the calltips needs to have a variable set (ps2), I wasn't running into this because I also use the PyShell plugin which defines this variable as well.

I checked in a fix under r49875 that should fix this problem.

Thanks,

cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Autocompletion v0.2.29 on Gentoo

Postby shmakes » Sun Dec 30, 2007 3:46 am

Followed your example:

----------------
import sys
sys.
----------------

No auto-completion after the dot.
Tried other working code files also, but no luck.

Here is the console debug:
Code: Select all
[21:29:44] [main_info] Initializing Application...
[21:29:44] [app][info] Editra is Initializing
[21:29:44] [app][info] Registering Editra's ArtProvider
[21:29:45] [docpositionmgr] successfully loaded book
[21:29:45] [styles][init] Loaded custom style sheet /usr/lib/python2.4/site-packages/wx-2.8-gtk2-unicode/wx/tools/Editra/styles/default.ess
[21:29:45] [stc_evt] Syntax Highlighting Turned On
[21:29:45] [stc_evt] Code Folding Turned On
[21:29:45] [stc_evt] Bracket Highlighting Turned On
[21:29:45] [stc_evt] Showing Line Numbers
[21:29:45] [nb_evt] Page Creation ID: -210
[21:29:45] [nb_evt] Page Changed to 0
[21:29:45] [nb_evt] Control Changing from Page: -1 to Page: 0
[21:29:45] [nb_info] It has file named:
[21:29:45] [main][info] Loading MainWindow Plugins
[21:29:45] [main][info] Loading Generator plugins
[21:29:45] [main_info] Starting MainLoop...
[21:29:58] [generator][info] Generation time 0.000373
[21:29:58] [stc_evt] Manually Setting Lexer to py
[21:30:06] [pycomp] Generated source: """"""
[21:30:06] class _PyCmplNoType:
[21:30:06]     def __getattr__(self,name):
[21:30:06]         return None
[21:30:06] [pycomp] get_completions('sys.','')
[21:30:06] [pycomp][err] get_completions: name 'sys' is not defined [stmt='sys']


It's probably something simple.

I have all the pre-req's working on Gentoo. (Glad to see that Gentoo is your test environment. :) )

I love this editor, but I really need to get the auto-complete working to make the move from SciTE/PyCrust.

Thanks,
Steve
shmakes
User
 
Posts: 6
Joined: Sun Dec 30, 2007 3:27 am

Postby cody » Sun Dec 30, 2007 7:52 am

Hello, thank you for reporting this

This is really strange it works fine with python 2.5 but not with python 2.4. I will try to get this figured out in the next few days if possible.

cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Python 2.5

Postby shmakes » Tue Jan 01, 2008 7:43 pm

Have you upgraded completely to Python-2.5 on Gentoo or are you running a separate development environment with this version?

I am a little hesitant to update my system to 2.5 as there are still reports of problems with some programs on Gentoo. (I know I could not run python-updater, and try to make Editra use the 2.5 slot, but I could imagine other bugs cropping in that scenario also.)

I tried updating Ubuntu (Gutsy) to the latest 2.8 series wxPython they have available because they are using Python-2.5 already. Unfortunately, the newest version in their repository is pre-inclusion of Editra, and it looks like their install is far from vanilla. (If I am going to have to build stuff myself, I will stick to Gentoo.)

Thanks for any advice you have.
Steve
shmakes
User
 
Posts: 6
Joined: Sun Dec 30, 2007 3:27 am

Postby cody » Tue Jan 01, 2008 11:03 pm

Actually due to a lack of hardware I dont have a machine setup with gentoo currently. I currently do most of the development on my mac using python2.5, this problem seems to be related to something in my code not agreeing with python2.4 (I can replicate this bug on any of my test enviorments with 2.4). Is wxpython2.8 still masked on portage?

I still want to support 2.4 for at least another year or so, I will get this fixed before the next release. I wouldn't upgrade your gentoo system just for this, especially as most of portage and the other core utilities on gentoo rely heavily on python and in my experience upgrading python can be slightly painful at times ;). If you are going to use Unbuntu you can get the latest release version of wxPython (w/ Editra) by getting the binaries from the wxpython site instead of the ones from the default unbuntu repository (http://wiki.wxpython.org/InstallingOnUbuntuOrDebian?highlight=%28ubuntu%29, http://wxpython.org/download.php#binaries)

This is near the top of my list of things to fix for the next release, I will update here after I get it sorted out.
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Postby shmakes » Wed Jan 02, 2008 2:59 am

Thanks for looking into this!

Gentoo currently has wxpython-2.8 hardmasked. They have just introduced the ability to load 2.6 and 2.8 in their own "slots" so they can co-exist. They also introduced a new eselect module to set the system default for wxWidgets when the required version is not specified.

Nice stuff - I just wish python 2.5 had an easier answer :? .

When you say "lack of hardware" do you mean "not allowed to operate", "no space/time to operate", or "unable to afford to purchase"? How far is Ichinomiya from Tokyo or Osaka?

If you need someone to test your changes for python 2.4, I would be willing to help. (I'm afraid my limited wx* skills would increase my inefficiencies at actually helping you fix the problem well above the normal "someone else's code" barrier.)

Thanks,
Steve
shmakes
User
 
Posts: 6
Joined: Sun Dec 30, 2007 3:27 am

Postby cody » Wed Jan 02, 2008 3:33 am

shmakes wrote:Thanks for looking into this!

Gentoo currently has wxpython-2.8 hardmasked. They have just introduced the ability to load 2.6 and 2.8 in their own "slots" so they can co-exist. They also introduced a new eselect module to set the system default for wxWidgets when the required version is not specified.

Nice stuff - I just wish python 2.5 had an easier answer :? .

nice to know

shmakes wrote:When you say "lack of hardware" do you mean "not allowed to operate", "no space/time to operate", or "unable to afford to purchase"? How far is Ichinomiya from Tokyo or Osaka?


I used to keep a fair collection of machines but I have been moving allot in recent years and had finally decided to cut myself down to a single laptop. Which works pretty well since I can run most things in a vm, unfortunately linux doesn't run so well in the parallels vm currently so I have been testing the editor for linux by using a custom compiled version of wxGTK that I compiled to run under X on my mac. Which for all intents and purposes works fine but is not quite the same as testing on an actual linux system. Been thinking about picking up another machine sometime soon though.

Ichinomiya is about exactly halfway between Tokyo and Osaka, its near Nagoya.

shmakes wrote:If you need someone to test your changes for python 2.4, I would be willing to help. (I'm afraid my limited wx* skills would increase my inefficiencies at actually helping you fix the problem well above the normal "someone else's code" barrier.)

Thanks,
Steve


Thanks I will let you know when get something worked out. This particular problem is in the non wx plain python backend code (Editra\src\autocomp\pycomp.py), I haven't had much time to check it yet but it seems that for some reason the parser is not finding the import statements for introspection when doing the parse under python2.4. The problem is likely that either 1) I used some python syntax that was introduced in 2.5 that is raising errors that are getting trapped with out saying anything in the parser code, 2) There are some differences to how the tokenize module works between python 2.4/2.5 that I need to compensate for in some way.

Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Ubuntu with Python 2.5

Postby shmakes » Wed Jan 02, 2008 5:11 am

I used the info you gave me regarding Ubuntu and got Editra running on my laptop with Python 2.5.

Unfortunately, I am getting the same sort of error in debug output and no autocomplete. As before, the autocompletion within the shell plugin works fine.

From Editra Help-About:

Code: Select all
Platform Info: (linux2, python 2.5.1,wxGTK 2.8.7.1, unicode, gtk2, wx-assertions-off, SWIG-1.3.29)


Setting lexer to "Python" and typing the following:

Code: Select all
import sys
sys.


Results in debug output:

Code: Select all
[23:00:16] [main_info] Initializing Application...
[23:00:16] [app][info] Editra is Initializing
[23:00:16] [app][info] Registering Editra's ArtProvider
[23:00:16] [docpositionmgr] successfully loaded book
[23:00:16] [styles][init] Loaded custom style sheet /usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/tools/Editra/styles/default.ess
[23:00:16] [stc_evt] Syntax Highlighting Turned On
[23:00:17] [stc_evt] Code Folding Turned On
[23:00:17] [stc_evt] Bracket Highlighting Turned On
[23:00:17] [stc_evt] Showing Line Numbers
[23:00:17] [nb_evt] Page Creation ID: -210
[23:00:17] [nb_evt] Page Changed to 0
[23:00:17] [nb_evt] Control Changing from Page: -1 to Page: 0
[23:00:17] [nb_info] It has file named:
[23:00:17] [main][info] Loading MainWindow Plugins
[23:00:17] [filebrowser] Installing filebrowser plugin

(python:10830): Gtk-CRITICAL **: gtk_widget_add_accelerator: assertion `GTK_IS_WIDGET (widget)' failed
[23:00:17] [main][info] Loading Generator plugins
[23:00:17] [main_info] Starting MainLoop...
[23:00:26] [generator][info] Generation time 0.000167
[23:00:26] [stc_evt] Manually Setting Lexer to py
[23:00:39] [pycomp] Generated source: """"""
[23:00:39] class _PyCmplNoType:
[23:00:39]     def __getattr__(self,name):
[23:00:39]         return None
[23:00:39] [pycomp] get_completions('sys.','')
[23:00:39] [pycomp][err] get_completions: name 'sys' is not defined [stmt='sys']


On both Gentoo and Ubuntu the following script is being used to start Editra:

Code: Select all
#!/usr/bin/python

import sys, os
import wx.tools

# Editra needs its src package to be on the sys.path for plugins and
# such to work right, so put it there before we do the first import of
# any Editra package or module.
sys.path.insert(0, os.path.join(os.path.dirname(wx.tools.__file__),
                                'Editra', 'src'))

import Editra
Editra.Main()


Is there something missing in this script? Could this be some sort of Linux environment variable or python path thing?

BTW - I am not being impatient. I just want to let you know what I find as I progress in case part of the problem is my fault. I would hate to have you waste time due to some stupid misconfiguration on my part.

Also, I asked about your location because the company I work for has offices in those locations. If you were lacking hardware resources, I could try to pull in some favors. It sounds like you are trying to cut down on electronic clutter. (Aren't we all :) .)

Thanks again,
Steve
shmakes
User
 
Posts: 6
Joined: Sun Dec 30, 2007 3:27 am

Postby cody » Wed Jan 02, 2008 6:38 pm

Hello,

I did some testing today and the problem is in Editra not your installation so don't worry about that. Here are my findings thus far.

OSX:
python 2.5 Works
python 2.4 Doesn't work, calltips for builtins do though (i.e type 'str(' )

Windows:
python 2.5 Works
python 2.4 Works

What concerns me is that you found it to not work with python 2.5 on Ubuntu if possible could you check the latest version out of svn and try it on your py2.5 installation, it doesn't need to be installed to run it.

Code: Select all
svn checkout http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/Editra Editra

cd Editra
python Editra


shmakes wrote:Is there something missing in this script? Could this be some sort of Linux environment variable or python path thing?


I don't think so,

The problem that I am seeing is that the new parser for the autocompletion is not finding import statements in the document as can be seen in the log output where it says 'Generated source', the line below this should have a line for each import in the document at the current scope of the carat. This generated source is then executed to create a namespace dictionary to do introspection on.

The PyShell plugin uses its own autocompletion code by doing something similar to the above by executing each line verbatim and then doing introspection. This method is not as safe as what I am doing with the autocompletion in the main editor as it actually runs the code in the buffer (i.e if the script in the buffer makes network connections this will actually happen when doing autocompletion with this method). The code in the main editor is parsed and reformed into a way that (hopefully) in all cases keep the actual action of the code from being executed during the introspection.
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Next

Return to Usage Tips

Who is online

Users browsing this forum: No registered users and 1 guest

cron