Merged wxPython 2.2.2 over to the main branch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8658 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2000-10-30 21:08:42 +00:00
parent 7874bf5430
commit c368d904fc
193 changed files with 21992 additions and 4366 deletions

View File

@@ -32,7 +32,7 @@ def MakeActiveXClass(CoClass, eventClass=None, eventObj=None):
can be used just like the wxWindow class, but will also respond
appropriately to the methods and properties of the COM object. If
this class, a derived class or a mix-in class has method names
that match the COM objects event names, they will be called
that match the COM object's event names, they will be called
automatically.
CoClass -- A COM control class from a module generated by

View File

@@ -31,7 +31,7 @@ class Tokenizer:
tname = tok_name[type]
if iskeyword(string):
tname = "KEY"
self.toks.append(tname, string, b, e)
self.toks.append( (tname, string, b, e) )
def readline(self):
t = self.text

View File

@@ -65,6 +65,12 @@ class FileBrowseButton(wxPanel):
self.fileMode = fileMode
self.changeCallback = changeCallback
# get background to match it
try:
self._bc = parent.GetBackgroundColour()
except:
pass
# create the dialog
self.createDialog(parent, id, pos, size, style )
# Setting a value causes the changeCallback to be called.
@@ -76,7 +82,11 @@ class FileBrowseButton(wxPanel):
def createDialog( self, parent, id, pos, size, style ):
"""Setup the graphic representation of the dialog"""
wxPanel.__init__ (self, parent, id, pos, size, style)
# try to set the background colour
try:
self.SetBackgroundColour(self._bc)
except:
pass
box = wxBoxSizer(wxHORIZONTAL)
self.label = self.createLabel( )
@@ -99,6 +109,10 @@ class FileBrowseButton(wxPanel):
if size.width != -1 or size.height != -1:
self.SetSize(size)
def SetBackgroundColour(self,color):
wxPanel.SetBackgroundColour(self,color)
self.label.SetBackgroundColour(color)
def createLabel( self ):
"""Create the label/caption"""
label = wxStaticText(self, -1, self.labelText, style =wxALIGN_RIGHT )
@@ -125,21 +139,27 @@ class FileBrowseButton(wxPanel):
EVT_BUTTON(button, ID, self.OnBrowse)
return button
def OnBrowse (self, event = None):
""" Going to browse for file... """
current = self.GetValue ()
current = self.GetValue()
directory = os.path.split(current)
if os.path.isdir( current):
directory = current
current = ''
elif directory and os.path.isdir( directory[0] ):
current = directory[1]
directory = directory [0]
else:
directory = self.startDirectory
dlg = wxFileDialog(self, self.dialogTitle, directory, current, self.fileMask, self.fileMode)
if dlg.ShowModal() == wxID_OK:
self.SetValue (dlg.GetPath())
dlg.Destroy()
def GetValue (self):
""" Convenient access to text control value """
return self.textControl.GetValue ()

View File

@@ -616,7 +616,7 @@ class TreePainter(Painter):
dc.SetPen(self.linepen)
dc.SetBrush(self.bgbrush)
dc.DrawRectangle(px -4, py-4, 9, 9)
self.knobs.append(kid, Rect(px -4, py -4, 9, 9))
self.knobs.append( (kid, Rect(px -4, py -4, 9, 9)) )
dc.SetPen(self.textpen)
if not kid.expanded:
dc.DrawLine(px, py -2, px, py + 3)
@@ -627,7 +627,7 @@ class TreePainter(Painter):
dc.SetPen(self.linepen)
dc.SetBrush(self.bgbrush)
dc.DrawRectangle(px -4, py-4, 9, 9)
self.knobs.append(node, Rect(px -4, py -4, 9, 9))
self.knobs.append( (node, Rect(px -4, py -4, 9, 9)) )
dc.SetPen(self.textpen)
if not node.expanded:
dc.DrawLine(px, py -2, px, py + 3)

View File

