def OnOk(self, hwnd):
        """When OK is pressed, if this isn't a progress dialog then simply
        gather the results and return. If this is a progress dialog then
        start a thread to handle progress via the progress iterator.
        """
        def progress_thread(iterator, cancelled):
            """Handle the progress side of the dialog by iterating over a supplied
            iterator(presumably a generator) sending generated values as messages
            to the progress box -- these might be percentages or files processed
            or whatever.

            If the user cancels, an event will be fired which is detected here and
            the iteration broken. Likewise an exception will be logged to the usual
            places and a suitable message sent.
            """
            try:
                for message in iterator:
                    if wrapped(win32event.WaitForSingleObject, cancelled, 0) != win32event.WAIT_TIMEOUT:
                        self._progress_complete("User cancelled")
                        break
                    else:
                        self._progress_message(message)
            except:
                info_dialog(
                    "An error occurred: please contact the Helpdesk",
                    traceback.format_exc(),
                    hwnd
                )
                self._progress_complete("An error occurred")
            else:
                self._progress_complete("Complete")

        #
        # Gather results from fields in the order they were entered
        #
        self.results = []
        for i, (field, default_value, callback) in enumerate(self.fields):
            value = self._get_item(self.IDC_FIELD_BASE + i)
            if isinstance(default_value, datetime.date):
                try:
                    if value:
                        value = datetime.datetime.strptime(value, "%d %b %Y").date()
                    else:
                        value = None
                except ValueError:
                    win32api.MessageBox(
                        hwnd,
                        datetime.date.today().strftime ("%d %b %Y").lstrip("0") % "Dates must look like:\n%s",
                        "Invalid Date"
                    )
                    return

            self.results.append(value)

        #
        # If this is a progress dialog, disable everything except the
        # Cancel button and start a thread which will loop over the
        # iterator keeping an eye out for a cancel event.
        #
        if self.progress_callback:
            self._set_item(self._progress_id, "Working...")
            for i in range(len(self.fields)):
                self._enable(self.IDC_FIELD_BASE + i, False)
            self._enable(win32con.IDOK, False)
            wrapped(win32gui.SetFocus, wrapped(win32gui.GetDlgItem, hwnd, win32con.IDCANCEL))
            progress_iterator = self.progress_callback(*self.results)
            self.progress_callback = None
            self.progress_thread = threading.Thread(
                target=progress_thread,
                args=(progress_iterator, self.progress_cancelled)
            )
            self.progress_thread.setDaemon(True)
            self.progress_thread.start()

        #
        # Either this isn't a progress dialog or the progress is
        # complete. In either event, close the dialog with an OK state.
        #
        else:
            wrapped(win32gui.EndDialog, hwnd, win32con.IDOK)
dataset/ETHPy150Open tjguk/winsys/winsys/dialogs.py/Dialog.OnOk/swapped operands of `%`