using wxMessageDialog well

Two very simple questions but I wanted to see how others do these 3
things regarding wxMessageDialog....

1) What's the best way to write the message if it is going to be a
long one (several lines)? I find that if I put the message all on one
line, that ensures it will not be badly broken in the dialog, but of
course a long message means the text runs way off the screen, and I
prefer it to be < 80 characters. Trying triple quotes or \n has
sometimes caused odd line breaks in the dialog text, so I thought I'd
ask what others do. Also, on this same note, I'd like something that
looks good on all platforms.

2) Eventually I may convert all my wxMessageDialogs to some kind of
fancier dialog that can be positioned. Is there any efficient way to
do that other than just searching through the code for all examples
and "manually" replacing them?

3) And, on that last note, is there any best practice for managing all
the various messages one's app may send? (I'm finding they pepper my
code in an unorganized way, and think they should be more controlled).

Thanks,
Che

Hi Che,

Two very simple questions but I wanted to see how others do these 3

things regarding wxMessageDialog…

  1. What’s the best way to write the message if it is going to be a

long one (several lines)? I find that if I put the message all on one

line, that ensures it will not be badly broken in the dialog, but of

course a long message means the text runs way off the screen, and I

prefer it to be < 80 characters. Trying triple quotes or \n has

sometimes caused odd line breaks in the dialog text, so I thought I’d

ask what others do. Also, on this same note, I’d like something that

looks good on all platforms.

For stuff like that, I tend to just subclass wx.Dialog. If I have Yes/No/OK button(s), then I use the appropriate ID (for example: wx.ID_OK). Then I can put any widget I want onto my dialog.

  1. Eventually I may convert all my wxMessageDialogs to some kind of

fancier dialog that can be positioned. Is there any efficient way to

do that other than just searching through the code for all examples

and “manually” replacing them?

I’ve done something like this for my BusyInfo dialogs:

def myDialog(message, caption, style):
“”“”“”

return wx.MessageDialog(None, message, caption=caption, style=style)

Then I just call it like so:

dlg = myDialog(“This is a cool message!”, “Information!”, wx.OK|wx.ICON_EXCLAMATION)

If I ever need to make my dialog any fancier, I can just edit my function.

  1. And, on that last note, is there any best practice for managing all

the various messages one’s app may send? (I’m finding they pepper my

code in an unorganized way, and think they should be more controlled).

Are you talking about PubSub here? I know my code has gotten a little unruly in this respect, but I just try to keep all the receivers in one location, usually in the init function somewhere.

···

On Tue, Mar 16, 2010 at 1:53 PM, C M cmpython@gmail.com wrote:

Thanks,

Che

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Mike Driscoll

Blog: http://blog.pythonlibrary.org

Hi,

Two very simple questions but I wanted to see how others do these 3
things regarding wxMessageDialog....

1) What's the best way to write the message if it is going to be a
long one (several lines)? I find that if I put the message all on one
line, that ensures it will not be badly broken in the dialog, but of
course a long message means the text runs way off the screen, and I
prefer it to be < 80 characters. Trying triple quotes or \n has
sometimes caused odd line breaks in the dialog text, so I thought I'd
ask what others do. Also, on this same note, I'd like something that
looks good on all platforms.

Try splitting it using wx.lib.textwrap. I usually do that using a
pre-specified width (80, 90, whatever) and it works pretty well.

2) Eventually I may convert all my wxMessageDialogs to some kind of
fancier dialog that can be positioned. Is there any efficient way to
do that other than just searching through the code for all examples
and "manually" replacing them?

You may want to look at wx.lib.agw.genericmessagedialog for a fancier
message dialog.

3) And, on that last note, is there any best practice for managing all
the various messages one's app may send? (I'm finding they pepper my
code in an unorganized way, and think they should be more controlled).

Not that I know of. You could put all your messages in a module and
indexing them. but I am not sure it's worth the effort.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever. <==

···

On 16 March 2010 18:53, C M wrote:

Hi Mike,