@@ -95,9 +95,10 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
# copyright/banner message
if banner is None:
self.write("Python %s on %s\n%s\n(%s)\n" %
(sys.version, sys.platform, sys.copyright,
self.__class__.__name__))
self.write("Python %s on %s\n" % #%s\n(%s)\n" %
(sys.version, sys.platform,
#sys.copyright, self.__class__.__name__
))
else:
self.write("%s\n" % banner)
@@ -143,17 +144,17 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
self.StyleSetSpec(wxSTC_STYLE_BRACELIGHT, p['bracegood'])
self.StyleSetSpec(wxSTC_STYLE_BRACEBAD, p['bracebad'])
self.StyleSetSpec(SCE_P_COMMENTLINE, p['comment'])
self.StyleSetSpec(SCE_P_NUMBER, p['number'])
self.StyleSetSpec(SCE_P_STRING, p['string'])
self.StyleSetSpec(SCE_P_CHARACTER, p['char'])
self.StyleSetSpec(SCE_P_WORD, p['keyword'])
self.StyleSetSpec(SCE_P_TRIPLE, p['triple'])
self.StyleSetSpec(SCE_P_TRIPLEDOUBLE, p['tripledouble'])
self.StyleSetSpec(SCE_P_CLASSNAME, p['class'])
self.StyleSetSpec(SCE_P_DEFNAME, p['def'])
self.StyleSetSpec(SCE_P_OPERATOR, p['operator'])
self.StyleSetSpec(SCE_P_COMMENTBLOCK, p['comment'])
self.StyleSetSpec(wxSTC_P_COMMENTLINE, p['comment'])
self.StyleSetSpec(wxSTC_P_NUMBER, p['number'])
self.StyleSetSpec(wxSTC_P_STRING, p['string'])
self.StyleSetSpec(wxSTC_P_CHARACTER, p['char'])
self.StyleSetSpec(wxSTC_P_WORD, p['keyword'])
self.StyleSetSpec(wxSTC_P_TRIPLE, p['triple'])
self.StyleSetSpec(wxSTC_P_TRIPLEDOUBLE, p['tripledouble'])
self.StyleSetSpec(wxSTC_P_CLASSNAME, p['class'])
self.StyleSetSpec(wxSTC_P_DEFNAME, p['def'])
self.StyleSetSpec(wxSTC_P_OPERATOR, p['operator'])
self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, p['comment'])
# used for writing to stdout, etc.
@@ -162,7 +163,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
pos = self.GetCurrentPos()
self.AddText(text)
self.StartStyling(pos, 0xFF)
self.SetStyleFor(len(text), style)
self.SetStyling(len(text), style)
self.EnsureCaretVisible()
wxYield()
@@ -174,7 +175,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
def Prompt(self):
# is the current line non-empty?
text, pos = self.GetCurrentLineText()
text, pos = self.GetCurLine()
if pos != 0:
self.AddText('\n')
self.AddText(self.props['ps1'])
@@ -198,7 +199,7 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
# if not on the last line, duplicate the current line
if self.GetLineCount()-1 != self.GetCurrentLine():
text, col = self.GetCurrentLineText()
text, col = self.GetCurLine()
prompt = self.props['ps1']
lp = len(prompt)
if text[:lp] == prompt:
@@ -251,14 +252,14 @@ class PyShellWindow(wxStyledTextCtrl, InteractiveInterpreter):
styleBefore = self.GetStyleAt(caretPos - 1)
# check before
if charBefore and charBefore in "[]{}()" and ord(styleBefore) == SCE_P_OPERATOR:
if charBefore and chr(charBefore) in "[]{}()" and styleBefore == wxSTC_P_OPERATOR:
braceAtCaret = caretPos - 1
# check after
if braceAtCaret < 0:
charAfter = self.GetCharAt(caretPos)
styleAfter = self.GetStyleAt(caretPos)
if charAfter and charAfter in "[]{}()" and ord(styleAfter) == SCE_P_OPERATOR:
if charAfter and chr(charAfter) in "[]{}()" and styleAfter == wxSTC_P_OPERATOR:
braceAtCaret = caretPos
if braceAtCaret >= 0:

View File

@@ -1,2 +0,0 @@
*.pyc

View File

@@ -1,45 +0,0 @@
#----------------------------------------------------------------------------
# Name: __init__.py
# Purpose: The presence of this file turns this directory into a
# Python package.
#
# Author: Robin Dunn
#
# Created: 18-May-1999
# RCS-ID: $Id$
# Copyright: (c) 1998 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------------
from sizer import *
from box import *
from border import *
from shape import *
#----------------------------------------------------------------------------
_msg = """\
Since the wxWindows library now includes its own sizers, the
classes in wxPython.lib.sizers have been deprecated. Please
see the Reference Manual for details of the new classes.
To contiunue using wxPython.lib.sizers without this
message you can set the WXP_OLDSIZERS envronment
variable to any value.
"""
import os
from wxPython.wx import wxMessageDialog, wxOK, wxICON_EXCLAMATION, wxPlatform
if not os.environ.has_key('WXP_OLDSIZERS'):
if wxPlatform == '__WXMSW__':
dlg = wxMessageDialog(None, _msg,
"Deprecated Feature",
wxOK | wxICON_EXCLAMATION)
dlg.ShowModal()
dlg.Destroy()
else:
print '\a'
print _msg
#----------------------------------------------------------------------------

