wxDc and DrawText

I have a wxDc where I draw text with DrawText function, of course :).
If this text has more that one line, I see a concatenate looong text
with at the point where every line end a little rectangle or a pipe.
Is this right, so I must separate and draw the lines one for time, or
this is a bug?

Thanks
Michele

win2k, wx 2.6.0, py 2.3.5

I have a wxDc where I draw text with DrawText function, of course :).
If this text has more that one line, I see a concatenate looong text
with at the point where every line end a little rectangle or a pipe.
Is this right, so I must separate and draw the lines one for time, or
this is a bug?

Thanks
Michele

win2k, wx 2.6.0, py 2.3.5

Yes. DrawText() is a very basic function and doesn't handle drawing
multiple lines. You must split the lines yourself and draw each one
seperately.

···

On 6/22/05, Michele Petrazzo <michele.petrazzo@unipex.it> wrote:

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hi,

How comes that there seem to be multiple APIs for playing sound???

There is

sound = wx.SoundFromData(open("data/plan.wav", "rb").read())

And then there is

Import winsound
winsound.PlaySound(open("data/plan.wav", "rb").read(), winsound.SND_MEMORY)

Questions:
1) which one is supposed to be used?
2) which formats are supported for playback besides WAV? What is this
depending on?
3) how can i buffer a sound for faster and smoother playback (asynchronous
playback without freezing the app)
4) how can i play back several sounds at a time, or would i need a package
like pyGame for that?

Thanks,

Christophe Leske

tel. +49-(0)211 230 99 70
.:. fürstenwall 157 .:.
::: 40215 düsseldorf :::
::: germany :::
http://www.multimedial.de

Hi,

How comes that there seem to be multiple APIs for playing sound???

There is

sound = wx.SoundFromData(open("data/plan.wav", "rb").read())

And then there is

Import winsound
winsound.PlaySound(open("data/plan.wav", "rb").read(), winsound.SND_MEMORY)

Questions:
1) which one is supposed to be used?

wx.SoundFromData is a wrapper for the wxSound apis, while winsound is
a standard Python module wrapping the win32 sound api. Use whichever
one you want

2) which formats are supported for playback besides WAV? What is this
depending on?

Neither support any format except WAV

3) how can i buffer a sound for faster and smoother playback (asynchronous
playback without freezing the app)

I believe both support async play back via a flag. Check the docs for
the appropriate functions.

4) how can i play back several sounds at a time, or would i need a package
like pyGame for that?

Both of these APIs are for simple, short sounds, such as interface/UI
feedback. If you want anything more complicated, you'll need to use a
different library.

···

On 6/22/05, Christophe Leske <leske@online.de> wrote:

Thanks,

Christophe Leske

tel. +49-(0)211 230 99 70
.:. fürstenwall 157 .:.
::: 40215 düsseldorf :::
::: germany :::
http://www.multimedial.de

Thank you Chris, that's excellent information.

Christophe Leske

tel. +49-(0)211 230 99 70
.:. fürstenwall 157 .:.
::: 40215 düsseldorf :::
::: germany :::
http://www.multimedial.de

> Hi,
>
> How comes that there seem to be multiple APIs for playing sound???
>
> There is
>
> sound = wx.SoundFromData(open("data/plan.wav", "rb").read())
>
> And then there is
>
> Import winsound
> winsound.PlaySound(open("data/plan.wav", "rb").read(),
> winsound.SND_MEMORY)
>
>
>
> Questions:
> 1) which one is supposed to be used?

wx.SoundFromData is a wrapper for the wxSound apis, while
winsound is a standard Python module wrapping the win32 sound
api. Use whichever one you want

> 2) which formats are supported for playback besides WAV?
What is this
> depending on?

Neither support any format except WAV

> 3) how can i buffer a sound for faster and smoother playback
> (asynchronous playback without freezing the app)

I believe both support async play back via a flag. Check the
docs for the appropriate functions.

> 4) how can i play back several sounds at a time, or would i need a
> package like pyGame for that?
>

Both of these APIs are for simple, short sounds, such as
interface/UI feedback. If you want anything more complicated,
you'll need to use a different library.

On Windows, I've had very good luck with PyMedia (http://www.pymedia.org).
It apparently works on Linux too, but does not compile on Mac OS X.

David

Chris Mellon wrote:

Yes. DrawText() is a very basic function and doesn't handle drawing
multiple lines. You must split the lines yourself and draw each one
seperately.

This is a platform difference,
GTK will break the lines for you. If you need it to run on Windows, you'll have to do it yourself. I've implemented a bunch of stuff for this in FloatCanvas, but it hasn't gotten into the version included with wxPython yet. It's probably more complicated than you need, as it has to figure out the layout in a way that is scalable, and there's a bunch of code in there so that you can line it up on the left, right, top, bottom, etc. If you're interested in all that, I can send you the latest version.

Here's an untested, simple way to do it however:

def DrawMultilineText(dc, S, x, y):
     lines = S.split("\n")
     LineSpacing = dc.GetTextExtent("X")[1]
     for line in lines:
         dc.DrawText(line, x, y)
         y += LineSpacing

-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

Chris Barker wrote:

Chris Mellon wrote:

Yes. DrawText() is a very basic function and doesn't handle drawing
multiple lines. You must split the lines yourself and draw each
one seperately.

This is a platform difference, GTK will break the lines for you. If
you need it to run on Windows, you'll have to do it yourself. I've
implemented a bunch of stuff for this in FloatCanvas, but it hasn't
gotten into the version included with wxPython yet. It's probably
more complicated than you need, as it has to figure out the layout in
a way that is scalable, and there's a bunch of code in there so that
you can line it up on the left, right, top, bottom, etc. If you're
interested in all that, I can send you the latest version.

Why not...
You can send me the code at my email-address (can you compress it?).
Thanks a lot.

Here's an untested, simple way to do it however:

def DrawMultilineText(dc, S, x, y): lines = S.split("\n") LineSpacing
= dc.GetTextExtent("X")[1] for line in lines: dc.DrawText(line, x, y)
y += LineSpacing

This is the same code that I have already write into my application.

-Chris

Michele