mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-06 12:00:13 +01:00
Some Py3 fixes for PyCrust
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@76040 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -816,10 +816,8 @@ def myExecfile(filename, ns):
|
||||
if sys.version_info < (3,):
|
||||
execfile(filename, ns)
|
||||
else:
|
||||
f = open(filename, 'r')
|
||||
source = f.read()
|
||||
f.close()
|
||||
exec(source, ns)
|
||||
with open(filename, 'r') as f:
|
||||
exec(f.read(), ns)
|
||||
|
||||
|
||||
def textfile_open(filename, mode='rt'):
|
||||
|
||||
@@ -17,7 +17,6 @@ class App(wx.App):
|
||||
wx.App.__init__(self, redirect=False)
|
||||
|
||||
def OnInit(self):
|
||||
wx.InitAllImageHandlers()
|
||||
self.frame = py.editor.EditorFrame(filename=self.filename)
|
||||
self.frame.Show()
|
||||
self.SetTopWindow(self.frame)
|
||||
|
||||
@@ -17,7 +17,6 @@ class App(wx.App):
|
||||
wx.App.__init__(self, redirect=False)
|
||||
|
||||
def OnInit(self):
|
||||
wx.InitAllImageHandlers()
|
||||
self.frame = py.editor.EditorNotebookFrame(filename=self.filename)
|
||||
self.frame.Show()
|
||||
self.SetTopWindow(self.frame)
|
||||
|
||||
@@ -17,7 +17,6 @@ class App(wx.App):
|
||||
wx.App.__init__(self, redirect=False)
|
||||
|
||||
def OnInit(self):
|
||||
wx.InitAllImageHandlers()
|
||||
self.frame = py.editor.EditorShellNotebookFrame(filename=self.filename)
|
||||
self.frame.Show()
|
||||
self.SetTopWindow(self.frame)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# main namespace to look as much as possible like the regular Python
|
||||
# shell environment.
|
||||
import __main__
|
||||
original = __main__.__dict__.keys()
|
||||
original = list(__main__.__dict__.keys())
|
||||
|
||||
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
||||
|
||||
@@ -53,7 +53,7 @@ def main():
|
||||
md = __main__.__dict__
|
||||
keepers = original
|
||||
keepers.append('App')
|
||||
for key in md.keys():
|
||||
for key in list(md.keys()):
|
||||
if key not in keepers:
|
||||
del md[key]
|
||||
# Create an application instance.
|
||||
|
||||
@@ -6,14 +6,15 @@ __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
||||
# We use this object to get more introspection when run standalone.
|
||||
app = None
|
||||
|
||||
import filling
|
||||
from . import filling
|
||||
|
||||
# These are imported just to have something interesting to inspect.
|
||||
import crust
|
||||
import interpreter
|
||||
import introspect
|
||||
import pseudo
|
||||
import shell
|
||||
from . import crust
|
||||
from . import interpreter
|
||||
from . import introspect
|
||||
from . import pseudo
|
||||
from . import shell
|
||||
|
||||
import sys
|
||||
import wx
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# main namespace to look as much as possible like the regular Python
|
||||
# shell environment.
|
||||
import __main__
|
||||
original = __main__.__dict__.keys()
|
||||
original = list(__main__.__dict__.keys())
|
||||
|
||||
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
||||
|
||||
@@ -51,7 +51,7 @@ def main():
|
||||
md = __main__.__dict__
|
||||
keepers = original
|
||||
keepers.append('App')
|
||||
for key in md.keys():
|
||||
for key in list(md.keys()):
|
||||
if key not in keepers:
|
||||
del md[key]
|
||||
# Create an application instance.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# main namespace to look as much as possible like the regular Python
|
||||
# shell environment.
|
||||
import __main__
|
||||
original = __main__.__dict__.keys()
|
||||
original = list(__main__.__dict__.keys())
|
||||
|
||||
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com> / "
|
||||
__author__ += "David N. Mashburn <david.n.mashburn@gmail.com>"
|
||||
@@ -69,7 +69,7 @@ def main(filename=None):
|
||||
keepers = original
|
||||
keepers.append('App')
|
||||
keepers.append('filename')
|
||||
for key in md.keys():
|
||||
for key in list(md.keys()):
|
||||
if key not in keepers:
|
||||
del md[key]
|
||||
# Create an application instance.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# main namespace to look as much as possible like the regular Python
|
||||
# shell environment.
|
||||
import __main__
|
||||
original = __main__.__dict__.keys()
|
||||
original = list(__main__.__dict__.keys())
|
||||
|
||||
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
||||
|
||||
@@ -65,7 +65,7 @@ def main(filename=None):
|
||||
keepers = original
|
||||
keepers.append('App')
|
||||
keepers.append('filename')
|
||||
for key in md.keys():
|
||||
for key in list(md.keys()):
|
||||
if key not in keepers:
|
||||
del md[key]
|
||||
# Create an application instance.
|
||||
|
||||
@@ -17,7 +17,6 @@ import os
|
||||
import sys
|
||||
|
||||
def wrap(app):
|
||||
wx.InitAllImageHandlers()
|
||||
frame = py.crust.CrustFrame()
|
||||
frame.SetSize((750, 525))
|
||||
frame.Show(True)
|
||||
|
||||
@@ -276,8 +276,7 @@ class EditorNotebookFrame(EditorFrame):
|
||||
intro = 'Py %s' % version.VERSION
|
||||
import imp
|
||||
module = imp.new_module('__main__')
|
||||
import __builtin__
|
||||
module.__dict__['__builtins__'] = __builtin__
|
||||
module.__dict__['__builtins__'] = __builtins__
|
||||
namespace = module.__dict__.copy()
|
||||
self.crust = crust.Crust(parent=self.notebook, intro=intro, locals=namespace)
|
||||
self.shell = self.crust.shell
|
||||
|
||||
@@ -344,7 +344,6 @@ class App(wx.App):
|
||||
"""PyFilling standalone application."""
|
||||
|
||||
def OnInit(self):
|
||||
wx.InitAllImageHandlers()
|
||||
self.fillingFrame = FillingFrame()
|
||||
self.fillingFrame.Show(True)
|
||||
self.SetTopWindow(self.fillingFrame)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com> / David Mashburn <david.n.mashburn@gmail.com>"
|
||||
|
||||
import wx
|
||||
from wx.lib.six import StringIO
|
||||
from wx.lib.six import BytesIO
|
||||
|
||||
def getPyIcon(shellName='PyCrust'):
|
||||
icon = wx.Icon()
|
||||
@@ -14,7 +14,7 @@ def getPyBitmap(shellName='PyCrust'):
|
||||
return wx.Bitmap(getPyImage(shellName))
|
||||
|
||||
def getPyImage(shellName='PyCrust'):
|
||||
stream = StringIO(getPyData(shellName))
|
||||
stream = BytesIO(getPyData(shellName))
|
||||
return wx.Image(stream)
|
||||
|
||||
def getPyData(shellName='PyCrust'):
|
||||
|
||||
@@ -8,7 +8,7 @@ import inspect
|
||||
import tokenize
|
||||
import types
|
||||
import wx
|
||||
from wx.lib.six import StringIO, PY3
|
||||
from wx.lib.six import BytesIO, PY3
|
||||
|
||||
def getAutoCompleteList(command='', locals=None, includeMagic=1,
|
||||
includeSingle=1, includeDouble=1):
|
||||
@@ -80,7 +80,7 @@ def getAttributeNames(object, includeMagic=1, includeSingle=1,
|
||||
# e.g. ITK http://www.itk.org/
|
||||
attributes = [attribute for attribute in attributes \
|
||||
if type(attribute) == str]
|
||||
attributes.sort(lambda x, y: cmp(x.upper(), y.upper()))
|
||||
attributes.sort(key=lambda x: x.upper())
|
||||
if not includeSingle:
|
||||
attributes = filter(lambda item: item[0]!='_' \
|
||||
or item[1:2]=='_', attributes)
|
||||
@@ -139,9 +139,9 @@ def getAllAttributeNames(object):
|
||||
except: # Must catch all because object might have __getattr__.
|
||||
pass
|
||||
else:
|
||||
if isinstance(bases, types.TupleType):
|
||||
if isinstance(bases, tuple):
|
||||
for base in bases:
|
||||
if type(base) is types.TypeType:
|
||||
if type(base) is type:
|
||||
# Break a circular reference. Happens in Python 2.2.
|
||||
pass
|
||||
else:
|
||||
@@ -304,7 +304,7 @@ def getTokens(command):
|
||||
except UnicodeEncodeError:
|
||||
pass # otherwise leave it alone
|
||||
|
||||
f = StringIO(command)
|
||||
f = BytesIO(command)
|
||||
# tokens is a list of token tuples, each looking like:
|
||||
# (type, string, (srow, scol), (erow, ecol), line)
|
||||
tokens = []
|
||||
|
||||
@@ -8,6 +8,7 @@ __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
||||
|
||||
import wx
|
||||
from wx import stc
|
||||
from wx.lib.six import PY3
|
||||
|
||||
import keyword
|
||||
import os
|
||||
@@ -409,7 +410,12 @@ class Shell(editwindow.EditWindow):
|
||||
"""Execute the user's PYTHONSTARTUP script if they have one."""
|
||||
if startupScript and os.path.isfile(startupScript):
|
||||
text = 'Startup script executed: ' + startupScript
|
||||
self.push('print(%r); execfile(%r)' % (text, startupScript))
|
||||
if PY3:
|
||||
self.push('print(%r)' % text)
|
||||
self.push('with open(%r, "r") as f:\n'
|
||||
' exec(f.read())\n' % (startupScript))
|
||||
else:
|
||||
self.push('print(%r); execfile(%r)' % (text, startupScript))
|
||||
self.interp.startupScript = startupScript
|
||||
else:
|
||||
self.push('')
|
||||
|
||||
@@ -15,6 +15,7 @@ __author__ += "Patrick K. O'Brien <pobrien@orbtech.com>"
|
||||
|
||||
import wx
|
||||
from wx import stc
|
||||
from wx.lib.six import PY3
|
||||
|
||||
import keyword
|
||||
import os
|
||||
@@ -622,7 +623,7 @@ class SlicesShell(editwindow.EditWindow):
|
||||
|
||||
# Import a default interpreter class if one isn't provided.
|
||||
if InterpClass == None:
|
||||
from interpreter import Interpreter
|
||||
from .interpreter import Interpreter
|
||||
else:
|
||||
Interpreter = InterpClass
|
||||
|
||||
@@ -963,13 +964,18 @@ class SlicesShell(editwindow.EditWindow):
|
||||
|
||||
This sets "close", "exit" and "quit" to a helpful string.
|
||||
"""
|
||||
import __builtin__
|
||||
__builtin__.close = __builtin__.exit = __builtin__.quit = \
|
||||
from wx.lib.six import PY3
|
||||
if PY3:
|
||||
import builtins
|
||||
else:
|
||||
import __builtin__
|
||||
builtins = __builtin__
|
||||
builtins.close = builtins.exit = builtins.quit = \
|
||||
'Click on the close button to leave the application.'
|
||||
__builtin__.cd = cd
|
||||
__builtin__.ls = ls
|
||||
__builtin__.pwd = pwd
|
||||
__builtin__.sx = sx
|
||||
builtins.cd = cd
|
||||
builtins.ls = ls
|
||||
builtins.pwd = pwd
|
||||
builtins.sx = sx
|
||||
|
||||
|
||||
def quit(self):
|
||||
@@ -992,7 +998,12 @@ class SlicesShell(editwindow.EditWindow):
|
||||
"""Execute the user's PYTHONSTARTUP script if they have one."""
|
||||
if startupScript and os.path.isfile(startupScript):
|
||||
text = 'Startup script executed: ' + startupScript
|
||||
self.push('print(%r); execfile(%r)' % (text, startupScript))
|
||||
if PY3:
|
||||
self.push('print(%r)' % text)
|
||||
self.push('with open(%r, "r") as f:\n'
|
||||
' exec(f.read())\n' % (startupScript))
|
||||
else:
|
||||
self.push('print(%r); execfile(%r)' % (text, startupScript))
|
||||
self.interp.startupScript = startupScript
|
||||
else:
|
||||
self.push('')
|
||||
|
||||
Reference in New Issue
Block a user