'Large' program structure - basic concepts
-
I am fairly new to both Python and Pyside. I've written a few single page scripts and some which call objects or functions in modules and things generally work as planned after the usual troubleshooting.
Now, I am trying to write what for me is a large application. Currently it has a main window with menu, tool bar and widgets in the central widget. These widgets (QTabWidgets) have their own seperate modules. The tabs inside these widgets have their own modules. Inside some tabs are QTreeViews and their respective Models... and of course, are written in their own modules. The net result is a heirachical chain of modules calling one another from the top down.
This was done with the intent to keep the program organized and avoid clutter. So far this has worked.
The problem I'm now running into is getting objects at one end of the heirarchy to see objects at the other end and interact if needed. Similar problems between objects at the bottoms of different heirarchy chains.
The immediate small picture problem is working between these scopes / namespaces.
The bigger picture now has me wondering whether the program has been structured in a workable fashion. If not, how does one structure larger applications? Are there different ways to structure larger applications? Any recommended reading / examples / tutorials?
Thank You
-
First, are you talking about instances or classes?
If instances: Although the general rule is: don't use global variables... sometime you do. (After all, if instances 'know' about other instances, they do, you can't pretend they don't, but you could pass them around in parameters.) Commonly, in a config.py module at the top. For example, mainWindow=None in that module. The module creating the main window would:
@import config
...
config.mainWindow = QMainWindow()@If classes, search for 'circular import problem.' Best to avoid, generally by rearranging your classes, but sometimes you solve by doing imports at the bottom of a module.