From b7059034ec0e3e9401823d406f8ca921df22d1a9 2008-08-28 22:27:05 From: Fernando Perez Date: 2008-08-28 22:27:05 Subject: [PATCH] Merged Laurent's fixes for various small issues with the standalone WX frontend. I modified the name of the new standalone script to be 'ipython-wx' because I expect we'll develop a set of new GUI frontends. Using the naming scheme 'ipython-XX' will make them easier to discover. --- diff --git a/IPython/ColorANSI.py b/IPython/ColorANSI.py index ea875c0..fbf9573 100644 --- a/IPython/ColorANSI.py +++ b/IPython/ColorANSI.py @@ -26,6 +26,7 @@ def make_color_table(in_class): Helper function for building the *TermColors classes.""" color_templates = ( + # Dark colors ("Black" , "0;30"), ("Red" , "0;31"), ("Green" , "0;32"), @@ -34,6 +35,7 @@ def make_color_table(in_class): ("Purple" , "0;35"), ("Cyan" , "0;36"), ("LightGray" , "0;37"), + # Light colors ("DarkGray" , "1;30"), ("LightRed" , "1;31"), ("LightGreen" , "1;32"), @@ -41,7 +43,17 @@ def make_color_table(in_class): ("LightBlue" , "1;34"), ("LightPurple" , "1;35"), ("LightCyan" , "1;36"), - ("White" , "1;37"), ) + ("White" , "1;37"), + # Blinking colors. Probably should not be used in anything serious. + ("BlinkBlack" , "5;30"), + ("BlinkRed" , "5;31"), + ("BlinkGreen" , "5;32"), + ("BlinkYellow" , "5;33"), + ("BlinkBlue" , "5;34"), + ("BlinkPurple" , "5;35"), + ("BlinkCyan" , "5;36"), + ("BlinkLightGray", "5;37"), + ) for name,value in color_templates: setattr(in_class,name,in_class._base % value) 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/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() diff --git a/scripts/ipython_win_post_install.py b/scripts/ipython_win_post_install.py index fa0ca53..ace3306 100755 --- a/scripts/ipython_win_post_install.py +++ b/scripts/ipython_win_post_install.py @@ -40,7 +40,7 @@ def install(): print ('To take full advantage of IPython, you need readline from:\n' 'http://sourceforge.net/projects/uncpythontools') - ipybase = '"'+prefix+r'\scripts\ipython"' + ipybase = '"' + prefix + r'\scripts\ipython"' # Create IPython entry ... if not os.path.isdir(ip_dir): os.mkdir(ip_dir) @@ -59,12 +59,12 @@ def install(): a = ipybase+' -pylab -p scipy' mkshortcut(python,'IPython scipy profile',f,a) - # Create documentation shortcuts ... + # Create documentation shortcuts ... t = prefix + r'\share\doc\ipython\manual\ipython.pdf' f = ip_dir + r'\Manual in PDF.lnk' mkshortcut(t,r'IPython Manual - PDF-Format',f) - t = prefix + r'\share\doc\ipython\manual\ipython.html' + t = prefix + r'\share\doc\ipython\manual\html\index.html' f = ip_dir + r'\Manual in HTML.lnk' mkshortcut(t,'IPython Manual - HTML-Format',f)