View File

@@ -1,109 +0,0 @@
#----------------------------------------------------------------------
# Name: wxPython.lib.sizers.border
# Purpose: A Sizer that wraps an empty border around its contents
#
# Author: Robin Dunn
#
# Created: 9-June-1999
# RCS-ID: $Id$
# Copyright: (c) 1998 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------
from sizer import wxSizer
wxNORTH = 1
wxSOUTH = 2
wxEAST = 4
wxWEST = 8
wxALL = wxNORTH | wxSOUTH | wxEAST | wxWEST
#----------------------------------------------------------------------
class wxBorderSizer(wxSizer):
"""
wxBorderSizer
This sizer provides an empty buffer on one or more sides of it's
contents. It can only hold a single widget, but that can be a
sizer containing other items if you wish.
The sizer is constructed with a parameter specifying which sides
should have the border. You can use a logical OR of the following
values to specify the sides:
wxNORTH -- the top side
wxSOUTH -- the bottom side
wxEAST -- the right side
wxWEST -- the left side
wxALL -- all sides
The width in pixels of the border is specified when the child
widget is Added to the sizer.
"""
def __init__(self, sides = wxALL):
wxSizer.__init__(self)
self.sides = sides
def Add(self, widget, borderSize):
if self.children:
raise ValueError("wxBorderSizer can only contain one child.")
wxSizer.Add(self, widget, borderSize)
def CalcMin(self):
isSizer, widget, width, height, borderSize = self.children[0]
if isSizer:
width, height = widget.CalcMin()
if self.sides & wxEAST:
width = width + borderSize
if self.sides & wxWEST:
width = width + borderSize
if self.sides & wxNORTH:
height = height + borderSize
if self.sides & wxSOUTH:
height = height + borderSize
return width, height
def RecalcSizes(self):
isSizer, widget, width, height, borderSize = self.children[0]
width = self.size.width
height = self.size.height
px = self.origin.x
py = self.origin.y
if self.sides & wxWEST:
width = width - borderSize
px = px + borderSize
if self.sides & wxEAST:
width = width - borderSize
if self.sides & wxNORTH:
height = height - borderSize
py = py + borderSize
if self.sides & wxSOUTH:
height = height - borderSize
widget.SetDimensions(px, py, width, height)
#----------------------------------------------------------------------
#
# TODO... Make an abstract class wxBorder whose decendants can be added to
# a wxBorderSizer to provide drawing for the buffer area. Ideas are
# to provide a color border, beveled borders, rounded borders, etc.

View File

