Re: Data access from multiple code modules




simon.hibbs@xxxxxxxxx wrote:
Lets say that I have an application consisting of 3 files. A main.py
file, gui.py and a data.py which handles persistent data storage.
Suppose data.py defines a class 'MyDB' which reads in data from a
database, and main.py creates an instance of this object. How does code
in gui.py access this object? Here's simplified pseudocode:

MAIN.PY
import gui, data
DataObject = data.MyDB(blah)

How do I write code in gui.py that can access DataObject? Is this
entirely the wrong way to approach this sort of problem?

Actualy the problem is more complex because the GUI consists of a main
GUI form, and panels defined as seperate objects in seperate files.
Various panels will contain controlls for manipulating data in the
DataObject, or wherever data storage end up.

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. If
the gui needs any database stuff at instantiation time, you probably
need to pass it into the constructor. However, a main.py, gui.py, and
db.py smells a little like your standard MVC, in which case, you would
get your controller to pass in the data pieces as the GUI needs them.

- Jeremy M. Jones

.



Relevant Pages

  • Re: Data access from multiple code modules
    ... How do I write code in gui.py that can access DataObject? ... GUI form, and panels defined as seperate objects in seperate files. ... or wherever data storage end up. ... and have the GUI part call on the controler. ...
    (comp.lang.python)
  • Data access from multiple code modules
    ... Lets say that I have an application consisting of 3 files. ... How do I write code in gui.py that can access DataObject? ... Actualy the problem is more complex because the GUI consists of a main ... or wherever data storage end up. ...
    (comp.lang.python)
  • Re: Data access from multiple code modules
    ... you could just pass DataObject into your gui thingy either into ... Each panel class contains controlls for performing ... depends on the size of the script. ...
    (comp.lang.python)
  • Re: Complex Windows Applications in C# -- how high is the bar?
    ... child windows containing various Windows controls, ... application in order to stretch it to handle an enitrely new database ... concern is the GUI -- this is a very complex application in terms of its ... There's nothing wrong with letting the complex GUI stuff remain in the hands of Win32 code and use managed code for the database access, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: porting curses driven to gui application
    ... > more than just replace the curses interface by a GUI. ... > don't have a X server (e.g. because they are just running Windows ... > running on the machine where the database is also running. ... > server and the client on the user side. ...
    (comp.unix.programmer)