[PyShell] Another Holy Grail ;)

Pawel Palucki sacrebis at wp.pl
Wed Nov 22 13:53:51 PST 2006


Hi.

	I just want to share with my little useful patch for PyShell. That 
patch adding capability of auto-completion for all local and global 
variables (try >>> a<Ctrl+Space> gives me all variables defined
in local or global scope starting with letter 'a').

	I think that every one know that we can use PyShell as 
pdb.set_trace()(without step execution) but with pdb we haven't 
auto-completion and other features of pyshell. So I wrote that simple 
function:

#pyshlib.py
def startpy(locals):
     import wx.py.shell,wx
     pyapp = wx.PySimpleApp()
     shFrame = wx.py.shell.ShellFrame(locals=locals)
     pyapp.SetTopWindow(shFrame)
     shFrame.Show()
     pyapp.MainLoop()

For simplicity I store it in my site-packages.

Then if I want run pyshell in application I paste something like that:
all = dict(globals());all.update(locals())
import pyshlib;pyshlib.startpy(all)

I use it as template in Eclipse.

It is path for auto-completion and history of commands in ShellFrame 
(shell.py):

#diff begin for wxpython/wx/py/shell.py
235d234
<         self.locals=locals # fix - remebmer locals
285,293d283
<         # -- load hiostory from file
<         import os
<         if os.path.isfile('c:/pyshhist.txt'):
<             hisfile = file('c:/pyshhist.txt','r')
<             for l in hisfile.readlines():
<                 self.history.append(l[:-1])
<             hisfile.close()
<         self.Bind(wx.EVT_WINDOW_DESTROY,self.onCloseSaveHist)
<
333,339d322
<     def onCloseSaveHist(self,evt):
<         ''' savehistory on Close '''
<         hisfile = file('c:/pyshhist.txt','w')
<         for l in self.history:
<             hisfile.write(l+'\n')
<         hisfile.close()
<         evt.Skip()
1087,1094d1069
<         #auto-comp for local,global variables
<         else:
<             if self.locals:
<                     pasujace = [ cmd for cmd in self.locals.keys() if 
cmd.startswith(command)]
<                     options = ' '.join(pasujace)
<                     self.AutoCompShow(offset,options)
<
<
1136c1111
<         if True or pointavailpos != -1:
---
 >         if pointavailpos != -1:
1139,1141d1113
<             #auto completetion fix
<             if pointavailpos == -1:
<                 textbehind = self.GetTextRange (stoppos, currpos)
1148,1150d1119
<                 #auto completetion fix
<                 if pointavailpos == 0:
<                     textbefore = textbehind
#diff end

Tested only on Windows.

Remember to change history file location.

I think it is really helpful for debugging and for me
even with developing new functions.

If it helps I will by happy :)

--
Pawel Palucki





More information about the wxpython-users mailing list