Merged wxPython 2.4.x to the 2.5 branch (Finally!!!)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19793 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-03-25 06:35:27 +00:00
parent 9b4e3f352b
commit 1e4a197e4c
586 changed files with 62691 additions and 17740 deletions

View File

@@ -28,13 +28,15 @@ wxGenBitmapToggleButton the same but with bitmaps.
"""
from wxPython.wx import *
import imageutils
#----------------------------------------------------------------------
class wxGenButtonEvent(wxPyCommandEvent):
def __init__(self, eventType, ID):
wxPyCommandEvent.__init__(self, eventType, ID)
self.isDown = false
self.isDown = False
self.theButton = None
def SetIsDown(self, isDown):
@@ -63,10 +65,10 @@ class wxGenButton(wxPyControl):
style = wxNO_BORDER
wxPyControl.__init__(self, parent, ID, pos, size, style, validator, name)
self.up = true
self.up = True
self.bezelWidth = 2
self.hasFocus = false
self.useFocusInd = true
self.hasFocus = False
self.useFocusInd = True
self.SetLabel(label)
self.SetPosition(pos)
@@ -131,6 +133,11 @@ class wxGenButton(wxPyControl):
return self.IsShown() and self.IsEnabled()
def Enable(self, enable=True):
wxPyControl.Enable(self, enable)
self.Refresh()
def SetBezelWidth(self, width):
"""Set the width of the 3D effect"""
self.bezelWidth = width
@@ -187,7 +194,7 @@ class wxGenButton(wxPyControl):
def _GetLabelSize(self):
""" used internally """
w, h = self.GetTextExtent(self.GetLabel())
return w, h, true
return w, h, True
def Notify(self):
@@ -270,7 +277,7 @@ class wxGenButton(wxPyControl):
def OnLeftDown(self, event):
if not self.IsEnabled():
return
self.up = false
self.up = False
self.CaptureMouse()
self.SetFocus()
self.Refresh()
@@ -278,35 +285,36 @@ class wxGenButton(wxPyControl):
def OnLeftUp(self, event):
if not self.IsEnabled():
if not self.IsEnabled() or not self.HasCapture():
return
self.ReleaseMouse()
if not self.up: # if the button was down when the mouse was released...
self.Notify()
self.up = true
self.Refresh()
event.Skip()
if self.HasCapture():
self.ReleaseMouse()
if not self.up: # if the button was down when the mouse was released...
self.Notify()
self.up = True
self.Refresh()
event.Skip()
def OnMotion(self, event):
if not self.IsEnabled():
if not self.IsEnabled() or not self.HasCapture():
return
if event.LeftIsDown():
if event.LeftIsDown() and self.HasCapture():
x,y = event.GetPositionTuple()
w,h = self.GetClientSizeTuple()
if self.up and x<w and x>=0 and y<h and y>=0:
self.up = false
self.up = False
self.Refresh()
return
if not self.up and (x<0 or y<0 or x>=w or y>=h):
self.up = true
self.up = True
self.Refresh()
return
event.Skip()
def OnGainFocus(self, event):
self.hasFocus = true
self.hasFocus = True
dc = wxClientDC(self)
w, h = self.GetClientSizeTuple()
if self.useFocusInd:
@@ -314,7 +322,7 @@ class wxGenButton(wxPyControl):
def OnLoseFocus(self, event):
self.hasFocus = false
self.hasFocus = False
dc = wxClientDC(self)
w, h = self.GetClientSizeTuple()
if self.useFocusInd:
@@ -323,14 +331,14 @@ class wxGenButton(wxPyControl):
def OnKeyDown(self, event):
if self.hasFocus and event.KeyCode() == ord(" "):
self.up = false
self.up = False
self.Refresh()
event.Skip()
def OnKeyUp(self, event):
if self.hasFocus and event.KeyCode() == ord(" "):
self.up = true
self.up = True
self.Notify()
self.Refresh()
event.Skip()
@@ -343,10 +351,10 @@ class wxGenBitmapButton(wxGenButton):
pos = wxDefaultPosition, size = wxDefaultSize,
style = 0, validator = wxDefaultValidator,
name = "genbutton"):
self.bmpLabel = bitmap
self.bmpDisabled = None
self.bmpFocus = None
self.bmpSelected = None
self.SetBitmapLabel(bitmap)
wxGenButton.__init__(self, parent, ID, "", pos, size, style, validator, name)
@@ -367,22 +375,32 @@ class wxGenBitmapButton(wxGenButton):
def SetBitmapFocus(self, bitmap):
"""Set bitmap to display when the button has the focus"""
self.bmpFocus = bitmap
self.SetUseFocusIndicator(false)
self.SetUseFocusIndicator(False)
def SetBitmapSelected(self, bitmap):
"""Set bitmap to display when the button is selected (pressed down)"""
self.bmpSelected = bitmap
def SetBitmapLabel(self, bitmap):
"""Set the bitmap to display normally. This is the only one that is required."""
def SetBitmapLabel(self, bitmap, createOthers=True):
"""
Set the bitmap to display normally.
This is the only one that is required. If
createOthers is True, then the other bitmaps
will be generated on the fly. Currently,
only the disabled bitmap is generated.
"""
self.bmpLabel = bitmap
if bitmap is not None and createOthers:
image = wxImageFromBitmap(bitmap)
imageutils.grayOut(image)
self.SetBitmapDisabled(wxBitmapFromImage(image))
def _GetLabelSize(self):
""" used internally """
if not self.bmpLabel:
return -1, -1, false
return self.bmpLabel.GetWidth()+2, self.bmpLabel.GetHeight()+2, false
return -1, -1, False
return self.bmpLabel.GetWidth()+2, self.bmpLabel.GetHeight()+2, False
def DrawLabel(self, dc, width, height, dw=0, dy=0):
bmp = self.bmpLabel
@@ -415,7 +433,7 @@ class wxGenBitmapTextButton(wxGenBitmapButton): # generic bitmapped button w
""" used internally """
w, h = self.GetTextExtent(self.GetLabel())
if not self.bmpLabel:
return w, h, true # if there isn't a bitmap use the size of the text
return w, h, True # if there isn't a bitmap use the size of the text
w_bmp = self.bmpLabel.GetWidth()+2
h_bmp = self.bmpLabel.GetHeight()+2
@@ -424,7 +442,7 @@ class wxGenBitmapTextButton(wxGenBitmapButton): # generic bitmapped button w
height = h_bmp
else:
height = h
return width, height, true
return width, height, True
def DrawLabel(self, dc, width, height, dw=0, dy=0):
@@ -456,10 +474,10 @@ class wxGenBitmapTextButton(wxGenBitmapButton): # generic bitmapped button w
pos_x = (width-bw-tw)/2+dw # adjust for bitmap and text to centre
if bmp !=None:
dc.DrawBitmap(bmp, pos_x, (height-bh)/2+dy, hasMask) # draw bitmap if available
dc.DrawBitmap(bmp, pos_x, (height-bh)/2+dy, hasMask) # draw bitmap if available
pos_x = pos_x + 2 # extra spacing from bitmap
dc.DrawText(label, pos_x + dw+bw, (height-th)/2+dy) # draw the text
dc.DrawText(label, pos_x + dw+bw, (height-th)/2+dy) # draw the text
#----------------------------------------------------------------------
@@ -468,9 +486,12 @@ class wxGenBitmapTextButton(wxGenBitmapButton): # generic bitmapped button w
class __ToggleMixin:
def SetToggle(self, flag):
self.up = not flag
self.Refresh()
SetValue = SetToggle
def GetToggle(self):
return not self.up
GetValue = GetToggle
def OnLeftDown(self, event):
if not self.IsEnabled():
@@ -482,16 +503,33 @@ class __ToggleMixin:
self.Refresh()
def OnLeftUp(self, event):
if not self.IsEnabled():
if not self.IsEnabled() or not self.HasCapture():
return
if self.up != self.saveUp:
self.Notify()
self.ReleaseMouse()
self.Refresh()
if self.HasCapture():
if self.up != self.saveUp:
self.Notify()
self.ReleaseMouse()
self.Refresh()
def OnKeyDown(self, event):
event.Skip()
def OnMotion(self, event):
if not self.IsEnabled():
return
if event.LeftIsDown() and self.HasCapture():
x,y = event.GetPositionTuple()
w,h = self.GetClientSizeTuple()
if x<w and x>=0 and y<h and y>=0:
self.up = not self.saveUp
self.Refresh()
return
if (x<0 or y<0 or x>=w or y>=h):
self.up = self.saveUp
self.Refresh()
return
event.Skip()
def OnKeyUp(self, event):
if self.hasFocus and event.KeyCode() == ord(" "):
self.up = not self.up