Reputation: 15
I am writing a class in wxPython that displays error dialogs. Here is my code:
import wx
class Error:
def __init__(self, number, string):
self.error_type = number
self.error_message = string
self.choose_error()
def choose_error(self):
if self.error_type == 1:
self.DisplayMessage1()
elif self.error_type == 2:
self.DisplayMessage2()
elif self.error_type == 3:
self.DisplayMessage3()
elif self.error_type == 4:
self.DisplayMessage4()
def DisplayMessage1(self):
dial = wx.MessageDialog(None, self.error_message, 'Info', wx.OK)
dial.ShowModal()
def DisplayMessage2(self):
dial = wx.MessageDialog(None, self.error_message, 'Error', wx.OK |
wx.ICON_ERROR)
dial.ShowModal()
def DisplayMessage3(self):
dial = wx.MessageDialog(None, self.error_message, 'Question',
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
dial.ShowModal()
def DisplayMessage4(self):
dial = wx.MessageDialog(None, self.error_message, 'Warning', wx.OK |
wx.ICON_EXCLAMATION)
dial.ShowModal()
How can change the default icons used to the custom ones?? I tried to replace them with wx.Icon but it did not work. Are dialogs in wxPython limited to the icons I used above? On Mac OS X they do not seem to display correctly.
Upvotes: 1
Views: 2124
Reputation: 57774
Arguments like wx.ICON_ERROR
or wx.ICON_EXCLAMATION
are not real icons, but rather integer flags for wx.MessageDialog
constructor. Those message dialogs are rendered natively with operating system calls, so they look differently e.g. on Windows and Mac OS X.
As wxWidgets was designed for Windows API, MessageDialog
arguments closely resemble Windows API MessageBox function style flags (MB_ICONERROR
, MB_ICONEXCLAMATION
, etc.).
If you want to use your own icons for dialogs, you just have to implement your own message dialog class, basing on wx.Dialog
.
Upvotes: 3