More Python2 migrations, patch from KA.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18837 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-01-20 23:41:15 +00:00
parent 2fa5f840d5
commit f86c833fe0
15 changed files with 51 additions and 58 deletions

View File

@@ -191,7 +191,7 @@ class wxPyNonWindowingErrorHandler:
self.file = file self.file = file
def write(self,s): def write(self,s):
import sys import sys
if string.find(s,"Warning") <> 0\ if s.find("Warning") <> 0\
and self.this_exception is not sys.last_traceback: and self.this_exception is not sys.last_traceback:
wxPyNonWindowingError("The Python interpreter encountered an error " wxPyNonWindowingError("The Python interpreter encountered an error "
"not handled by any\nexception handler--this " "not handled by any\nexception handler--this "
@@ -380,7 +380,7 @@ class wxPyNonFatalErrorDialogWithTraceback(wxDialog):
value = value[:-1] value = value[:-1]
if _debug: if _debug:
print "%s.SetTraceback(): ...SetValue('%s' (^M=\\r; ^J=\\n))"\ print "%s.SetTraceback(): ...SetValue('%s' (^M=\\r; ^J=\\n))"\
% (self,string.replace(value,'\n',"^J")) % (self,value.replace('\n',"^J"))
c.SetValue(value) c.SetValue(value)
# Despite using the wxADJUST_MINSIZE flag in the # Despite using the wxADJUST_MINSIZE flag in the
@@ -399,7 +399,7 @@ class wxPyNonFatalErrorDialogWithTraceback(wxDialog):
print "%s.SetTraceback(): %s.GetBestSize() = (%s,%s)"\ print "%s.SetTraceback(): %s.GetBestSize() = (%s,%s)"\
% (self,c,size.width,size.height) % (self,c,size.width,size.height)
w,h = 0,0 w,h = 0,0
for v in string.split(value,"\n"): for v in value.split("\n"):
pw,ph,d,e = t = c.GetFullTextExtent(v) pw,ph,d,e = t = c.GetFullTextExtent(v)
if _debug: if _debug:
print v, t print v, t
@@ -669,7 +669,7 @@ def _startmailerwithhtml(mailto,subject,html,text=None,mailfrom=None):
s = 'mailto:%s?subject=%s&body=%s' % (mailto, s = 'mailto:%s?subject=%s&body=%s' % (mailto,
urllib.quote(subject), urllib.quote(subject),
urllib.quote( urllib.quote(
string.replace(text,'\n','\r\n'), text.replace('\n','\r\n'),
"")) ""))
# Note that RFC 2368 requires that line breaks in the body of # Note that RFC 2368 requires that line breaks in the body of
@@ -797,7 +797,7 @@ def wxPyResizeHTMLWindowToDispelScrollbar(window,
# Will go no further than specified fraction of display size. # Will go no further than specified fraction of display size.
w = 200 w = 200
if type(fraction) == type(''): if type(fraction) == type(''):
fraction = string.atoi(fraction[:-1]) / 100. fraction = int(fraction[:-1]) / 100.
ds = wxDisplaySize () ds = wxDisplaySize ()
c = window.GetInternalRepresentation () c = window.GetInternalRepresentation ()
while w < ds[0] * fraction: while w < ds[0] * fraction:
@@ -812,7 +812,7 @@ def wxPyResizeHTMLWindowToDispelScrollbar(window,
w = w + 20 w = w + 20
else: else:
if type(defaultfraction) == type(''): if type(defaultfraction) == type(''):
defaultfraction = string.atoi(defaultfraction[:-1]) / 100. defaultfraction = int(defaultfraction[:-1]) / 100.
defaultsize = (defaultfraction * ds[0], defaultfraction * ds[1]) defaultsize = (defaultfraction * ds[0], defaultfraction * ds[1])
if _debug: if _debug:
print 'defaultsize =',defaultsize print 'defaultsize =',defaultsize

View File

@@ -13,7 +13,6 @@
from wxPython.wx import * from wxPython.wx import *
from CDate import * from CDate import *
import string, time
CalDays = [6, 0, 1, 2, 3, 4, 5] CalDays = [6, 0, 1, 2, 3, 4, 5]

View File

@@ -24,7 +24,6 @@
import os, time import os, time
from wxPython.wx import * from wxPython.wx import *
from string import *
import selection import selection
import images import images
@@ -650,7 +649,7 @@ class wxEditor(wxScrolledWindow):
def CopyToClipboard(self, linesOfText): def CopyToClipboard(self, linesOfText):
do = wxTextDataObject() do = wxTextDataObject()
do.SetText(string.join(linesOfText, os.linesep)) do.SetText(os.linesep.join(linesOfText))
wxTheClipboard.Open() wxTheClipboard.Open()
wxTheClipboard.SetData(do) wxTheClipboard.SetData(do)
wxTheClipboard.Close() wxTheClipboard.Close()

View File

@@ -17,7 +17,7 @@
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
import os, sys, string import os, sys
from wxPython.wx import * from wxPython.wx import *
dir_path = os.getcwd() dir_path = os.getcwd()
@@ -29,7 +29,7 @@ def ConvertBMP(file_nm):
fl_fld = os.path.splitext(file_nm) fl_fld = os.path.splitext(file_nm)
ext = fl_fld[1] ext = fl_fld[1]
ext = string.lower(ext[1:]) ext = ext[1:].lower()
if ext == 'bmp': if ext == 'bmp':
image = wxImage(file_nm, wxBITMAP_TYPE_BMP) image = wxImage(file_nm, wxBITMAP_TYPE_BMP)
elif ext == 'gif': elif ext == 'gif':
@@ -278,14 +278,14 @@ class FindFiles:
dirlist = [".."] dirlist = [".."]
self.dir = dir self.dir = dir
self.file = "" self.file = ""
mask = string.upper(mask) mask = mask.upper()
pattern = self.MakeRegex(mask) pattern = self.MakeRegex(mask)
for i in os.listdir(dir): for i in os.listdir(dir):
if i == "." or i == "..": if i == "." or i == "..":
continue continue
path = os.path.join(dir, i) path = os.path.join(dir, i)
path = string.upper(path) path = path.upper()
value = string.upper(i) value = i.upper()
if pattern.match(value) != None: if pattern.match(value) != None:
filelist.append(i) filelist.append(i)

View File

@@ -121,7 +121,7 @@ see the appropriate "stub" file in the wxPython demo.
""" """
from wxPython.wx import * from wxPython.wx import *
import string, sys, types, tempfile, os import sys, tempfile, os
class _MyStatusBar(wxStatusBar): class _MyStatusBar(wxStatusBar):
def __init__(self, parent,callbacks=None,useopenbutton=0): def __init__(self, parent,callbacks=None,useopenbutton=0):

View File

@@ -1,7 +1,7 @@
from wxPython.wx import wxLayoutConstraints,\ from wxPython.wx import wxLayoutConstraints,\
wxTop, wxLeft, wxBottom, wxRight, \ wxTop, wxLeft, wxBottom, wxRight, \
wxHeight, wxWidth, wxCentreX, wxCentreY wxHeight, wxWidth, wxCentreX, wxCentreY
import re,string import re
class Layoutf(wxLayoutConstraints): class Layoutf(wxLayoutConstraints):
""" """
@@ -130,8 +130,8 @@ time of this writing not documented.
self.pack(pstr,winlist) self.pack(pstr,winlist)
def pack(self, pstr, winlist): def pack(self, pstr, winlist):
pstr = string.lower(pstr) pstr = pstr.lower()
for item in string.split(pstr,';'): for item in pstr.split(';'):
m = self.rexp1.match(item) m = self.rexp1.match(item)
if m: if m:
g = list(m.groups()) g = list(m.groups())
@@ -159,8 +159,8 @@ time of this writing not documented.
else: func(winlist[g[4]], cmp) else: func(winlist[g[4]], cmp)
def debug_pack(self, pstr, winlist): def debug_pack(self, pstr, winlist):
pstr = string.lower(pstr) pstr = pstr.lower()
for item in string.split(pstr,';'): for item in pstr.split(';'):
m = self.rexp1.match(item) m = self.rexp1.match(item)
if m: if m:
g = list(m.groups()) g = list(m.groups())

View File

@@ -405,8 +405,7 @@ class FSTreeModel(BasicTreeModel):
""" """
def __init__(self, path): def __init__(self, path):
BasicTreeModel.__init__(self) BasicTreeModel.__init__(self)
import string fw = FileWrapper(path, path.split(os.sep)[-1])
fw = FileWrapper(path, string.split(path, os.sep)[-1])
self._Build(path, fw) self._Build(path, fw)
self.SetRoot(fw) self.SetRoot(fw)
self._editable = true self._editable = true
@@ -431,8 +430,7 @@ class LateFSTreeModel(FSTreeModel):
""" """
def __init__(self, path): def __init__(self, path):
BasicTreeModel.__init__(self) BasicTreeModel.__init__(self)
import string name = path.split(os.sep)[-1]
name = string.split(path, os.sep)[-1]
pathpart = path[:-len(name)] pathpart = path[:-len(name)]
fw = FileWrapper(pathpart, name) fw = FileWrapper(pathpart, name)
self._Build(path, fw) self._Build(path, fw)

View File

@@ -15,7 +15,7 @@
# add index to data list after parsing total pages for paging # add index to data list after parsing total pages for paging
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
import os, sys, string, copy import os, sys, copy
from wxPython.wx import * from wxPython.wx import *
import copy import copy
@@ -46,7 +46,7 @@ class PrintBase:
return wxColour(fcolour[0], fcolour[1], fcolour[2]) return wxColour(fcolour[0], fcolour[1], fcolour[2])
def OutTextRegion(self, textout, txtdraw = TRUE): def OutTextRegion(self, textout, txtdraw = TRUE):
textlines = string.splitfields(textout, '\n') textlines = textout.split('\n')
y = copy.copy(self.y) + self.pt_space_before y = copy.copy(self.y) + self.pt_space_before
for text in textlines: for text in textlines:
remain = 'X' remain = 'X'
@@ -88,7 +88,7 @@ class PrintBase:
def SetFlow(self, ln_text, width): def SetFlow(self, ln_text, width):
width = width - self.pcell_right_margin width = width - self.pcell_right_margin
text = "" text = ""
split = string.split(ln_text) split = ln_text.split()
if len(split) == 1: if len(split) == 1:
return ln_text, "" return ln_text, ""
@@ -109,12 +109,12 @@ class PrintBase:
text = text + bword text = text + bword
cnt = cnt + 1 cnt = cnt + 1
else: else:
remain = string.joinfields(split[cnt:],' ') remain = ' '.join(split[cnt:])
text = string.strip(text) text = text.strip()
return text, remain return text, remain
remain = string.joinfields(split[cnt:],' ') remain = ' '.join(split[cnt:])
vout = string.strip(text) vout = text.strip()
return vout, remain return vout, remain
def SetChar(self, ln_text, width): # truncate string to fit into width def SetChar(self, ln_text, width): # truncate string to fit into width
@@ -129,7 +129,7 @@ class PrintBase:
return text return text
def OutTextPageWidth(self, textout, y_out, align, indent, txtdraw = TRUE): def OutTextPageWidth(self, textout, y_out, align, indent, txtdraw = TRUE):
textlines = string.splitfields(textout, '\n') textlines = textout.split('\n')
y = copy.copy(y_out) y = copy.copy(y_out)
pagew = self.parent.page_width * self.pwidth # full page width pagew = self.parent.page_width * self.pwidth # full page width
@@ -169,7 +169,7 @@ class PrintBase:
def GetNow(self): def GetNow(self):
full = str(wxDateTime_Now()) # get the current date and time in print format full = str(wxDateTime_Now()) # get the current date and time in print format
flds = string.splitfields(full) flds = full.split()
date = flds[0] date = flds[0]
time = flds[1] time = flds[1]
return date, time return date, time

View File

@@ -30,7 +30,7 @@ etc... But it's a good start.
from wxPython.wx import * from wxPython.wx import *
from wxPython.stc import * from wxPython.stc import *
import sys, string, keyword import sys, keyword
from code import InteractiveInterpreter from code import InteractiveInterpreter
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@@ -238,7 +238,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
lastPos = self.GetTextLength() lastPos = self.GetTextLength()
if self.lastPromptPos and self.lastPromptPos != lastPos: if self.lastPromptPos and self.lastPromptPos != lastPos:
self.SetLexer(wxSTC_LEX_PYTHON) self.SetLexer(wxSTC_LEX_PYTHON)
self.SetKeywords(0, string.join(keyword.kwlist)) self.SetKeywords(0, ' '.join(keyword.kwlist))
self.Colourise(self.lastPromptPos, lastPos) self.Colourise(self.lastPromptPos, lastPos)

View File

@@ -72,7 +72,6 @@ from wxPython.wx import *
import xmlrpcserver,xmlrpclib import xmlrpcserver,xmlrpclib
import threading import threading
import SocketServer import SocketServer
import string
import new import new
import sys import sys
@@ -305,7 +304,7 @@ class rpcMixin:
event.rpcStatusLock.acquire() event.rpcStatusLock.acquire()
doQuit = 0 doQuit = 0
try: try:
methsplit = string.split(event.method,'.') methsplit = event.method.split('.')
meth = self meth = self
for piece in methsplit: for piece in methsplit:
meth = getattr(meth,piece) meth = getattr(meth,piece)

View File

@@ -5,7 +5,7 @@
from wxPython.wx import * from wxPython.wx import *
from wxPython.grid import * from wxPython.grid import *
from string import * import string
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
class CTextCellEditor(wxTextCtrl): class CTextCellEditor(wxTextCtrl):
@@ -124,7 +124,7 @@ class CCellEditor(wxPyGridCellEditor):
elif key < 256 and key >= 0 and chr(key) in string.printable: elif key < 256 and key >= 0 and chr(key) in string.printable:
ch = chr(key) ch = chr(key)
if not evt.ShiftDown(): if not evt.ShiftDown():
ch = string.lower(ch) ch = ch.lower()
if ch is not None: # If are at this point with a key, if ch is not None: # If are at this point with a key,
self._tc.SetValue(ch) # replace the contents of the text control. self._tc.SetValue(ch) # replace the contents of the text control.
@@ -265,10 +265,10 @@ class CSheet(wxGrid):
crlf = chr(13) + chr(10) # CrLf characters crlf = chr(13) + chr(10) # CrLf characters
tab = chr(9) # Tab character tab = chr(9) # Tab character
rows = split(s, crlf) # split into rows rows = s.split(crlf) # split into rows
rows = rows[0:-1] # leave out last element, which is always empty rows = rows[0:-1] # leave out last element, which is always empty
for i in range(0, len(rows)): # split rows into elements for i in range(0, len(rows)): # split rows into elements
rows[i] = split(rows[i], tab) rows[i] = rows[i].split(tab)
# Get the starting and ending cell range to paste into # Get the starting and ending cell range to paste into
if self._selected == None: # If no cells selected... if self._selected == None: # If no cells selected...

View File

@@ -29,7 +29,7 @@ History:
__version__ ="$Revision$" __version__ ="$Revision$"
# $RCSfile$ # $RCSfile$
import sys, string, code, traceback import sys, code, traceback
from wxPython.wx import * from wxPython.wx import *
from wxPython.html import * from wxPython.html import *
@@ -90,7 +90,7 @@ class PyShellInput(wxPanel):
return return
text =self.entry.GetValue() text =self.entry.GetValue()
# weird CRLF thingy # weird CRLF thingy
text =string.replace(text, "\r\n", "\n") text = text.replace("\r\n", "\n")
# see if we've finished # see if we've finished
if (not (self.first_line or text[-1] =="\n") # in continuation mode if (not (self.first_line or text[-1] =="\n") # in continuation mode
or (text[-1] =="\\") # escaped newline or (text[-1] =="\\") # escaped newline
@@ -193,9 +193,9 @@ class PyShellOutput(wxPanel):
if 0 and __debug__: sys.__stdout__.write(text) if 0 and __debug__: sys.__stdout__.write(text)
# handle entities # handle entities
for (symbol, eref) in self.erefs: for (symbol, eref) in self.erefs:
text =string.replace(text, symbol, eref) text = text.replace(symbol, eref)
# replace newlines # replace newlines
text =string.replace(text, "\n", style[2]) text = text.replace("\n", style[2])
# add to contents # add to contents
self.text =self.text +style[0] +text +style[1] self.text =self.text +style[0] +text +style[1]
if not self.in_batch: self.UpdWindow() if not self.in_batch: self.UpdWindow()
@@ -302,14 +302,14 @@ class PyShell(wxPanel):
(etype, value, tb) =sys.exc_info() (etype, value, tb) =sys.exc_info()
# remove myself from traceback # remove myself from traceback
tblist =traceback.extract_tb(tb)[1:] tblist =traceback.extract_tb(tb)[1:]
msg =string.join(traceback.format_exception_only(etype, value) msg = ' '.join(traceback.format_exception_only(etype, value)
+traceback.format_list(tblist)) +traceback.format_list(tblist))
self.output.write_exc(msg) self.output.write_exc(msg)
def ShowSyntaxError(self): def ShowSyntaxError(self):
"""display message about syntax error (no traceback here)""" """display message about syntax error (no traceback here)"""
(etype, value, tb) =sys.exc_info() (etype, value, tb) =sys.exc_info()
msg =string.join(traceback.format_exception_only(etype, value)) msg = ' '.join(traceback.format_exception_only(etype, value))
self.output.write_exc(msg) self.output.write_exc(msg)
def OnSize(self, event): def OnSize(self, event):

View File

@@ -738,7 +738,7 @@ class wxTimeCtrl(wxTextCtrl):
# Process AM/PM cell # Process AM/PM cell
elif pos == dict_start['am_pm']: elif pos == dict_start['am_pm']:
char = string.upper(char) char = char.upper()
if char not in ('A','P'): return # disallow all but A or P as 1st char of column if char not in ('A','P'): return # disallow all but A or P as 1st char of column
newtext = text[:pos] + char + text[pos+1:] newtext = text[:pos] + char + text[pos+1:]
else: return # not a valid position else: return # not a valid position

View File

@@ -20,7 +20,6 @@ Original comment follows below:
""" """
from wxPython import wx from wxPython import wx
import string
# Not everybody will have Numeric, so let's be cool about it... # Not everybody will have Numeric, so let's be cool about it...
try: try:

View File

@@ -89,7 +89,6 @@ from wxPython.wx import *
from wxPython.html import * from wxPython.html import *
import wxPython.wx import wxPython.wx
import string
import types import types
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@@ -146,12 +145,12 @@ class wxpTagHandler(wxHtmlWinTagHandler):
if tag.HasParam('WIDTH'): if tag.HasParam('WIDTH'):
width = tag.GetParam('WIDTH') width = tag.GetParam('WIDTH')
if width[-1] == '%': if width[-1] == '%':
self.ctx.floatWidth = string.atoi(width[:-1], 0) self.ctx.floatWidth = int(width[:-1], 0)
width = self.ctx.floatWidth width = self.ctx.floatWidth
else: else:
width = string.atoi(width) width = int(width)
if tag.HasParam('HEIGHT'): if tag.HasParam('HEIGHT'):
height = string.atoi(tag.GetParam('HEIGHT')) height = int(tag.GetParam('HEIGHT'))
self.ctx.kwargs['size'] = wxSize(width, height) self.ctx.kwargs['size'] = wxSize(width, height)
# parse up to the closing tag, and gather any nested Param tags. # parse up to the closing tag, and gather any nested Param tags.
@@ -185,7 +184,7 @@ class wxpTagHandler(wxHtmlWinTagHandler):
if name == 'id': if name == 'id':
theID = -1 theID = -1
try: try:
theID = string.atoi(value) theID = int(value)
except ValueError: except ValueError:
theID = getattr(self.ctx.classMod, value) theID = getattr(self.ctx.classMod, value)
value = theID value = theID
@@ -202,9 +201,9 @@ class wxpTagHandler(wxHtmlWinTagHandler):
# convert to wxColour # convert to wxColour
elif value[0] == '#': elif value[0] == '#':
try: try:
red = string.atoi('0x'+value[1:3], 16) red = int('0x'+value[1:3], 16)
green = string.atoi('0x'+value[3:5], 16) green = int('0x'+value[3:5], 16)
blue = string.atoi('0x'+value[5:], 16) blue = int('0x'+value[5:], 16)
value = wxColor(red, green, blue) value = wxColor(red, green, blue)
except: except:
pass pass
@@ -229,7 +228,7 @@ class _Context:
# Function to assist with importing packages # Function to assist with importing packages
def _my_import(name): def _my_import(name):
mod = __import__(name) mod = __import__(name)
components = string.split(name, '.') components = name.split('.')
for comp in components[1:]: for comp in components[1:]:
mod = getattr(mod, comp) mod = getattr(mod, comp)
return mod return mod