Returning value from home made unit - how to?

bobicanprogram icanbob at gmail.com
Tue Jun 1 09:07:56 EDT 2010


On May 30, 6:22 pm, Mel <mwil... at the-wire.com> wrote:
> Martin Hvidberg wrote:
> > I have a Python program, which has until now, been running in command line
> > mode only. I wish to add a GUI.
>
> > I would like to develop (and maintain) the GUI part in a separate module,
> > i.e. in its own .py file, and then ‘import’ that into the old main
> > program.
>
> > I jumped into wxPython, as it seems to be the right GUI for me, and
> > downloaded some examples that I took apart and joined. Now the basic GUI
> > is running, though neither beautiful nor complete.
>
> > The main task for my GUI is to allow the user to point to an input file.
> > It can now obtain a filename from a file selection dialog, but I can’t
> > figure out how to get the filename, i.e. the string variable containing
> > the file name, send back to the main program…
>
> > I attach the two .py files hereunder.
>
> > My question is:
> > How do I get the information from variable strSequenceFile, back to the
> > main module in file jacxl.py ?
>
> AFAIK, typically, you don't -- the way it is here.  Returning a value from a
> Button handler, or any event handler generally, won't have any effect.  The
> event handlers are called from deep in wx code by routines that don't deal
> with anything specific to the data-processing side of the program.
>
> What I think you might do is to make strSequenceFile an attribute of your
> Frame, so that OnFindFile button does ``self.strSequenceFile =
> dialog.GetPath()'' rather than returning that value.
>
> Then your main level can do ``jacXlgui.app.GetTopWindow().strSequenceFile''
> .
>
> There are probably refinements to be added to this, but I think it's a good
> beginning strategy.  The first new place I would take the whole program
> would be to remove the command-line controls from the command line program,
> so you're left with a sort of "business model" that contains only the data
> processing.  Then you can write a new GUI program based on jacXlgui that
> imports the  data processing module and calls computations and reports
> results from the model.
>
>         Mel.


Another way to encapsulate functionality like a GUI is to "hide" it
behind a nice clean messaging interface.  The SIMPL toolkit (http://
www.icanprogram.com/06py/lesson1/lesson1.html) promotes this kind of
design.  SIMPL allows Python to Python messaging as well as Python to
C, C++, JAVA or Tcl/Tk so what you ultimately choose for the GUI has
only minimal impact on what you choose for your "processing engine".

Happy coding.

bob



More information about the Python-list mailing list