On Fri, Feb 22, 2013 at 7:35 AM, Benjamin Jessup <[email protected]> wrote:
> One thing I could use some help with if anyone is bored.... I try to
> draw a constant message overtop the FloatCanvas, which is always there
> and always in the same position (top left corner). I did not want to use
> a floatcanvas object for this as I (thought I?) would have to keep
> moving it's position...

yes, pretty much true, but it turns out there is a way to leverage
FloatCanvas objects...

>I investigated
> FC.OnPaint but that never seems to get called. For the longest time I
> thought that FC was a subclass of wx.Window ...

well, it it a subclas of wx.Panel (which subclasses wx.Window), but
there is a lot ni ther to control the drawing, so it's a bit hard to
hook int it the way you are doing it.

But, it turns out that I added a feature a whihle back to support
drawing grids (or graticules) on top of, or under, the rest of the
canvas -- essentially, you create an object that will get drawn after
or before eveything else, and it doesn't need to use all teh scaling,
etc that regular DrawObjects do.

So, to make one, all you need is an ojbect with a _Draw method with
this signature:

def _Draw(self, dc, Canvas)

for example, one that draws text on top of eveything else, at a
particular pixel positon relative to teh client area of the Window:

class TextOverlay(FloatCanvas.Text):
    """
    An example of an Overlay object:

    all it needs is a new _Draw method.

   this subclasses the Text DrawObject, to get some of the fint
handling, etc code.

    NOTE: you may want to get fancier with this,
          deriving from ScaledTextBox


    """
    def __init__(self,
                 String,
                 xy,
                 Size = 24,
                 Color = "Black",
                 BackgroundColor = None,
                 Family = wx.MODERN,
                 Style = wx.NORMAL,
                 Weight = wx.NORMAL,
                 Underlined = False,
                 Font = None):
        FloatCanvas.Text.__init__(self,
                                  String,
                                  xy,
                                  Size = Size,
                                  Color = Color,
                                  BackgroundColor = BackgroundColor,
                                  Family = Family,
                                  Style = Style,
                                  Weight = Weight,
                                  Underlined = Underlined,
                                  Font = Font)

    def _Draw(self, dc, Canvas):
        """
        _Draw method for Overlay
         note: this is a differeent signarture than the DrawObject Draw
        """
        dc.SetFont(self.Font)
        dc.SetTextForeground(self.Color)
        if self.BackgroundColor:
            dc.SetBackgroundMode(wx.SOLID)
            dc.SetTextBackground(self.BackgroundColor)
        else:
            dc.SetBackgroundMode(wx.TRANSPARENT)
        dc.DrawTextPoint(self.String, self.XY)

That's it.

I've enclosed a working sample, that's also been added to the Demos in SVN.

-Chris

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]

Attachment: OverlayDemo.py
Description: Binary data

_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to