@@ -1,137 +0,0 @@
#----------------------------------------------------------------------
# Name: wxPython.lib.sizers.box
# Purpose: A sizer/layout managers for wxPython that places items in
# a stretchable box
#
# Author: Robin Dunn and Dirk Holtwick
#
# Created: 17-May-1999
# RCS-ID: $Id$
# Copyright: (c) 1998 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------
from sizer import wxSizer
from wxPython.wx import wxVERTICAL, wxHORIZONTAL
#----------------------------------------------------------------------
class wxBoxSizer(wxSizer):
"""
wxBoxSizer
A Sizer that lays components out in a box, in the order they are
added to the layout manager, with a given orientation. The
orientation is specified in the constructor with either wxVERTICAL
or wxHORIZONTAL.
The optional parameter to the Add method (for this sizer it's
called the stretch flag) can be used to flag one or more components
as stretchable, meaning that they will expand to fill available
space in the given orientation. The default is zero, or not
stretchable.
If the stretch flag is non-zero then the widget will stretch. If
the sizer holds more than one item that is stretchable then they
share the available space.
If the strech flag is greater than 1 then it serves as a weighting
factor. Widgets with a flag of 2 will get twice as much space as
widgets with 1, etc.
"""
def __init__(self, orientation, size = None):
wxSizer.__init__(self, size)
self.orientation = orientation
def CalcMin(self):
self.stretchable = 0 # number of stretchable items
self.minWidth = 0 # minimal size
self.minHeight = 0
self.fixedWidth = 0 # size without stretched widgets
self.fixedHeight = 0
# iterate through children
for (isSizer, widget, width, height, stretch) in self.children:
weight = 1
if stretch:
weight = stretch
if isSizer:
# let sub-sizers recalc their required space
width, height = widget.CalcMin()
# minimal size
if self.orientation == wxVERTICAL:
self.minHeight = self.minHeight + (height * weight)
self.minWidth = max(self.minWidth, width)
else:
self.minWidth = self.minWidth + (width * weight)
self.minHeight = max(self.minHeight, height)
# stretchable items
if stretch:
self.stretchable = self.stretchable + weight
else:
if self.orientation == wxVERTICAL:
self.fixedHeight = self.fixedHeight + height
self.fixedWidth = max(self.fixedWidth, width)
else:
self.fixedWidth = self.fixedWidth + width
self.fixedHeight = max(self.fixedHeight, height)
return self.minWidth, self.minHeight
def RecalcSizes(self):
# get current dimensions, save for performance
myWidth = self.size.width
myHeight = self.size.height
# relative recent positions & sizes
px = self.origin.x
py = self.origin.y
newWidth = 0
newHeight = 0
# calculate space for one stretched item
if self.stretchable:
if self.orientation == wxHORIZONTAL:
delta = (myWidth - self.fixedWidth) / self.stretchable
extra = (myWidth - self.fixedWidth) % self.stretchable
else:
delta = (myHeight - self.fixedHeight) / self.stretchable
extra = (myHeight - self.fixedHeight) % self.stretchable
# iterate children ...
for (isSizer, widget, width, height, stretch) in self.children:
weight = 1
if stretch:
weight = stretch
if isSizer:
width, height = widget.CalcMin()
# ... vertical
if self.orientation == wxVERTICAL:
newHeight = height
if stretch:
newHeight = (delta * weight) + extra # first stretchable gets extra pixels
extra = 0
widget.SetDimensions(px, py, myWidth, newHeight)
# ... horizontal
elif self.orientation == wxHORIZONTAL:
newWidth = width
if stretch:
newWidth = (delta * weight) + extra # first stretchable gets extra pixels
extra = 0
widget.SetDimensions(px, py, newWidth, myHeight)
px = px + newWidth
py = py + newHeight
#----------------------------------------------------------------------

View File

@@ -1,97 +0,0 @@
#----------------------------------------------------------------------
# Name: wxPython.lib.sizers.shape
# Purpose: A Sizer that preserves the shape (proportions)
# of the managed window
#
# Created: 7-October-1999
# RCS-ID: $Id$
# Copyright: SIA "ANK"
# Licence: wxWindows license
#----------------------------------------------------------------------
from sizer import wxSizer
wxANCHOR_NONE = 0
wxANCHOR_NORTH = 1
wxANCHOR_SOUTH = 2
wxANCHOR_EAST = 4
wxANCHOR_WEST = 8
wxANCHOR_NW = wxANCHOR_NORTH | wxANCHOR_WEST
wxANCHOR_NE = wxANCHOR_NORTH | wxANCHOR_EAST
wxANCHOR_SW = wxANCHOR_SOUTH | wxANCHOR_WEST
wxANCHOR_SE = wxANCHOR_SOUTH | wxANCHOR_EAST
#----------------------------------------------------------------------
class wxShapeSizer(wxSizer):
"""
wxShapeSizer
This sizer preserves the proportional dimensions of the managed
window, leaving empty space either in horizontal or vertical
dimension.
By default, the managed window is centered within allowed size.
You may specify an anchor parameter to leave all of the extra
space on one side: wxANCHOR_NORTH and wxANCHOR_SOUTH manage
vertical dimension, leaving extra space on the bottom or top side,
respectively; wxANCHOR_EAST and wxANCHOR_WEST do the same in
horizontal dimension. wxANCHOR_NW, wxANCHOR_NE, wxANCHOR_SW
and wxANCHOR_SE are short-cut names for combinations north+west,
north+east, south+west, south+east.
If both anchors are specified in either direction, south and east
take precedence over north and west, respectively. (Because of
gravity, widgets tend to fall down.)
"""
def __init__(self, anchor =wxANCHOR_NONE):
wxSizer.__init__(self)
self.anchor =anchor
def Add(self, widget):
if self.children:
raise ValueError("wxShapeSizer can only contain one child.")
wxSizer.Add(self, widget)
def CalcMin(self):
isSizer, widget, width, height, borderSize = self.children[0]
if isSizer:
width, height = widget.CalcMin()
return width, height
def RecalcSizes(self):
isSizer, widget, width, height, borderSize = self.children[0]
width =self.size.width
height =self.size.height
px =self.origin.x
py =self.origin.y
anchor =self.anchor
# get current dimensions of the managed window
w, h =self.CalcMin()
ratio =float(w) /h
# in what direction space should be added:
# -1: horisontal
# 1: vertical
# 0: shape is ok
dir =cmp(ratio /width *height, 1)
if dir <0:
# recalculate width
old_width =width
width =height *ratio
if anchor & wxANCHOR_EAST:
px =px +old_width -width
elif not (anchor & wxANCHOR_WEST):
px =px +(old_width -width) /2
elif dir >0:
# recalculate height
old_height =height
height =width /ratio
if anchor & wxANCHOR_SOUTH:
py =py +old_height -height
elif not (anchor & wxANCHOR_NORTH):
py =py +(old_height -height) /2
widget.SetDimensions(px, py, width, height)

