Re: Data access from multiple code modules



simon.hibbs@xxxxxxxxx wrote:
Jeremy Jones wrote:


What does main.py do? Are you creating an instance of the gui thingy?
If so, you could just pass DataObject into your gui thingy either into
the constructor or to a setter once you create an instance of it.


It's a wxPython app. I created the GUI initialy using wxGlade which
gave me a small myapp.py script, a file containing the main application
frame (containing a listbook controll) and several files containing
panel classes. Each panel class contains controlls for performing
various operations on the data set (adding records, deleting them,
running various transformations).

Do you mean the code effectively doing these operations is in the gui ?
If yes, it would be better to factor it out IMHO.

I can't say I understand how it all
works at a deep level,
although I've been hacking it about quite
successfuly so far.

Presumably if I pass DataObject through to the Frame object, and from
there through to the Panel objects then presumably this will solve the
probelm?

Presumably !-)

I guess it would be passed by reference so all the panels
would be working on the same data object?

Python doesn't really have a "pass by value" semantic, since "variables"
are really just names bound to (ie : refering to) objects. So when it
comes to arguments passing, the argument *name* is local to the function
(rebinding the name won't affect the binding in the caller's namespace),
but what's bound to the name is really a reference to the object (so
mutating the object will effectively affect it).

Doh! How simple. Why didn't I think of that? I'm too used to procedural
scripts where you'd just put everything in a global data structure. I
know this is bad,

Well, depends on the size of the script. But it sure doesn't scale !-)

And FWIW, even with procedural, it's possible (and usually better) to
pass arguments around instead of having a big global datastructure.
Classes are handy when many functions needs to share state (work on a
same dataset), but there's no way to have one call the other and pass it
the dataset.

but it's hard to get out of that mentality.

Seems you're on the right way !-)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb@xxxxxxxxxxx'.split('@')])"
.



Relevant Pages

  • Re: Possible bug in Exchange GUI (Exchange System Manager.msc)
    ... Connection settings for SMTP server. ... Script that I used for changing settings and reading them ... And GUI ...
    (microsoft.public.exchange.admin)
  • Re: how do you test GUI functionality?
    ... (CART; Classic is the name of the application). ... I have one script which tests handing off control from one GUI to ... # Returns a script to push a specified button in a GUI. ...
    (comp.lang.tcl)
  • Re: GUI v Script
    ... > I maintain an old system which has a locally developed script interface. ... > faster with a CLI than a GUI, particularly if the GUI is like Windows, ... with both programming skills and subject matter knowledge. ...
    (comp.object)
  • Possible bug in Exchange GUI (Exchange System Manager.msc)
    ... I’m writing this because I think I found one small bug in Exchange GUI. ... Connection settings for SMTP server. ... Manager.msc on first server and iis.msc on second server. ... First I used script to target settings for SmtpSvc/1 ...
    (microsoft.public.exchange.admin)
  • Re: Scalars Leaked and Segmentation Fault
    ... where you can launch threads after a gui was created. ... before you create the main part of your script. ... (and possibly refs). ... but are harmless. ...
    (comp.lang.perl.misc)