I have a wxPython program which does some calculations and displays
the results. During these calculations if I click the mouse inside the
dialog the program locks up. If I leave the dialog alone the process
completes fine. I have tried running the function from a separate
dialog with Show Modal and I have tried using SetEvtHandlerEnabled all
to no avail. The program is long and occupies several files so I won't
show the whole thing but here is the calculation part. How do I block
events?

    def DoEfficiency(self):

      from time import sleep

      self.timer.Stop()



      TotalPower = 0
      Counter = 0
      for ang in range(1,89):
        self.tc_angle.SetValue(ang)
        height = int(self.eclwidth * 10)
        for hgt in range(0,height):
          self.tc_height.SetValue(float(hgt)/10.0)
          self.UpdateValues()
          self.Redraw()
          self.DrawRays()
          sPower = self.tc_power.GetValue()
          Power = sPower.split('%')
          TotalPower +=float(Power[0])
          Counter +=1
          sleep(0.1)

      efficiency = TotalPower/Counter
      self.tc_eff.SetLabel(str(round(efficiency,1)))
      self.timer.Start(10)


    # end DoEfficiency

    def OnEfficiency(self, event):

      self.tc_aangle.SetEvtHandlerEnabled(False)
      self.tc_angle.SetEvtHandlerEnabled(False)
      self.tc_calc_len.SetEvtHandlerEnabled(False)
      self.tc_cpclength.SetEvtHandlerEnabled(False)
      self.tc_cpcwidth.SetEvtHandlerEnabled(False)
      self.tc_det.SetEvtHandlerEnabled(False)
      self.tc_ecl.SetEvtHandlerEnabled(False)
      self.tc_eff.SetEvtHandlerEnabled(False)
      self.tc_gap1.SetEvtHandlerEnabled(False)
      self.tc_gap2.SetEvtHandlerEnabled(False)
      self.tc_height.SetEvtHandlerEnabled(False)
      self.tc_parab.SetEvtHandlerEnabled(False)
      self.tc_power.SetEvtHandlerEnabled(False)
      self.tc_refresh.SetEvtHandlerEnabled(False)
      self.tc_tlength.SetEvtHandlerEnabled(False)
      self.tc_twidth.SetEvtHandlerEnabled(False)
      self.tc_use_tir.SetEvtHandlerEnabled(False)
      self.SetEvtHandlerEnabled(False)

      dlf = CalcEfficiency(self,"CalcEfficiency",wx.DefaultPosition,
(90,60))

      self.tc_aangle.SetEvtHandlerEnabled(True)
      self.tc_angle.SetEvtHandlerEnabled(True)
      self.tc_calc_len.SetEvtHandlerEnabled(True)
      self.tc_cpclength.SetEvtHandlerEnabled(True)
      self.tc_cpcwidth.SetEvtHandlerEnabled(True)
      self.tc_det.SetEvtHandlerEnabled(True)
      self.tc_ecl.SetEvtHandlerEnabled(True)
      self.tc_eff.SetEvtHandlerEnabled(True)
      self.tc_gap1.SetEvtHandlerEnabled(True)
      self.tc_gap2.SetEvtHandlerEnabled(True)
      self.tc_height.SetEvtHandlerEnabled(True)
      self.tc_parab.SetEvtHandlerEnabled(True)
      self.tc_power.SetEvtHandlerEnabled(True)
      self.tc_refresh.SetEvtHandlerEnabled(True)
      self.tc_tlength.SetEvtHandlerEnabled(True)
      self.tc_twidth.SetEvtHandlerEnabled(True)
      self.tc_use_tir.SetEvtHandlerEnabled(True)
      self.SetEvtHandlerEnabled(True)

# end MyInterface


class CalcEfficiency(wx.Dialog):
    """
    """
    def __init__(self, parent, title, pos, size):

        self.parent = parent


        wx.Dialog.__init__(self,parent, -1, title, pos, size)

        self.runButton = wx.ToggleButton(self, ID_TOGGLE, "Start",
                                wx.DefaultPosition, (70,30))
        self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, id =
ID_TOGGLE)

        self.ShowModal()

        self.Destroy()

    # end init

    def OnToggle(self, event):

      if self.runButton.GetValue():
        self.runButton.SetLabel("WAIT")
        self.SetEvtHandlerEnabled(False)
        self.parent.DoEfficiency()
        self.SetEvtHandlerEnabled(True)
      else:
        self.Close()


    # end OnQuit

# end CalcEfficiency


if __name__ == '__main__':
    app = MyApp(False)
    app.MainLoop()

# end main
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to