title: How to terminate thread using condition returned by wx.CallAfter()?
body: <p>I am very new to wxPython and also not familiar with thread concept. I would appreciate a lot if anyone could provide info sources or suggestion to my question. </p>
  
  <p>I had created a GUI using wxpython to allow users run my script with inputs. Since one step takes 20 min to run so I plan to create a Progress Dialog to show users progress and allow them to abort it. I had tested this using the sample code below. </p>
  
  <p>However, I couldn't stop WorkThread even though I clicked the Stop Button in Progress Dialog. I tried 
   1. make if statement using return value from pb.sendMessage() 
   2. create the ProgressDialog object when WorkThread starts and call ProgressDialog.abort 
  but none of them work. I wonder if there's conceptual mistakes implementing code like this to achieve what I want to do? Or if this can work with correction? Any hint would be appreciated!!</p>
  
  <pre><code>class WorkThread(Thread):
  
      def __init__(self):
          """Init Worker Thread Class."""
          Thread.__init__(self)
          self.start()  # start the thread
  
      def run(self):
  
          for i in range(10):
              time.sleep(1)
              val = 100 / 10
              wx.CallAfter(pub.sendMessage, "update", step=val)
          print 'Finish Run'
  
  class ProgressDialog(wx.Dialog):
      def __init__(self):
  
          wx.Dialog.__init__(self, None)
          self.abort = False
          self.progress = 0
  
          bSizer2 = wx.BoxSizer(wx.VERTICAL)
          self.gauge = wx.Gauge(self, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL)
          self.gauge.SetValue(0)
  
          self.m_button1 = wx.Button(self, wx.ID_ANY, u"Stop Training", wx.DefaultPosition, wx.DefaultSize, 0)
          bSizer2.Add(self.gauge, 0, 0, 5)
          bSizer2.Add(self.m_button1, 0, 0, 5)
  
          self.SetSizer(bSizer2)
          self.Layout()
          self.Centre(wx.BOTH)
  
          ## Connect Events
  
          self.m_button1.Bind(wx.EVT_BUTTON, self.on_cancel)
          pub.subscribe(self.updateProgress, "update")
  
      def updateProgress(self, step):
          self.progress += step
  
          if self.abort:
              self.Update()
              self.Close()
          elif self.progress &gt;= 100:
              self.gauge.SetValue(self.progress)
              self.Update()
              self.Close()
          else:
              self.gauge.SetValue(self.progress)
  
      def on_cancel(self, event):
          """Cancels the conversion process"""
          self.abort = True
          print 'Click'
          # pub.unsubscribe(self.if_abort, 'cancel')
  
      def __del__(self):
          pass
  
  
  ########################################################################################
  
  class MainFrame(wx.Frame):
      # ----------------------------------------------------------------------
      def __init__(self,parent):
          wx.Frame.__init__(self,parent)
          # Add a panel so it looks the correct on all platforms
          panel = wx.Panel(self, wx.ID_ANY)
          self.btn = btn = wx.Button(panel, label="Start Thread")
          btn.Bind(wx.EVT_BUTTON, self.onButton)
  
          sizer = wx.BoxSizer(wx.VERTICAL)
          sizer.Add(btn, 0, wx.ALL | wx.CENTER, 5)
          panel.SetSizer(sizer)
  
      # ----------------------------------------------------------------------
      def onButton(self, event):
          btn = event.GetEventObject()
          btn.Disable()
          WorkThread()
          self.dlg = ProgressDialog()
          self.dlg.ShowModal()
          btn.Enable()
  
  app = wx.App()
  frame = MainFrame(None)
  frame.Show(True)
  # start the applications
  app.MainLoop()
  </code></pre>