jeudi 17 mars 2016

Is it possible to make a python message dialog using Model-View-Controller architecture?

I'm trying to do a class that holds all my message dialogs such I don't need to have them mixed with my logic. The aim is to keep the GUI code away of the Non-GUI stuff, I'd like achieve a nice Model-View-Controller architecture

class errorMessageDialog(wx.MessageDialog):

    def __init__(self, message, caption= 'Error'):
        wx.MessageDialog.__init__(self, None, message, caption, wx.OK | wx.ICON_ERROR)
        self.ShowModal()
        self.Destroy()

I've manage to do it for simple error messages (see exemple above), however I'd like to do a message dialog where the user can select either OK or Cancel. In that case the method should return a boolean. I tried the following:

class safetyCheckAFT(wx.MessageDialog):
    def __init__(self, message="Make sure the following set commands won't famage your platform", caption= 'Safety Warning'):
    wx.MessageDialog.__init__(self, None, message, caption, wx.OK | wx.CANCEL | wx.CENTRE | wx.ICON_EXCLAMATION)

        if self.ShowModal() == wx.ID_OK:
            safetyCheckPassed = True
        else:
            safetyCheckPassed = False
        return safetyCheckPassed
        self.Destroy()

I might be mistaken but I think what I'm trying to achieve is not possible cause the self.Destroy method must be called before the return, therefore the return line is never run.

Obviously I could create my dialog inside my model code but this would be messy.

Aucun commentaire:

Enregistrer un commentaire