When display a wx.MessageBox with a
multiline message, and the 2nd line is empty, then the first
line is rendered in a larger font and blue colour on Windows10,
but not on Mac.
The Mac just displays the caption in bold
and the multiline text as normal text. This is what I’d prefer
on all platforms (more or less, not withstanding that Windows
seems to put the caption in the window frame).
Why does Windows render the first line of
the message in a larger font and a blue colour? (only if there
3 or more lines and the 2nd line is empty). It looks like a
caption (which it is not).
Is this a bug in wx.Python or just a
Windows specific native dialog thang?
wxPython 4.0.3 and Python 3.6.
`import wx``
``
``message = """\``
`` Line 1 => a long multiline message to display in a
wx.MessageBox``
`` Line 3 => a long multiline message to display in a
It’s just differing behaviors of the native dialogs. If you would like the same behavior on each platform then you’ll need to make a custom dialog. The wx.lib.msgpanel.MessagePanel might be a good starting point.
···
On Wednesday, November 7, 2018 at 6:17:57 PM UTC-8, Brendan Simon wrote:
When display a wx.MessageBox with a
multiline message, and the 2nd line is empty, then the first
line is rendered in a larger font and blue colour on Windows10,
but not on Mac.
The Mac just displays the caption in bold
and the multiline text as normal text. This is what I’d prefer
on all platforms (more or less, not withstanding that Windows
seems to put the caption in the window frame).
Why does Windows render the first line of
the message in a larger font and a blue colour? (only if there
3 or more lines and the 2nd line is empty). It looks like a
caption (which it is not).
I might investigate that at some stage, however I worked around it by manipulating the caption and message attributes for __WXMSW__ platforms, so that if a caption was specified that it was inserted in the first line of the message followed by an empty second line. If no caption was specified, then I made sure the second line was not empty (set to a space).
I also cleared the caption setting so it wasn’t duplicated in the titlebar. This was also interesting. Setting it to an empty string, produced “python.exe” in the titlebar. Setting it to None caused an exception (unexpected type. i.e. not a string). Removing the attribute from kwargs produced “Message”. I had to set caption to a space for nothing to be displayed in the titlebar. I wonder why setting it to an empty string causes “python.exe” to be displayed?
def MessageBox( message, **kwargs ):
“”“Custom message box to handle differences in Windows/Mac rendering”“”
if wx.Platform == '__WXMSW__' :
lines = message.split('\n')
cap = kwargs.get( 'caption', None )
if cap == '' :
#! Windows displays 'python.exe` if caption == ''
#! Windows displays 'Message' caption is not present (the default)
#del kwargs['caption']
kwargs['caption'] = ' '
if cap :
#! have a caption, so place it on first line of message,
#! followed by an empty line, then append the rest of the message.
lines = [ cap, '\n' ] + lines
elif len( lines ) >= 3 and lines[1] == '' :
#! if no caption, and there are 3+ lines,
#! then make sure second line is NOT empty.
lines[1] = ' '
#! reassemble message
message = '\n'.join( lines )
wx.MessageBox( message, **kwargs )
``
···
On Wednesday, November 7, 2018 at 6:17:57 PM UTC-8, Brendan Simon wrote:
When display a wx.MessageBox with a
multiline message, and the 2nd line is empty, then the first
line is rendered in a larger font and blue colour on Windows10,
but not on Mac.
The Mac just displays the caption in bold
and the multiline text as normal text. This is what I’d prefer
on all platforms (more or less, not withstanding that Windows
seems to put the caption in the window frame).
Why does Windows render the first line of
the message in a larger font and a blue colour? (only if there
3 or more lines and the 2nd line is empty). It looks like a
caption (which it is not).
Is this a bug in wx.Python or just a
Windows specific native dialog thang?
wxPython 4.0.3 and Python 3.6.
On Thursday, 8 November 2018 14:29:33 UTC+11, Robin Dunn wrote:
It’s just differing behaviors of the native dialogs. If you would like the same behavior on each platform then you’ll need to make a custom dialog. The wx.lib.msgpanel.MessagePanel might be a good starting point.
It is probably using the app object’s GetAppName() method to get the string to be displayed in that case.
···
On Thursday, November 8, 2018 at 8:05:15 PM UTC-8, Brendan Simon wrote:
I also cleared the caption setting so it wasn’t duplicated in the titlebar. This was also interesting. Setting it to an empty string, produced “python.exe” in the titlebar. Setting it to None caused an exception (unexpected type. i.e. not a string). Removing the attribute from kwargs produced “Message”. I had to set caption to a space for nothing to be displayed in the titlebar. I wonder why setting it to an empty string causes “python.exe” to be displayed?