diff --git a/IPython/Extensions/ipy_miscapps.py b/IPython/Extensions/ipy_miscapps.py new file mode 100644 index 0000000..5e05d57 --- /dev/null +++ b/IPython/Extensions/ipy_miscapps.py @@ -0,0 +1,19 @@ +""" Completers for miscellaneous command line apps + +""" +import IPython.ipapi +ip = IPython.ipapi.get() +import os + +def surfraw_completer(self,cmdline): + """ Completer for 'surfraw' + + example:: + sr go => sr google + + """ + compl = [l.split(None,1)[0] for l in os.popen('sr -elvi')] + return compl + + +ip.set_hook('complete_command', surfraw_completer, str_key = 'sr') \ No newline at end of file diff --git a/IPython/gui/wx/ipshell_nonblocking.py b/IPython/gui/wx/ipshell_nonblocking.py index 9fb2183..be9d47b 100644 --- a/IPython/gui/wx/ipshell_nonblocking.py +++ b/IPython/gui/wx/ipshell_nonblocking.py @@ -154,13 +154,18 @@ class NonBlockingIPShell(object): self._term = IPython.genutils.IOTerm(cin=cin, cout=cout, cerr=cerr) excepthook = sys.excepthook - + #Hack to save sys.displayhook, because ipython seems to overwrite it... + self.sys_displayhook_ori = sys.displayhook + self._IP = IPython.Shell.make_IPython( argv,user_ns=user_ns, user_global_ns=user_global_ns, embedded=True, shell_class=IPython.Shell.InteractiveShell) + #we restore sys.displayhook + sys.displayhook = self.sys_displayhook_ori + #we replace IPython default encoding by wx locale encoding loc = locale.getpreferredencoding() if loc: @@ -195,8 +200,9 @@ class NonBlockingIPShell(object): self._line_to_execute = line #we launch the ipython line execution in a thread to make it interruptible - ce = _CodeExecutor(self, self._afterExecute) - ce.start() + #with include it in self namespace to be able to call ce.raise_exc(KeyboardInterrupt) + self.ce = _CodeExecutor(self, self._afterExecute) + self.ce.start() #----------------------- IPython management section ---------------------- def getDocText(self): diff --git a/IPython/gui/wx/ipython_view.py b/IPython/gui/wx/ipython_view.py index fa72bbd..c189780 100644 --- a/IPython/gui/wx/ipython_view.py +++ b/IPython/gui/wx/ipython_view.py @@ -30,6 +30,21 @@ import wx.stc as stc import re from StringIO import StringIO +import sys +import codecs +import locale +for enc in (locale.getpreferredencoding(), + sys.getfilesystemencoding(), + sys.getdefaultencoding()): + try: + codecs.lookup(enc) + ENCODING = enc + break + except LookupError: + pass +else: + ENCODING = 'utf-8' + from ipshell_nonblocking import NonBlockingIPShell class WxNonBlockingIPShell(NonBlockingIPShell): @@ -604,7 +619,7 @@ class IPShellWidget(wx.Panel): self.text_ctrl.write('\n') lines_to_execute = lines.replace('\t',' '*4) lines_to_execute = lines_to_execute.replace('\r','') - self.IP.doExecute(lines_to_execute.encode('cp1252')) + self.IP.doExecute(lines_to_execute.encode(ENCODING)) self.updateHistoryTracker(lines) self.setCurrentState('WAIT_END_OF_EXECUTION') diff --git a/IPython/gui/wx/options.conf b/IPython/gui/wx/options.conf deleted file mode 100644 index b202640..0000000 --- a/IPython/gui/wx/options.conf +++ /dev/null @@ -1,6 +0,0 @@ -completion=IPYTHON -background_color=BLACK -filter_empty=True -filter_magic=True -filter_doc=True -filter_cmd=True diff --git a/IPython/gui/wx/wxIPython.py b/IPython/gui/wx/wxIPython.py index 972acfa..0d0d249 100644 --- a/IPython/gui/wx/wxIPython.py +++ b/IPython/gui/wx/wxIPython.py @@ -2,7 +2,7 @@ # -*- coding: iso-8859-15 -*- import wx.aui - +import sys #used for about dialog from wx.lib.wordwrap import wordwrap @@ -10,6 +10,9 @@ from wx.lib.wordwrap import wordwrap from IPython.gui.wx.ipython_view import IPShellWidget from IPython.gui.wx.ipython_history import IPythonHistoryPanel +#used to create options.conf file in user directory +from IPython.ipapi import get + __version__ = 0.8 __author__ = "Laurent Dufrechou" __email__ = "laurent.dufrechou _at_ gmail.com" @@ -84,7 +87,9 @@ class MyFrame(wx.Frame): dlg.Destroy() def optionSave(self, name, value): - opt = open('options.conf','w') + ip = get() + path = ip.IP.rc.ipythondir + opt = open(path + '/options.conf','w') try: options_ipython_panel = self.ipython_panel.getOptions() @@ -98,24 +103,31 @@ class MyFrame(wx.Frame): opt.close() def optionLoad(self): - opt = open('options.conf','r') - lines = opt.readlines() - opt.close() + try: + ip = get() + path = ip.IP.rc.ipythondir + opt = open(path + '/options.conf','r') + lines = opt.readlines() + opt.close() - options_ipython_panel = self.ipython_panel.getOptions() - options_history_panel = self.history_panel.getOptions() - - for line in lines: - key = line.split('=')[0] - value = line.split('=')[1].replace('\n','').replace('\r','') - if key in options_ipython_panel.keys(): - options_ipython_panel[key]['value'] = value - elif key in options_history_panel.keys(): - options_history_panel[key]['value'] = value - else: - print >>sys.__stdout__,"Warning: key ",key,"not found in widget options. Check Options.conf" - self.ipython_panel.reloadOptions(options_ipython_panel) - self.history_panel.reloadOptions(options_history_panel) + options_ipython_panel = self.ipython_panel.getOptions() + options_history_panel = self.history_panel.getOptions() + + for line in lines: + key = line.split('=')[0] + value = line.split('=')[1].replace('\n','').replace('\r','') + if key in options_ipython_panel.keys(): + options_ipython_panel[key]['value'] = value + elif key in options_history_panel.keys(): + options_history_panel[key]['value'] = value + else: + print >>sys.__stdout__,"Warning: key ",key,"not found in widget options. Check Options.conf" + self.ipython_panel.reloadOptions(options_ipython_panel) + self.history_panel.reloadOptions(options_history_panel) + + except IOError: + print >>sys.__stdout__,"Could not open Options.conf, defaulting to default values." + def createMenu(self): """local method used to create one menu bar""" diff --git a/docs/examples/core/ipython-sh.desktop b/docs/examples/core/ipython-sh.desktop new file mode 100644 index 0000000..f0aabcd --- /dev/null +++ b/docs/examples/core/ipython-sh.desktop @@ -0,0 +1,22 @@ +# If you want ipython to appear in a linux app launcher ("start menu"), install this by doing: +# sudo desktop-file-install ipython-sh.desktop + +[Desktop Entry] +Comment=Perform shell-like tasks in interactive ipython session +Exec=ipython -p sh +GenericName[en_US]=IPython shell mode +GenericName=IPython shell mode +Icon=gnome-netstatus-idle +MimeType= +Name[en_US]=ipython-sh +Name=ipython-sh +Path= +Categories=Development;Utility; +StartupNotify=false +Terminal=true +TerminalOptions= +Type=Application +X-DBUS-ServiceName= +X-DBUS-StartupType=none +X-KDE-SubstituteUID=false +X-KDE-Username= diff --git a/docs/examples/core/ipython.desktop b/docs/examples/core/ipython.desktop new file mode 100644 index 0000000..98793bf --- /dev/null +++ b/docs/examples/core/ipython.desktop @@ -0,0 +1,22 @@ +# If you want ipython to appear in a linux app launcher ("start menu"), install this by doing: +# sudo desktop-file-install ipython.desktop + +[Desktop Entry] +Comment=Enhanced interactive Python shell +Exec=ipython +GenericName[en_US]=IPython +GenericName=IPython +Icon=gnome-netstatus-idle +MimeType= +Name[en_US]=ipython +Name=ipython +Path= +Categories=Development;Utility; +StartupNotify=false +Terminal=true +TerminalOptions= +Type=Application +X-DBUS-ServiceName= +X-DBUS-StartupType=none +X-KDE-SubstituteUID=false +X-KDE-Username= diff --git a/scripts/ipython-wx b/scripts/ipython-wx new file mode 100644 index 0000000..5741eff --- /dev/null +++ b/scripts/ipython-wx @@ -0,0 +1,11 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""wxIPython -- An enhanced Interactive Python GUI fonrtend +This script starts the Wx graphical frontend. +This is experimental so far. +Currently it support only ipython0 instance. Will be upgraded to ipython1 one. +""" + +from IPython.gui.wx import wxIPython + +wxIPython.main()