1) What's the best way to write the message if it is going to be a
long one (several lines)? I find that if I put the message all on one
line, that ensures it will not be badly broken in the dialog, but of
course a long message means the text runs way off the screen, and I
prefer it to be < 80 characters. Trying triple quotes or \n has
sometimes caused odd line breaks in the dialog text, so I thought I'd
ask what others do. Also, on this same note, I'd like something that
looks good on all platforms.

For stuff like that, I tend to just subclass wx.Dialog. If I have Yes/No/OK
button(s), then I use the appropriate ID (for example: wx.ID_OK). Then I can
put any widget I want onto my dialog.

So you use a wxStaticTextCtrl then, or something like that, in the dialog?

2) Eventually I may convert all my wxMessageDialogs to some kind of
fancier dialog that can be positioned. Is there any efficient way to
do that other than just searching through the code for all examples
and "manually" replacing them?

I've done something like this for my BusyInfo dialogs:

def myDialog(message, caption, style):
""""""
return wx.MessageDialog(None, message, caption=caption, style=style)

Then I just call it like so:

dlg = myDialog("This is a cool message!", "Information!",
wx.OK|wx.ICON_EXCLAMATION)

If I ever need to make my dialog any fancier, I can just edit my function.

Got it.

3) And, on that last note, is there any best practice for managing all
the various messages one's app may send? (I'm finding they pepper my
code in an unorganized way, and think they should be more controlled).

Are you talking about PubSub here? I know my code has gotten a little unruly
in this respect, but I just try to keep all the receivers in one location,
usually in the __init__ function somewhere.

I was open to any suggestions. But now, along the lines of what
Andrea said, I'm thinking it isn't worth it to bother, since the
dialog is not much more than its message, and I have to keep the
message (or an index to the message) there at the point of use anyway.

Thanks,
Che

Hi

Hi,

Two very simple questions but I wanted to see how others do these 3
things regarding wxMessageDialog....

1) What's the best way to write the message if it is going to be a
long one (several lines)? I find that if I put the message all on one
line, that ensures it will not be badly broken in the dialog, but of
course a long message means the text runs way off the screen, and I
prefer it to be < 80 characters. Trying triple quotes or \n has
sometimes caused odd line breaks in the dialog text, so I thought I'd
ask what others do. Also, on this same note, I'd like something that
looks good on all platforms.

Try splitting it using wx.lib.textwrap. I usually do that using a
pre-specified width (80, 90, whatever) and it works pretty well.

Could you just paste in a quick (non-runnable) example that I could
try? I'm a little confused by the dc argument in it.

You may want to look at wx.lib.agw.genericmessagedialog for a fancier
message dialog.

Yes, I had my eye on just that. :smiley:

Thanks,
Che

···

On Tue, Mar 16, 2010 at 4:51 PM, Andrea Gavana <andrea.gavana@gmail.com> wrote:

On 16 March 2010 18:53, C M wrote:

hi Che,

Hi

Hi,

Two very simple questions but I wanted to see how others do these 3
things regarding wxMessageDialog....

1) What's the best way to write the message if it is going to be a
long one (several lines)? I find that if I put the message all on one
line, that ensures it will not be badly broken in the dialog, but of
course a long message means the text runs way off the screen, and I
prefer it to be < 80 characters. Trying triple quotes or \n has
sometimes caused odd line breaks in the dialog text, so I thought I'd
ask what others do. Also, on this same note, I'd like something that
looks good on all platforms.

Try splitting it using wx.lib.textwrap. I usually do that using a
pre-specified width (80, 90, whatever) and it works pretty well.

Could you just paste in a quick (non-runnable) example that I could
try? I'm a little confused by the dc argument in it.

Sorry, I got confused between the Python textwrap module and the one
in wx.lib. If you use the former, you can just do something like this:

lines = textwrap.wrap(yourText, max_num_characters)

Then you get a list of lines wrapped by the maximum numbers of
characters you wish (80, 90, whatever). If you want to display them,
you just pass to your message dialog the string:

"\n".join(lines)

and you're done.

···

On 16 March 2010 22:13, C M wrote:

On Tue, Mar 16, 2010 at 4:51 PM, Andrea Gavana <andrea.gavana@gmail.com> wrote:

On 16 March 2010 18:53, C M wrote:

