]>
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 #----------------------------------------------------------------------
20 #----------------------------------------------------------------------
22 class GenStaticText(wx
.PyControl
):
25 def __init__(self
, parent
, ID
, label
,
26 pos
= wx
.DefaultPosition
, size
= wx
.DefaultSize
,
28 name
= "genstattext"):
29 wx
.PyControl
.__init
__(self
, parent
, ID
, pos
, size
, style|wx
.NO_BORDER
,
30 wx
.DefaultValidator
, name
)
32 wx
.PyControl
.SetLabel(self
, label
) # don't check wx.ST_NO_AUTORESIZE yet
34 font
= parent
.GetFont()
36 font
= wx
.SystemSettings
.GetSystemFont(wx
.SYS_DEFAULT_GUI_FONT
)
37 wx
.PyControl
.SetFont(self
, font
) # same here
39 self
.defBackClr
= parent
.GetBackgroundColour()
40 if not self
.defBackClr
.Ok():
41 self
.defBackClr
= wx
.SystemSettings
.GetSystemColour(wx
.SYS_COLOUR_3DFACE
)
42 self
.SetBackgroundColour(self
.defBackClr
)
44 clr
= parent
.GetForegroundColour()
46 clr
= wx
.SystemSettings_GetSystemColour(wx
.SYS_COLOUR_BTNTEXT
)
47 self
.SetForegroundColour(clr
)
50 bw
, bh
= self
.GetBestSize()
53 self
.SetSize(wx
.Size(rw
, rh
))
55 wx
.EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
56 wx
.EVT_PAINT(self
, self
.OnPaint
)
59 def SetLabel(self
, label
):
61 Sets the static text label and updates the control's size to exactly
62 fit the label unless the control has wx.ST_NO_AUTORESIZE flag.
64 wx
.PyControl
.SetLabel(self
, label
)
65 style
= self
.GetWindowStyleFlag()
66 if not style
& wx
.ST_NO_AUTORESIZE
:
67 self
.SetSize(self
.GetBestSize())
71 def SetFont(self
, font
):
73 Sets the static text font and updates the control's size to exactly
74 fit the label unless the control has wx.ST_NO_AUTORESIZE flag.
76 wx
.PyControl
.SetFont(self
, font
)
77 style
= self
.GetWindowStyleFlag()
78 if not style
& wx
.ST_NO_AUTORESIZE
:
79 self
.SetSize(self
.GetBestSize())
83 def DoGetBestSize(self
):
84 """Overridden base class virtual. Determines the best size of the
85 button based on the label size."""
86 label
= self
.GetLabel()
87 maxWidth
= totalHeight
= 0
88 for line
in label
.split('\n'):
90 w
, h
= self
.GetTextExtent('W') # empty lines have height too
92 w
, h
= self
.GetTextExtent(line
)
94 maxWidth
= max(maxWidth
, w
)
95 return wx
.Size(maxWidth
, totalHeight
)
98 def AcceptsFocus(self
):
99 """Overridden base class virtual."""
103 def OnPaint(self
, event
):
104 dc
= wx
.BufferedPaintDC(self
)
105 #dc = wx.PaintDC(self)
106 width
, height
= self
.GetClientSize()
107 if not width
or not height
:
110 clr
= self
.GetBackgroundColour()
111 backBrush
= wx
.Brush(clr
, wx
.SOLID
)
112 if wx
.Platform
== "__WXMAC__" and clr
== self
.defBackClr
:
113 # if colour is still the default then use the striped background on Mac
114 backBrush
.SetMacTheme(1) # 1 == kThemeBrushDialogBackgroundActive
115 dc
.SetBackground(backBrush
)
117 dc
.SetTextForeground(self
.GetForegroundColour())
119 dc
.SetFont(self
.GetFont())
120 label
= self
.GetLabel()
121 style
= self
.GetWindowStyleFlag()
123 for line
in label
.split('\n'):
125 w
, h
= self
.GetTextExtent('W') # empty lines have height too
127 w
, h
= self
.GetTextExtent(line
)
128 if style
& wx
.ALIGN_RIGHT
:
130 if style
& wx
.ALIGN_CENTER
:
132 dc
.DrawText(line
, (x
, y
))
136 def OnEraseBackground(self
, event
):
142 #----------------------------------------------------------------------