]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/stattext.py
d93b16d156ad2c0dc9d3042f3e47f15867cbaa28
1 #----------------------------------------------------------------------
2 # Name: wxPython.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 #----------------------------------------------------------------------
18 from wxPython
.wx
import *
20 #----------------------------------------------------------------------
22 class wxGenStaticText(wxPyControl
):
25 def __init__(self
, parent
, ID
, label
,
26 pos
= wxDefaultPosition
, size
= wxDefaultSize
,
28 name
= "genstattext"):
29 wxPyControl
.__init
__(self
, parent
, ID
, pos
, size
, style
, wxDefaultValidator
, name
)
31 wxPyControl
.SetLabel(self
, label
) # don't check wxST_NO_AUTORESIZE yet
33 font
= parent
.GetFont()
35 font
= wxSystemSettings_GetSystemFont(wxSYS_DEFAULT_GUI_FONT
)
36 wxPyControl
.SetFont(self
, font
) # same here
38 clr
= parent
.GetBackgroundColour()
40 clr
= wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNFACE
)
41 self
.SetBackgroundColour(clr
)
43 clr
= parent
.GetForegroundColour()
45 clr
= wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNTEXT
)
46 self
.SetForegroundColour(clr
)
49 bw
, bh
= self
.GetBestSize()
52 self
.SetSize(wxSize(rw
, rh
))
54 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
55 EVT_PAINT(self
, self
.OnPaint
)
58 def SetLabel(self
, label
):
60 Sets the static text label and updates the control's size to exactly
61 fit the label unless the control has wxST_NO_AUTORESIZE flag.
63 wxPyControl
.SetLabel(self
, label
)
64 style
= self
.GetWindowStyleFlag()
65 if not style
& wxST_NO_AUTORESIZE
:
66 self
.SetSize(self
.GetBestSize())
70 def SetFont(self
, font
):
72 Sets the static text font and updates the control's size to exactly
73 fit the label unless the control has wxST_NO_AUTORESIZE flag.
75 wxPyControl
.SetFont(self
, font
)
76 style
= self
.GetWindowStyleFlag()
77 if not style
& wxST_NO_AUTORESIZE
:
78 self
.SetSize(self
.GetBestSize())
82 def DoGetBestSize(self
):
83 """Overridden base class virtual. Determines the best size of the
84 button based on the label size."""
85 label
= self
.GetLabel()
86 maxWidth
= totalHeight
= 0
87 for line
in label
.split('\n'):
89 w
, h
= self
.GetTextExtent('W') # empty lines have height too
91 w
, h
= self
.GetTextExtent(line
)
93 maxWidth
= max(maxWidth
, w
)
94 return wxSize(maxWidth
, totalHeight
)
97 def AcceptsFocus(self
):
98 """Overridden base class virtual."""
102 def OnPaint(self
, event
):
103 dc
= wxBufferedPaintDC(self
)
104 #dc = wxPaintDC(self)
105 width
, height
= self
.GetClientSize()
106 if not width
or not height
:
108 dc
.SetBackground(wxBrush(self
.GetBackgroundColour(), wxSOLID
))
109 dc
.SetTextForeground(self
.GetForegroundColour())
111 dc
.SetFont(self
.GetFont())
112 label
= self
.GetLabel()
113 style
= self
.GetWindowStyleFlag()
115 for line
in label
.split('\n'):
117 w
, h
= self
.GetTextExtent('W') # empty lines have height too
119 w
, h
= self
.GetTextExtent(line
)
120 if style
& wxALIGN_RIGHT
:
122 if style
& wxALIGN_CENTER
:
124 dc
.DrawText(line
, x
, y
)
128 def OnEraseBackground(self
, event
):
134 #----------------------------------------------------------------------