You may want to look at wx.lib.agw.genericmessagedialog for a fancier
message dialog.

Yes, I had my eye on just that. :smiley:

Thanks,
Che

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever. <==

Try splitting it using wx.lib.textwrap. I usually do that using a
pre-specified width (80, 90, whatever) and it works pretty well.

Could you just paste in a quick (non-runnable) example that I could
try? I'm a little confused by the dc argument in it.

Sorry, I got confused between the Python textwrap module and the one
in wx.lib. If you use the former, you can just do something like this:

lines = textwrap.wrap(yourText, max_num_characters)

Then you get a list of lines wrapped by the maximum numbers of
characters you wish (80, 90, whatever). If you want to display them,
you just pass to your message dialog the string:

"\n".join(lines)

and you're done.

Thanks, that's handy. But, I still don't know the best way to split
long lines of text in the Python code itself so that it is easily
readable from the IDE. In other words, if I want to use textwrap to
wrap this something long--like this:

lines = textwrap.wrap('Four score and seven years ago our fathers
brought forth on this continent, a new nation, conceived in Liberty,
and dedicated to the proposition that all men are created equal.', 80)

Though that line should be wrapped in Gmail, in the source code that
would be a 208 character-long line which is well beyond the maximum
line length of 79 in the Python Style Guide and is just unpleasant to
have in compact, readable code.

So what's the right way to break that up in a Python line? I know
I've seen this before, I just can't seem to search for it correctly.
Sorry for this super-basic question.

Che

Consecutive string constants in Python are automatically concatenated, so you can do something like this:

lines = textwrap.wrap(
     'Four score and seven years ago our fathers brought forth '
     'on this continent, a new nation, conceived in Liberty, and '
     'dedicated to the proposition that all men are created equal.',
     80)

BTW, to answer your other question the dc parameter in wx.lib.wordwrap is used to measure the text extent of the text using the actual font it will (presumably) be drawn with. The width parameter is in pixels. This way with proportional fonts you will have a better result when some lines have more wide characters vs some that that more narrow characters.

···

On 3/16/10 6:08 PM, C M wrote:

Thanks, that's handy. But, I still don't know the best way to split
long lines of text in the Python code itself so that it is easily
readable from the IDE. In other words, if I want to use textwrap to
wrap this something long--like this:

lines = textwrap.wrap('Four score and seven years ago our fathers
brought forth on this continent, a new nation, conceived in Liberty,
and dedicated to the proposition that all men are created equal.', 80)

--
Robin Dunn
Software Craftsman

Thanks, that's handy. But, I still don't know the best way to split
long lines of text in the Python code itself so that it is easily
readable from the IDE. In other words, if I want to use textwrap to
wrap this something long--like this:

lines = textwrap.wrap('Four score and seven years ago our fathers
brought forth on this continent, a new nation, conceived in Liberty,
and dedicated to the proposition that all men are created equal.', 80)

Consecutive string constants in Python are automatically concatenated,

I didn't realize that!

so you can do something like this:

lines = textwrap.wrap(
'Four score and seven years ago our fathers brought forth '
'on this continent, a new nation, conceived in Liberty, and '
'dedicated to the proposition that all men are created equal.',
80)

Great. But then Linux doesn't like the wrapping interfering with how
it wraps it (as you recently responded in this list to another
poster), so to deal with both Win and Linux, what I've done is
something like this, in case it's helpful to others who were as unsure
about this as I was:

message = 'Four score and seven years ago our fathers brought forth ' \
                 'on this continent, a new nation, conceived in Liberty, and ' \
                 'dedicated to the proposition that all men are created equal.'

if sys.platform == "win32":
    lines = textwrap.wrap(message,70)
    message = "\n".join(lines)

dlg = wx.MessageDialog(self, message, '', wx.OK | wx.ICON_INFORMATION)
    try:
        result = dlg.ShowModal()
    finally:
        dlg.Destroy()

Thanks for all the help, everyone. This will make my code neater and
the message dialogs look nicely more compact.

Che

···

On Wed, Mar 17, 2010 at 1:19 AM, Robin Dunn <robin@alldunn.com> wrote:

On 3/16/10 6:08 PM, C M wrote: