change font

Hi All,

Sorry, this seems really dumb, but how do you change the font face in wx. I’m looking at the FloatCanvas and at this point,

        self.Canvas.AddText("MODERN Font", -10, 0, Family = wx.MODERN)
        self.Canvas.AddText("DECORATIVE Font", -10, -1, Family = wx.DECORATIVE)
        self.Canvas.AddText("ROMAN Font", -10, -2, Family = wx.ROMAN)
        self.Canvas.AddText("SCRIPT Font", -10, -3, Family = wx.SCRIPT)

I thought to change the face to say Arial or a musical notation font.

Thanks,

M

First, create the widget as if you weren't changing fonts.

Then, use widget.GetFont() to get a copy of the font it used. (where
widget is the widget you created)

Then, use font.Set*() methods to set the weight, face, size, etc
(where 'font' is what widgets.GetFont() returned).

You can economize by setting the font at a higher level, say the
parent of all your widgets, for example.

You can also economize by pre-creating an instance of wx.Font() with
the desired attributes, then using widget.SetFont() to apply it. That
only makes sense if you need to use it a lot, though.

The upshot is: it ain't elegant :slight_smile:

···

----- Original Message -----
From: Malcolm Clift <mail@mjclift.freeserve.co.uk>
Date: Fri, 1 Oct 2004 04:53:18 +0100
Subject: [wxPython-users] change font
To: wxpython-users@lists.wxwidgets.org

Hi All,
  
Sorry, this seems really dumb, but how do you change the font face in
wx. I'm looking at the FloatCanvas and at this point,
  
            self.Canvas.AddText("MODERN Font", -10, 0, Family = wx.MODERN)
            self.Canvas.AddText("DECORATIVE Font", -10, -1, Family =
wx.DECORATIVE)
            self.Canvas.AddText("ROMAN Font", -10, -2, Family = wx.ROMAN)
            self.Canvas.AddText("SCRIPT Font", -10, -3, Family = wx.SCRIPT)
  
I thought to change the face to say Arial or a musical notation font.
  
Thanks,
  
M
  
--
Regards,

    Jeff

Thanks Jeff,

Malcolm

Jeff Grimmett wrote:

First, create the widget as if you weren't changing fonts.

Then, use widget.GetFont() to get a copy of the font it used. (where
widget is the widget you created)

Then, use font.Set*() methods to set the weight, face, size, etc
(where 'font' is what widgets.GetFont() returned).

note that there was a bug in wxGTK a while back that made this not work as it should. The solution there was to create a new font, using the attributes found from the Get*() methods on the old font.

You can economize by setting the font at a higher level, say the
parent of all your widgets, for example.

You can also economize by pre-creating an instance of wx.Font() with
the desired attributes, then using widget.SetFont() to apply it. That
only makes sense if you need to use it a lot, though.

The upshot is: it ain't elegant :slight_smile:

right. That's why I wrapped some of the functionality in FloatCanvas, but if you want to specify a specific font there, you still have to create it and pass it in.

Malcolm, do you want to set a font in FloatCanvas? or where you just looking there for an example?

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hi Chris,

I'm new to python and am looking for away to display music notation. As for
setting the font, of course the examples are there, I just didn't use my
eyes. Sorry.

Chris, can I ask you will FloatCanvas do antialiasing of fonts?

Also, not particularly to do with FloatCanvas, but my needs are similar to
your 'Hit test foreground' example, With the right up/down/left/right box,
how would I impliment a stepped drag. What I mean is, at the moment when you
click on a hit point it steps in that direction, would there be some way to
drag it through these steps? Of course what I'm thinking of is using it for
notes on a staff.

Malcolm

I'm new to python and am looking for away to display music notation.

[snip]

would there be some way to
drag it through these steps? Of course what I'm thinking of is using it for
notes on a staff.

I haven't done this, but it's an interesting problem,
so I'll put in my 2 cents worth (or whatever it's worth!).
Note that this is based on my reading of the wxWidgets
Reference (2.5.2).

For drag feedback, look at wxDropTarget::OnDragOver.
My first thought is this:

For the staff, create a staff-drawing object
(a wx.Frame), and make it a wx.DropTarget.
Model the staff as a series of lines and spaces.
From OnDragOver, quantize mouse y location to
determine which line or space the note is over
(or closest to), and highlight that line or space
across the entire staff. For additional user
feedback, calculate a horizontal target position
and draw a vertical bar, top and bottom arrows,
or a copy of the note (temporary, of course) to
indicate the horizontal drop position.
    I'd also think about having the staff recognize
positions above and below the currently-visible staff
and add (as part of the feedback graphics) additional
partial staff lines as needed (perhaps up to 3 lines
above and below), since this is a common notation.

Anyway, that's my 2 cents worth. Hope it's useful.

- Sam

···

At 2004-10-02 12:42 AM +0100, you wrote:

__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com

Hi Sam,

I value those two cents of yours and anyone else who cares to donate, feel
free : )

A great help, thankyou.

Malcolm

Malcolm Clift wrote:

I'm new to python and am looking for away to display music notation. As for
setting the font, of course the examples are there, I just didn't use my
eyes. Sorry.

Chris, can I ask you will FloatCanvas do antialiasing of fonts?

FloatCanvas uses wx's font rendering, so I think that means anti-aliasing for true-type fonts, at least on some systems.

Also, not particularly to do with FloatCanvas, but my needs are similar to
your 'Hit test foreground' example, With the right up/down/left/right box,
how would I impliment a stepped drag. What I mean is, at the moment when you
click on a hit point it steps in that direction, would there be some way to
drag it through these steps?

Doing it in FloatCanvas is pretty different than doing it without, but I'll give a little summary in either case:

1) catch the mouse-down event, and check if it's on one of your objects (FloatCanvas does this for you). Set a flag if it is, and store the coords of the point clicked. Set wx.Window.CaptureMouse(), so that if they move out of the window, you don't' lose what's happening

2) catch EVT_MOTION, and if the "moving" flag is set, calculate how far the mouse has moved, and redraw the image, if it has moved far enough to be at the next step.

3) repeat (2) until....

4) catch EVT_LEFT_UP, and reset: wx.Window.CaptureMouse(), and your "moving" flag

or:

download FloatCanvas from:

http://home.comcast.net/~chrishbarker/FloatCanvas/

In there you'll find a PolyEditor example that does much of what you need to do.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks Chris,

Malcolm