wxpython: detect whether a dialog has been closed
<p>I am using wxpython to create a GUI and I have the following customized dialog class:</p>

<pre><code>class GetDataDlg(wx.Dialog):

    def __init__(self, *args, **kwargs):
        self.parameters = kwargs.pop('parameters', None)
        request = kwargs.pop('request', None)
        assert self.parameters is not None
        assert request is not None
        strings = re.findall('[A-Z][a-z]*', request)
        info = ""
        for string in strings:
            if len(string) == 1:
                info = info + string
            elif not info:
                info = string.lower()
            else:
                info = info + " " + string.lower()

        wx.Dialog.__init__(self, *args, **kwargs)

        self.data = {}

        main_sizer = wx.BoxSizer(wx.VERTICAL)
        input_text = wx.StaticText(self, label="Please type the new {}".format(info))
        main_sizer.Add(input_text, 1, wx.ALL, 10)
        input_sizer = wx.BoxSizer(wx.HORIZONTAL)
        main_sizer.Add(input_sizer, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT, 10)
        text_sizer = wx.BoxSizer(wx.VERTICAL)
        input_sizer.Add(text_sizer, 1, wx.ALIGN_LEFT | wx.RIGHT, 10)
        ctrl_sizer = wx.BoxSizer(wx.VERTICAL)
        input_sizer.Add(ctrl_sizer, 1, wx.ALIGN_RIGHT)
        self.controls = controls = {}

        for key in self.parameters:
            text = wx.StaticText(self, label=key)
            text_sizer.Add(text, 0, wx.BOTTOM, 17)
            ctrl = controls[key] = wx.TextCtrl(self)
            ctrl_sizer.Add(ctrl, 0, wx.BOTTOM, 10)
        ok_button = wx.Button(self, id=wx.ID_OK)
        main_sizer.Add(ok_button, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
        self.SetSizer(main_sizer)
        self.Fit()
        self.Layout()

        ok_button.Bind(wx.EVT_BUTTON, self.save_data)

    def save_data(self, event):
        for item in self.parameters:
            self.data[item] = self.controls[item].GetValue()
        event.Skip()
</code></pre>

<p>In my main frame I call the dialog like this:</p>

<pre><code>dlg = GetDataDlg(self, parameters=parameter, request=item)
result = dlg.ShowModal()
</code></pre>

<p>Now I need to detect whether the user has pushed the ok button provided by my code or the close button in the right upper part of the dialog provided by the class itself. <code>result</code> does not seem to change in the two cases, neither do other attributes of <code>dlg</code>. Besides I cannot check the existence of <code>dlg.data</code>, because the dialog appears to save the values even when pushing the close button.</p>

<p>Does anyone have any ideas?</p>

<p>You are not binding the close event.<br>
Have you tried inserting a <code>self.Bind(wx.EVT_CLOSE, self.OnQuit)</code> where OnQuit returns wx.ID_CANCEL</p>

python user-interface dialog modal-dialog wxpython