Skip to content

Commit

Permalink
Merged Laurent's fixes for various small issues with the standalone WX
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fperez committed Aug 28, 2008
3 parents 9666d22 + 8083753 + ff2e1f2 commit b705903
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 33 deletions.
14 changes: 13 additions & 1 deletion IPython/ColorANSI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -34,14 +35,25 @@ 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"),
("Yellow" , "1;33"),
("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)
Expand Down
12 changes: 9 additions & 3 deletions IPython/gui/wx/ipshell_nonblocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,18 @@ def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
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:
Expand Down Expand Up @@ -195,8 +200,9 @@ def doExecute(self, line):

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):
Expand Down
17 changes: 16 additions & 1 deletion IPython/gui/wx/ipython_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
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):
Expand Down Expand Up @@ -604,7 +619,7 @@ def stateDoExecuteLine(self):
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')

Expand Down
6 changes: 0 additions & 6 deletions IPython/gui/wx/options.conf

This file was deleted.

50 changes: 31 additions & 19 deletions IPython/gui/wx/wxIPython.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
# -*- coding: iso-8859-15 -*-

import wx.aui

import sys
#used for about dialog
from wx.lib.wordwrap import wordwrap

#used for ipython GUI objects
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"
Expand Down Expand Up @@ -84,7 +87,9 @@ def __init__(self, parent=None, id=-1, title="WxIPython",
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()
Expand All @@ -98,24 +103,31 @@ def optionSave(self, name, value):
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"""
Expand Down
11 changes: 11 additions & 0 deletions scripts/ipython-wx
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 3 additions & 3 deletions scripts/ipython_win_post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit b705903

Please sign in to comment.