View File

@@ -1,112 +0,0 @@
#----------------------------------------------------------------------
# Name: wxPython.lib.sizers.sizer
# Purpose: General purpose sizer/layout managers for wxPython
#
# Author: Robin Dunn and Dirk Holtwick
#
# Created: 17-May-1999
# RCS-ID: $Id$
# Copyright: (c) 1998 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------
from wxPython.wx import wxPoint, wxSize
#----------------------------------------------------------------------
class wxSizer:
"""
wxSizer
An abstract base sizer class. A sizer is able to manage the size and
layout of windows and/or child sizers.
Derived classes should implement CalcMin, and RecalcSizes.
A window or sizer is added to this sizer with the Add method:
def Add(self, widget, opt=0)
The meaning of the opt parameter is different for each type of
sizer. It may be a single value or a collection of values.
"""
def __init__(self, size = None):
self.children = []
self.origin = wxPoint(0, 0)
if not size:
size = wxSize(0,0)
self.size = size
def Add(self, widget, opt=0):
"""
Add a window or a sizer to this sizer. The meaning of the opt
parameter is different for each type of sizer. It may be a single
value or a collection of values.
"""
size = widget.GetSize()
isSizer = isinstance(widget, wxSizer)
self.children.append( (isSizer, widget, size.width, size.height, opt) )
def AddMany(self, widgets):
"""
Add a sequence (list, tuple, etc.) of widgets to this sizer. The
items in the sequence should be tuples containing valid args for
the Add method.
"""
for childinfo in widgets:
if type(childinfo) != type(()):
childinfo = (childinfo, )
apply(self.Add, childinfo)
def SetDimensions(self, x, y, width, height):
self.origin = wxPoint(x, y)
self.size = wxSize(width, height)
self.RecalcSizes()
def GetSize(self):
return self.size
def GetPosition(self):
return self.origin
def CalcMin(self):
raise NotImplementedError("Derived class should implement CalcMin")
def RecalcSizes(self):
raise NotImplementedError("Derived class should implement RecalcSizes")
def __getMinWindowSize(self, win):
"""
Calculate the best size window to hold this sizer, taking into
account the difference between client size and window size.
"""
min = self.GetMinSize()
a1,a2 = win.GetSizeTuple()
b1,b2 = win.GetClientSizeTuple()
w = min.width + (a1 - b1)
h = min.height + (a2 - b2)
return (w, h)
def GetMinSize(self):
minWidth, minHeight = self.CalcMin()
return wxSize(minWidth, minHeight)
def SetWindowSizeHints(self, win):
w, h = self.__getMinWindowSize(win)
win.SetSizeHints(w,h)
def FitWindow(self, win):
w, h = self.__getMinWindowSize(win)
win.SetSize(wxSize(w,h))
def Layout(self, size):
self.CalcMin()
self.SetDimensions(self.origin.x, self.origin.y,
size.width, size.height)
#----------------------------------------------------------------------

View File

@@ -184,7 +184,7 @@ class PlotCanvas(wx.wxWindow):
def OnPaint(self, event):
pdc = wx.wxPaintDC(self)
if self.last_draw is not None:
apply(self.draw, self.last_draw + (pdc,))
apply(self.draw, self.last_draw + (pdc,))
def reconfigure(self, event):
(new_width,new_height) = self.GetClientSizeTuple()
@@ -342,7 +342,7 @@ class PlotCanvas(wx.wxWindow):
ticks = []
t = -grid*Numeric.floor(-lower/grid)
while t <= upper:
ticks.append(t, format % (t,))
ticks.append( (t, format % (t,)) )
t = t + grid
return ticks