Retrieving and displaying OS icons in custom controls

Hello everyone,

Until now, I’ve been using a standard wx.MessageDialog to notify users when errors have been encountered in my app. Though this works well enough, I’d like to ideally add a couple custom controls (read-only log TextCtrl, copy to clipboard and send to developer).

After some experimentation, it doesn’t look as if subclassing wx.MessageDialog is an option, as my custom UI basically just gets thrown out. I’m assuming this is because the actual rendering is done directly through OS APIs.
So now I’ve been attempting to use a standard wx.Dialog with an STD button sizer, but I’m once more stopped at displaying an ICON_ERROR. It briefly looked like wx.ArtProvider would have the answer, but after thirty minutes of trying to get the right icon and display it I’m back at the drawing board.

Has anyone done something similar? If so, any pointers would be appreciated, I’m probably overthinking this one.


I wrote my own version of a MessageDialog class because I don’t like the one provided by GTK3 which stretches the buttons to fit the width of the dialog.

I don’t claim it’s the best or right way to do this, but it might give you some clues had to create your customised version: (8.9 KB)

The MessagePanel class in the wx.lib.msgpanel module can be a good starting point.

These were exactly what I was looking for.

In essence:

style = wx.ART_ERROR
icon = wx.ArtProvider.GetBitmap(style, wx.ART_MESSAGE_BOX)
# add to wx.StaticBitmap

To more accurately emulate a MessageBox, I also implemented the following function which plays a sound based on the provided icon. As far as I know this would only be necessary under windows.

def play_icon(icon):
	if platform.system() == "Windows":
		import winsound
		if icon & wx.ICON_ERROR:
			snd = winsound.MB_ICONHAND
		elif icon & wx.ICON_QUESTION:
			snd = winsound.MB_ICONQUESTION
		elif icon & wx.ICON_EXCLAMATION:
			snd = winsound.MB_ICONEXCLAMATION
		elif icon & wx.ICON_INFORMATION:
			snd = winsound.MB_ICONASTERISK
			return  # couldn't interpret the icon

Thanks again