[wxPython-users] Help !!!

Joe Brown joebrown at podiatryfl.com
Sun Oct 29 12:11:29 PST 2006


This little tidbit comes in handy and works better than yeild(ing) when
you keep the gui thread's attention.

while wx.GetApp().Pending()
  wx.GetApp().Dispatch()

It is advisable that a separate thread be used for processing extended
loops/etc.  But that's a bigger ball of wax, ie. messaging between
threads for progress status, etc. 


-Joseph

On Sun, 2006-10-29 at 11:26 -0700, Josiah Carlson wrote:
> "ROY ZINN" <royzinn at hotmail.com> wrote:
> > 
> > Hi All,
> > 
> > I'm using wxpython to run hardware tests. the gui has a splitter window 
> > which the right pane is used for stdout/stderr, the left is the list of 
> > test.
> > 
> > when i run on the list of tests, i use functions imported from other file.
> > 
> > the problem is that when i start to run the test (in a loop until the last 
> > test), the GUI gets stuck, and at some point it looks as if the same test 
> > runs over and over again in undefinite loop !!!
> > 
> > the part of the code that handles the loop is attached, the rest of the 
> > functions do not use wxpython, but they use our own DLL.
> > 
> > i tried wx.SafeYield() and self.Update to refresh etc
> 
> The GUI won't update while you are not calling wx.Yield() or
> wx.SafeYield() in your code.  Let us say, for example, that your test
> function was defined and called like the following...
> 
> def test_fcn():
>     time.sleep(10)
> 
> ...
>     def OnRunClick(self, event):
>         for i in xrange(10):
>             test_fcn()
>             wx.Yield()
> 
> Then every 10 seconds the GUI will update, but nothing will happen when
> time.sleep(10) is waiting 10 seconds.
> 
> 
> Want my suggestion?  Use wx.lib.delayedresult.  Below is an updating of
> your method to use delayedresult in wxPython 2.7 .  If you want to stop
> the testing early, use del obj.tests[:], and it will stop testing when
> it is done with the most recent test.  Also, don't use 'is' for string
> comparison.  It only works here because Python (generally speaking)
> interns all strings that could be variable names, but generally you want
> the == semantics for string comparison.
> 
>  - Josiah
> 
> 
> import wx.lib.delayedresult as dr
> 
> ...
>     def __init__(...):
>         ...
>         
>         self.tests = []
>         self.running = 0
>         
>         ...
>     
>     def OnRunClick(self, event):
>         if self.running:
>             return
>         
>         dialog = GeneralParametersDialog()
>         result = dialog.ShowModal()
>         
>         tests = self.tests
>         
>         smpl = self.MidPanel.list
>         
>         Num_Of_Tests = smpl.GetItemCount()
> 
>         for index in range(Num_Of_Tests):
>             smpl.SetItemBackgroundColour(index,'yellow')
>             TestName = smpl.GetItemText(index)
>             TestType = dictionary_data.dict[TestName][0]
> 
>             if TestType is 'dch':
>                 dch = dictionary_data.dict[TestName][1]
>                 test_param = All_Tests.set_test_param('dch ' + dch + ' results', 0, -99, 0)
>                 
>                 tests.append((index, All_Tests.run_on_dch, (test_param, [str(dch)])))
> 
>             elif TestType is 'fach':
>                 SlotFormat = dictionary_data.dict[TestName][1]
>                 test_param = test_param = All_Tests.set_test_param('fach ' + SlotFormat + ' results', 0, -99, 0)
>                 
>                 tests.append((index, All_Tests.Run_on_FACH_RACH, (test_param, [int(SlotFormat)])))
> 
>             elif TestType is 'sho':
>                 dch = dictionary_data.dict[TestName][1]
>                 test_param = All_Tests.set_test_param('dch_sho ' + dch + ' results', 0, -99, 0)
>                 
>                 tests.append((index, All_Tests.run_on_dch, (test_param, [str(dch)])))
> 
>             elif TestType is 'cm':
>                 CmMethod = dictionary_data.dict[TestName][1]
>                 Pattern = dictionary_data.dict[TestName][2]
>                 MaxNumOfPatterns = dictionary_data.dict[TestName][3]
>                 test_param = All_Tests.set_test_param('cm ' + Pattern + ' results', 0, -99, 0)
>                 
>                 tests.append((index, All_Tests.run_on_cm, (test_param, [Pattern, MaxNumOfPatterns])))
>         
>         self.running = 1
>         self.OnRunResult(None, None)
>     
>     def OnRunResult(self, TestResult, index):
>         if index is not None:
>             if TestResult == 'pass':
>                 self.MidPanel.list.SetItemBackgroundColour(index,'green')
>             else:
>                 self.MidPanel.list.SetItemBackgroundColour(index,'red')
>         self.RightPanel.log.clear()
>         if self.tests:
>             index, testfcn, args = self.tests.pop(0)
>             dr.startWorker(self.OnRunResult, testfcn, cargs=(index,), wargs=args)
>         else:
>             self.running = 0
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
> 
> 





More information about the wxpython-users mailing list