using wxpython with non-GUI applications

From: Aaron Brady [mailto:castironpi@comcast.net]
Sent: Thursday, January 17, 2008 8:34 PM
> From: Aaron Brady [mailto:castironpi@comcast.net]
> Sent: Wednesday, January 09, 2008 5:21 PM
Here's a splash. Perky li'l. Attached & reproduced.

Thinking still.

Here's the catch.

Repaired. Attached.

        @ThreadEx
        def thr1( thr1 ):
            while 1:
                with thr1.finishlock:
                    if not thr1.bContinue: break
                    AsyncCall( gauge1.Pulse ) #do not Wait
                    caption= AsyncCall( text1.GetValue ).Wait( 1 )
                    print 'Text: %s\n'% caption,
                time.sleep( .1 )

Here:

        def thr1( thr1 ):
            while thr1.bContinue:
                AsyncCall( gauge1.Pulse ) #do not Wait
                captcall= AsyncCall( text1.GetValue )
                caption= captcall.Wait()
                print 'Text: %s\n'% caption,
                time.sleep( .01 )
            wx.CallAfter( frame.Destroy )

        @BindEx( frame, wx.EVT_CLOSE )
        def onclose( event ):
            thr1.bContinue= False
            with thr1.finishlock: pass
            event.Skip()

And here:

        @BindEx( frame, wx.EVT_CLOSE )
        def onclose( event ):
            event.Skip( False )
            thr1.bContinue= False

Just move Destroy to the end of 'thr1', and remove thr1.finishlock.

You could even do:

  frame.Bind( wx.EVT_CLOSE, lambda e: ( e.Skip( False ), thr1.Stop() )
)

for the binding.

asyncable-revised.py (2.28 KB)

···

-----Original Message-----
> -----Original Message-----

        def thr1( thr1 ):
            while thr1.bContinue:
                AsyncCall( gauge1.Pulse ) #do not Wait
                captcall= AsyncCall( text1.GetValue )
                caption= captcall.Wait()
                print 'Text: %s\n'% caption,
                time.sleep( .01 )
            wx.CallAfter( frame.Destroy )

        @BindEx( frame, wx.EVT_CLOSE )
        def onclose( event ):
            event.Skip( False )
            thr1.bContinue= False

Just move Destroy to the end of 'thr1', and remove thr1.finishlock.

wx.CallAfter( frame.Destroy ) can go back wither it was. 'thr1' is sort of
like 'self' for threads. Two concurrents are running too.

  @ThreadWx.Arg( 1 )
  def thr1( thr1, thid ):
    with guilock:
      if not thr1.bContinue: return
      wx.CallAfter( gauge1.Pulse )
      @ThreadWx.CallAfter( text1.GetValue )
      def nextstep( nextstep, caption ):
        with guilock:
          print 'Text %i: %s\n'%( thid,
caption ),
          time.sleep( .01 )
          thr1.Restart( thid )
    nextstep.Joins()
  thr1.Restart( 2 )

  if closeimm: wx.CallLater( 100, frame.Close )

  @BindEx( frame, wx.EVT_CLOSE )
  def onclose( event ):
    event.Skip( False )
    thr1.bContinue= False
    with guilock: pass
    wx.CallAfter( frame.Destroy )

  app.MainLoop()
  thr1.Joins()

And some output:
  Text 1: Arbitrary text
  Text 2: Arbitrary text
  Text 1: Arbitrary text
  Text 2: Arbitrary text

asyncable5 works.py (3.51 KB)