]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/stattext.py
c5a89e9f4534ef4adf4cee715813f71f6224b6f2
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 *
21 #----------------------------------------------------------------------
23 class wxGenStaticText(wxPyControl
):
26 def __init__(self
, parent
, ID
, label
,
27 pos
= wxDefaultPosition
, size
= wxDefaultSize
,
29 name
= "genstattext"):
30 wxPyControl
.__init
__(self
, parent
, ID
, pos
, size
, style
, wxDefaultValidator
, name
)
32 wxPyControl
.SetLabel(self
, label
) # don't check wxST_NO_AUTORESIZE yet
34 font
= parent
.GetFont()
36 font
= wxSystemSettings_GetSystemFont(wxSYS_DEFAULT_GUI_FONT
)
37 wxPyControl
.SetFont(self
, font
) # same here
39 clr
= parent
.GetBackgroundColour()
41 clr
= wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNFACE
)
42 self
.SetBackgroundColour(clr
)
44 clr
= parent
.GetForegroundColour()
46 clr
= wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNTEXT
)
47 self
.SetForegroundColour(clr
)
50 bw
, bh
= self
.GetBestSize()
53 self
.SetSize(wxSize(rw
, rh
))
55 EVT_ERASE_BACKGROUND(self
, self
.OnEraseBackground
)
56 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 wxST_NO_AUTORESIZE flag.
64 wxPyControl
.SetLabel(self
, label
)
65 style
= self
.GetWindowStyleFlag()
66 if not style
& wxST_NO_AUTORESIZE
:
67 self
.SetSize(self
.GetBestSize())
69 def SetFont(self
, font
):
71 Sets the static text font and updates the control's size to exactly
72 fit the label unless the control has wxST_NO_AUTORESIZE flag.
74 wxPyControl
.SetFont(self
, font
)
75 style
= self
.GetWindowStyleFlag()
76 if not style
& wxST_NO_AUTORESIZE
:
77 self
.SetSize(self
.GetBestSize())
80 def DoGetBestSize(self
):
81 """Overridden base class virtual. Determines the best size of the
82 button based on the label and bezel size."""
83 label
= self
.GetLabel()
84 maxWidth
= totalHeight
= 0
85 for line
in label
.split('\n'):
87 w
, h
= self
.GetTextExtent('W') # empty lines have height too
89 w
, h
= self
.GetTextExtent(line
)
91 maxWidth
= max(maxWidth
, w
)
92 return wxSize(maxWidth
, totalHeight
)
95 def AcceptsFocus(self
):
96 """Overridden base class virtual."""
100 def OnPaint(self
, event
):
101 width
, height
= self
.GetClientSize()
102 dc
= wxBufferedPaintDC(self
)
103 dc
.SetBackground(wxBrush(self
.GetBackgroundColour(), wxSOLID
))
105 dc
.SetFont(self
.GetFont())
106 label
= self
.GetLabel()
107 style
= self
.GetWindowStyleFlag()
109 for line
in label
.split('\n'):
111 w
, h
= self
.GetTextExtent('W') # empty lines have height too
113 w
, h
= self
.GetTextExtent(line
)
114 if style
& wxALIGN_RIGHT
:
116 if style
& wxALIGN_CENTER
:
118 dc
.DrawText(line
, x
, y
)
122 def OnEraseBackground(self
, event
):
128 #----------------------------------------------------------------------