On Wed, Mar 28, 2012 at 2:31 PM, Jonno
Take this calculator example: CalculatorDemo - wxPyWiki
Let's say I want to launch the calculator (gui and all) from another
script and then give it some inputs and then tell it to calculate the
sum of the inputs and then display the result in the UI. How would one
do that?
got curious, so I did a bit more:
first, that demo brings up a dialog with ShowModal() which kind of
complicates things, as that crates its own event loop. so I
re-factored it to use a regular frame.
Then the app had no hooks to have it calculate -- sending key strokes
seemed to be overkill (and difficult to do cross-platform) -- so I
added a "ComputeExpression" mehtod, that sets an expression, and calls
compute (I needed to factor out the compute method, too...)
Anyway, with a now "drivable" GUII app, I wrote a script that starts
up the app, then starts up a new thread to do stuff in, then starts
the mailoop of the app.
as the secondary thread does its thing -- it uses wx.CallAfter to call
the "ComputeExpression" method on the Calculator.
Note that in this case, calling that method directly worked, but
that's not reliable with multi-threading.
This was kind of fun -- even though maybe not what you were looking for.
See enclosed. (start the CalculatorDriver.py) script to run.
-Chris
CalculatorDemo.py (2.69 KB)
CalculatorDriver.py (853 Bytes)
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov