]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/stattext.py
1 #----------------------------------------------------------------------
2 # Name: wx.lib.stattext
3 # Purpose: A generic wxGenStaticText class. Using this should
4 # eliminate some of the platform differences in wxStaticText,
5 # such as background colours and mouse sensitivity.
11 # Copyright: (c) 2002 by Total Control Software
12 # Licence: wxWindows license
13 #----------------------------------------------------------------------
14 # 12/12/2003 - Jeff Grimmett (grimmtooth@softhome.net)
16 # o 2.5 compatability update.
22 #----------------------------------------------------------------------
24 class GenStaticText(wx
.PyControl
):
27 def __init__(self
, parent
, ID
, label
,
28 pos
= wx
.DefaultPosition
, size
= wx
.DefaultSize
,
30 name
= "genstattext"):
31 wx
.PyControl
.__init
__(self
, parent
, ID
, pos
, size
, style|wx
.NO_BORDER
,
32 wx
.DefaultValidator
, name
)
34 wx
.PyControl
.SetLabel(self
, label
) # don't check wx.ST_NO_AUTORESIZE yet
36 font
= parent
.GetFont()
38 font
= wx
.SystemSettings
.GetFont(wx
.SYS_DEFAULT_GUI_FONT
)
39 wx
.PyControl
.SetFont(self
, font
) # same here
41 self
.defBackClr
= parent
.GetBackgroundColour()
42 if not self
.defBackClr
.Ok():
43 self
.defBackClr
= wx
.SystemSettings
.GetColour(wx
.SYS_COLOUR_3DFACE
)
44 self
.SetBackgroundColour(self
.defBackClr
)
46 clr
= parent
.GetForegroundColour()
48 clr
= wx
.SystemSettings
.GetColour(wx
.SYS_COLOUR_BTNTEXT
)
49 self
.SetForegroundColour(clr
)
52 bw
, bh
= self
.GetBestSize()
55 self
.SetSize(wx
.Size(rw
, rh
))
57 self
.Bind(wx
.EVT_ERASE_BACKGROUND
, self
.OnEraseBackground
)
58 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
61 def SetLabel(self
, label
):
63 Sets the static text label and updates the control's size to exactly
64 fit the label unless the control has wx.ST_NO_AUTORESIZE flag.
66 wx
.PyControl
.SetLabel(self
, label
)
67 style
= self
.GetWindowStyleFlag()
68 if not style
& wx
.ST_NO_AUTORESIZE
:
69 self
.SetSize(self
.GetBestSize())
73 def SetFont(self
, font
):
75 Sets the static text font and updates the control's size to exactly
76 fit the label unless the control has wx.ST_NO_AUTORESIZE flag.
78 wx
.PyControl
.SetFont(self
, font
)
79 style
= self
.GetWindowStyleFlag()
80 if not style
& wx
.ST_NO_AUTORESIZE
:
81 self
.SetSize(self
.GetBestSize())
85 def DoGetBestSize(self
):
86 """Overridden base class virtual. Determines the best size of the
87 button based on the label size."""
88 label
= self
.GetLabel()
89 maxWidth
= totalHeight
= 0
90 for line
in label
.split('\n'):
92 w
, h
= self
.GetTextExtent('W') # empty lines have height too
94 w
, h
= self
.GetTextExtent(line
)
96 maxWidth
= max(maxWidth
, w
)
97 return wx
.Size(maxWidth
, totalHeight
)
100 def AcceptsFocus(self
):
101 """Overridden base class virtual."""
105 def OnPaint(self
, event
):
106 dc
= wx
.BufferedPaintDC(self
)
107 #dc = wx.PaintDC(self)
108 width
, height
= self
.GetClientSize()
109 if not width
or not height
:
112 clr
= self
.GetBackgroundColour()
113 backBrush
= wx
.Brush(clr
, wx
.SOLID
)
114 if wx
.Platform
== "__WXMAC__" and clr
== self
.defBackClr
:
115 # if colour is still the default then use the striped background on Mac
116 backBrush
.SetMacTheme(1) # 1 == kThemeBrushDialogBackgroundActive
117 dc
.SetBackground(backBrush
)
119 dc
.SetTextForeground(self
.GetForegroundColour())
121 dc
.SetFont(self
.GetFont())
122 label
= self
.GetLabel()
123 style
= self
.GetWindowStyleFlag()
125 for line
in label
.split('\n'):
127 w
, h
= self
.GetTextExtent('W') # empty lines have height too
129 w
, h
= self
.GetTextExtent(line
)
130 if style
& wx
.ALIGN_RIGHT
:
132 if style
& wx
.ALIGN_CENTER
:
134 dc
.DrawText(line
, (x
, y
))
138 def OnEraseBackground(self
, event
):
144 #----------------------------------------------------------------------