def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1)
self.log = log
+ ##self.SetBackgroundColour("sky blue")
sizer = wx.FlexGridSizer(1, 3, 20, 20)
b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
b.SetBezelWidth(5)
###b.SetBestSize()
+ b.SetSizeHints(wx.DefaultSize)
b.SetBackgroundColour("Navy")
b.SetForegroundColour(wx.WHITE)
b.SetToolTipString("This is a BIG button...")
import wx
import images
+
+USE_GENERIC = 0
+
+if USE_GENERIC:
+ from wx.lib.stattext import GenStaticText as StaticText
+ from wx.lib.statbmp import GenStaticBitmap as StaticBitmap
+else:
+ StaticText = wx.StaticText
+ StaticBitmap = wx.StaticBitmap
+
+
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1)
self.log = log
- self.count = 0
+ ##self.SetBackgroundColour("sky blue")
- wx.StaticText(self, -1, "This is a wx.StaticBitmap.", (45, 15))
+ StaticText(self, -1, "This is a wx.StaticBitmap.", (45, 15))
bmp = images.getTest2Bitmap()
mask = wx.Mask(bmp, wx.BLUE)
bmp.SetMask(mask)
- wx.StaticBitmap(self, -1, bmp, (80, 50), (bmp.GetWidth(), bmp.GetHeight()))
+ StaticBitmap(self, -1, bmp, (80, 50), (bmp.GetWidth(), bmp.GetHeight()))
bmp = images.getRobinBitmap()
- wx.StaticBitmap(self, -1, bmp, (80, 150))
+ StaticBitmap(self, -1, bmp, (80, 150))
- wx.StaticText(self, -1, "Hey, if Ousterhout can do it, so can I.", (200, 175))
+ StaticText(self, -1, "Hey, if Ousterhout can do it, so can I.", (200, 175))
#----------------------------------------------------------------------
USE_GENERIC = 0
+
if USE_GENERIC:
from wx.lib.stattext import GenStaticText as StaticText
else:
class TestPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
+ ##self.SetBackgroundColour("sky blue")
StaticText(self, -1, "This is an example of static text", (20, 10))
StaticText(self, -1, "using the wx.StaticText Control.", (20, 30))
StaticText(
- self, -1, "Is this yellow?", (20, 70), (90, -1)
+ self, -1, "Is this yellow?", (20, 70), (120, -1)
).SetBackgroundColour('Yellow')
StaticText(
- self, -1, "align center", (120, 70), (90, -1), wx.ALIGN_CENTER
+ self, -1, "align center", (160, 70), (120, -1), wx.ALIGN_CENTER
).SetBackgroundColour('Yellow')
StaticText(
- self, -1, "align right", (220, 70), (90, -1), wx.ALIGN_RIGHT
+ self, -1, "align right", (300, 70), (120, -1), wx.ALIGN_RIGHT
).SetBackgroundColour('Yellow')
str = "This is a different font."
- text = StaticText(self, -1, str, (20, 100))
+ text = StaticText(self, -1, str, (20, 120))
font = wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL)
text.SetFont(font)
text.SetSize(text.GetBestSize())
- StaticText(self, -1, "Multi-line wx.StaticText\nline 2\nline 3\n\nafter empty line", (20,150))
- StaticText(self, -1, "Align right multi-line\nline 2\nline 3\n\nafter empty line", (220,150), style=wx.ALIGN_RIGHT)
+ StaticText(self, -1,
+ "Multi-line wx.StaticText\nline 2\nline 3\n\nafter empty line",
+ (20,170))
+ StaticText(self, -1,
+ "Align right multi-line\nline 2\nline 3\n\nafter empty line",
+ (220,170), style=wx.ALIGN_RIGHT)
#---------------------------------------------------------------------------
Deprecated the wx.Sizer.AddWindow, AddSizer, AddSpacer methods as well
as their Insert* and Prepend* counterparts.
+Added a generic StaticBitmap class in wx.lib.statbmp for the same
+reasons that stattext was created, so it could be mouse sensitive on
+all platforms like normal windows. Also updated stattext.py and
+buttons.py to handle attribute (font & colour) defaults and
+inheritance the new way. If you have custom controls of your own you
+should review stattxt.py or one of the others to see how it is to be
+done.
self.useFocusInd = True
self.SetLabel(label)
- self.SetPosition(pos)
- font = parent.GetFont()
- if not font.Ok():
- font = wx.SystemSettings.GetSystemFont(wx.SYS_DEFAULT_GUI_FONT)
- self.SetFont(font)
+ self.InheritAttributes()
self.SetBestSize(size)
self.InitColours()
and set a good size.
"""
if size is None:
- size = wx.Size(-1,-1)
- if type(size) == type(()):
- size = wx.Size(size[0], size[1])
- size = wx.Size(size.width, size.height) # make a copy
-
- best = self.GetBestSize()
- if size.width == -1:
- size.width = best.width
- if size.height == -1:
- size.height = best.height
-
- self.SetSize(size)
+ size = wx.DefaultSize
+ wx.PyControl.SetBestSize(self, size)
def DoGetBestSize(self):
- """Overridden base class virtual. Determines the best size of the
- button based on the label and bezel size."""
+ """
+ Overridden base class virtual. Determines the best size of the
+ button based on the label and bezel size.
+ """
w, h, useMin = self._GetLabelSize()
defSize = wx.Button.GetDefaultSize()
width = 12 + w
return self.IsShown() and self.IsEnabled()
+ def GetDefaultAttributes(self):
+ """
+ Overridden base class virtual. By default we should use
+ the same font/colour attributes as the native Button.
+ """
+ return wx.Button.GetClassDefaultAttributes()
+
+
+ def ShouldInheritColours(self):
+ """
+ Overridden base class virtual. Buttons usually don't inherit
+ the parent's colours.
+ """
+ return False
+
+
def Enable(self, enable=True):
wx.PyControl.Enable(self, enable)
self.Refresh()
def InitColours(self):
- faceClr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE)
- textClr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNTEXT)
- self.faceDnClr = faceClr
- self.SetBackgroundColour(faceClr)
- self.SetForegroundColour(textClr)
-
- shadowClr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNSHADOW)
- highlightClr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
- self.shadowPen = wx.Pen(shadowClr, 1, wx.SOLID)
- self.highlightPen = wx.Pen(highlightClr, 1, wx.SOLID)
+ """
+ Calculate a new set of highlight and shadow colours based on
+ the background colour. Works okay if the colour is dark...
+ """
+ faceClr = self.GetBackgroundColour()
+ r, g, b = faceClr.Get()
+ fr, fg, fb = min(255,r+32), min(255,g+32), min(255,b+32)
+ self.faceDnClr = wx.Colour(fr, fg, fb)
+ sr, sg, sb = max(0,r-32), max(0,g-32), max(0,b-32)
+ self.shadowPen = wx.Pen(wx.Colour(sr,sg,sb), 1, wx.SOLID)
+ hr, hg, hb = min(255,r+64), min(255,g+64), min(255,b+64)
+ self.highlightPen = wx.Pen(wx.Colour(hr,hg,hb), 1, wx.SOLID)
+ self.focusClr = wx.Colour(hr, hg, hb)
+
+ textClr = self.GetForegroundColour()
if wx.Platform == "__WXMAC__":
self.focusIndPen = wx.Pen(textClr, 1, wx.SOLID)
else:
self.focusIndPen = wx.Pen(textClr, 1, wx.USER_DASH)
self.focusIndPen.SetDashes([1,1])
self.focusIndPen.SetCap(wx.CAP_BUTT)
- self.focusClr = highlightClr
-
-
+
+
def SetBackgroundColour(self, colour):
wx.PyControl.SetBackgroundColour(self, colour)
- colour = self.GetBackgroundColour()
+ self.InitColours()
- # Calculate a new set of highlight and shadow colours based on
- # the new background colour. Works okay if the colour is dark...
- r, g, b = colour.Get()
- fr, fg, fb = min(255,r+32), min(255,g+32), min(255,b+32)
- self.faceDnClr = wx.Colour(fr, fg, fb)
- sr, sg, sb = max(0,r-32), max(0,g-32), max(0,b-32)
- self.shadowPen = wx.Pen(wx.Colour(sr,sg,sb), 1, wx.SOLID)
- hr, hg, hb = min(255,r+64), min(255,g+64), min(255,b+64)
- self.highlightPen = wx.Pen(wx.Colour(hr,hg,hb), 1, wx.SOLID)
- self.focusClr = wx.Colour(hr, hg, hb)
+
+ def SetForegroundColour(self, colour):
+ wx.PyControl.SetForegroundColour(self, colour)
+ self.InitColours()
def _GetLabelSize(self):
def DrawFocusIndicator(self, dc, w, h):
bw = self.bezelWidth
-## if self.hasFocus:
-## self.focusIndPen.SetColour(self.GetForegroundColour())
-## else:
-## #self.focusIndPen.SetColour(self.GetBackgroundColour())
-## self.focusIndPen.SetColour(self.GetForegroundColour())
self.focusIndPen.SetColour(self.focusClr)
dc.SetLogicalFunction(wx.INVERT)
dc.SetPen(self.focusIndPen)
--- /dev/null
+#----------------------------------------------------------------------
+# Name: wx.lib.statbmp
+# Purpose: A generic StaticBitmap class.
+#
+# Author: Robin Dunn
+#
+# Created: 12-May-2004
+# RCS-ID: $Id$
+# Copyright: (c) 2004 by Total Control Software
+# Licence: wxWindows license
+#----------------------------------------------------------------------
+
+import wx
+
+#----------------------------------------------------------------------
+
+class GenStaticBitmap(wx.PyControl):
+ labelDelta = 1
+
+ def __init__(self, parent, ID, bitmap,
+ pos = wx.DefaultPosition, size = wx.DefaultSize,
+ style = 0,
+ name = "genstatbmp"):
+ wx.PyControl.__init__(self, parent, ID, pos, size, style|wx.NO_BORDER,
+ wx.DefaultValidator, name)
+ self._bitmap = bitmap
+ self.InheritAttributes()
+ self.SetBestSize(size)
+
+ self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+
+
+ def SetBitmap(self, bitmap):
+ self._bitmap = bitmap
+ self.SetBestSize( (bitmap.GetWidth(), bitmap.GetHeight()) )
+ self.Refresh()
+
+
+ def GetBitmap(self):
+ return self._bitmap
+
+
+ def DoGetBestSize(self):
+ """
+ Overridden base class virtual. Determines the best size of the
+ control based on the bitmap size.
+ """
+ return wx.Size(self._bitmap.GetWidth(), self._bitmap.GetHeight())
+
+
+ def AcceptsFocus(self):
+ """Overridden base class virtual."""
+ return False
+
+
+ def GetDefaultAttributes(self):
+ """
+ Overridden base class virtual. By default we should use
+ the same font/colour attributes as the native StaticBitmap.
+ """
+ return wx.StaticBitmap.GetClassDefaultAttributes()
+
+
+ def ShouldInheritColours(self):
+ """
+ Overridden base class virtual. If the parent has non-default
+ colours then we want this control to inherit them.
+ """
+ return True
+
+
+ def OnPaint(self, event):
+ dc = wx.PaintDC(self)
+ dc.DrawBitmap(self._bitmap, 0, 0, True)
+
+
+ def OnEraseBackground(self, event):
+ pass
+
+
+
+
+#----------------------------------------------------------------------
+
+
wx.DefaultValidator, name)
wx.PyControl.SetLabel(self, label) # don't check wx.ST_NO_AUTORESIZE yet
- self.SetPosition(pos)
- font = parent.GetFont()
- if not font.Ok():
- font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
- wx.PyControl.SetFont(self, font) # same here
-
- self.defBackClr = parent.GetBackgroundColour()
- if not self.defBackClr.Ok():
- self.defBackClr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE)
- self.SetBackgroundColour(self.defBackClr)
-
- clr = parent.GetForegroundColour()
- if not clr.Ok():
- clr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNTEXT)
- self.SetForegroundColour(clr)
-
- rw, rh = size
- bw, bh = self.GetBestSize()
- if rw == -1: rw = bw
- if rh == -1: rh = bh
- self.SetSize(wx.Size(rw, rh))
+ self.defBackClr = self.GetBackgroundColour()
+ self.InheritAttributes()
+ self.SetBestSize(size)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_PAINT, self.OnPaint)
wx.PyControl.SetLabel(self, label)
style = self.GetWindowStyleFlag()
if not style & wx.ST_NO_AUTORESIZE:
- self.SetSize(self.GetBestSize())
+ best = self.GetBestSize()
+ self.SetSize(best)
+ self.SetSizeHints(best)
self.Refresh()
wx.PyControl.SetFont(self, font)
style = self.GetWindowStyleFlag()
if not style & wx.ST_NO_AUTORESIZE:
- self.SetSize(self.GetBestSize())
+ best = self.GetBestSize()
+ self.SetSize(best)
+ self.SetSizeHints(best)
self.Refresh()
def DoGetBestSize(self):
- """Overridden base class virtual. Determines the best size of the
- button based on the label size."""
+ """
+ Overridden base class virtual. Determines the best size of
+ the button based on the label size.
+ """
label = self.GetLabel()
maxWidth = totalHeight = 0
for line in label.split('\n'):
return False
+ def GetDefaultAttributes(self):
+ """
+ Overridden base class virtual. By default we should use
+ the same font/colour attributes as the native StaticText.
+ """
+ return wx.StaticText.GetClassDefaultAttributes()
+
+
+ def ShouldInheritColours(self):
+ """
+ Overridden base class virtual. If the parent has non-default
+ colours then we want this control to inherit them.
+ """
+ return True
+
+
def OnPaint(self, event):
dc = wx.BufferedPaintDC(self)
#dc = wx.PaintDC(self)