I am trying to make a wxPython control that responds to changes in its size
by possibly
changing fonts. I want to embed this control in a sizer (currently I an
using wxFlexGridSizer),
and I am expecting that when the sizer calls my control's SetSize or
setDimensions methods,
I can do something.
I am finding that these methods are not being called at all. I looked in
wxPython/lib/grids.py,
and that code calls "item.SetDimension(ipt, isz)", to resize children. This
method is defined
for sizer children, but not for window children, but with four arguments,
x,y, width, height, not two,
as in grids.py. But it seems that the wxFlexGridSizer apperently defined in
grids.py is not
being used at all.
So, my simple question is: How can I make a control of my own that can
become aware of
resizing actions taken by automatic sizers?
···
-------------------------
class Gauge(wxControl):
def __init__(self, parent, ID, dev,
pos = wxDefaultPosition, size = (100,10),
style = 0, name=None):
if style == 0:
style = wxSUNKEN_BORDER
if not name:
name = dev.key + "." + str(ID)
wxControl.__init__(self, parent, ID, pos, size, style,
validator = wxDefaultValidator, name=name)
self.lo = dev.lo
self.hi = dev.hi
self.rValue = 0.0
self.txtlo = sstr(self.lo)
self.txthi = sstr(self.hi)
EVT_PAINT(self, self.OnPaint)
def SetValue(self, value, dev, opt):
self.rValue = min(1.0, max(0.0,
(value-self.lo)/(self.hi-self.lo)))
self.Refresh()
def OnPaint(self, event):
self.Draw(wxPaintDC(self))
def SetSize(self,size):
wxLogMessage("SetSize: ", str(size))
wxControl.SetSize(self, size)
def SetDimensions(self, x, y, width, height, sizeFlags=wxSIZE_AUTO):
wxLogMessage("SetDimensions: x=%d, y=%d, w=%d,h=%d"
%(x,y,width,height))
wxControl.SetDimensions(self, x, y, width, height, sizeFlags)
def SetPosition(self,point):
wxLogMessage("SetPosition: ", str(point))
wxControl.SetPosition(self, point)
def Draw(self,dc):
w, h = self.GetClientSizeTuple()
dc.BeginDrawing()
ch = dc.GetCharHeight()
hbar = max(4, h - ch)
ytext = hbar
twlo,th = dc.GetTextExtent(self.txtlo)
twhi,th = dc.GetTextExtent(self.txthi)
dc.Clear()
dc.SetBrush(wxBLUE_BRUSH)
dc.DrawRectangle(0,0, int(w*self.rValue), hbar)
xtext = max(0, w-twhi)
dc.DrawText(self.txthi, xtext, ytext)
if xtext > twlo + ch:
dc.DrawText(self.txtlo, 0, ytext)
dc.EndDrawing()
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users