Python Forum
[PyQt] Managing variables accross a multiple module GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Managing variables accross a multiple module GUI
#2
First and foremost -- K.I.S.S. It -- aka Keep It Simple and Smart -- keep in mind making something more complex is often not smart as it can cause lots of issues later on.

Yes (2) sounds like another way to implement global variables which are and were almost always a very bad idea. Yes sometimes unavoidable but most of the time not the case just lazy thinking. (1) Sometimes passing a structure containing data works but most often if you find you are passing quite a few bits of information then their is something wrong with the basic design try rethinking things.

Now as for variables in generaly this is greatly dependent on the variables in question but I typically pass just a handle to the child of its parent in most cases where there is something significant going on within the child that might require the parents guidance or assistance. This thus allows direct access of all the shared variables in the child to the parent and vice versa. For again passing specific variables can get rather lengthy and/or cumbersome eventually and eventually this means you need to rethink the design.

Next make sure your variables have the proper scope and that you are not being lazy minded and just creating global variables (or nearly global variables) for nearly everything. I see this a lot in post production code and subsequently have had to clean a lot of that up. Make sure that the variable needs to be persistent but also make sure it needs to be shared. Sometimes restructuring the code can limit the need of passing and/or sharing such variables. For instance maybe instead of passing some variables you got from the database you instead pass a handle to the database class or create another instance of that class locally. Keep in mind keeping a persistent connection to any data source (be it a database or otherwise) is generally not a good idea for many reasons so doing this is quite viable in most cases.

When modularizing your GUI do your best to design it so that each module encapsulates its functionality in a manner that "passing variables" between modules becomes the exception and not the rule.

Okay those are just a few ideas. Again K.I.S.S. It always -- and thoroughly exercise the gray matter to produce quality designs
Reply


Messages In This Thread
RE: Managing variables accross a multiple module GUI - by Denni - Jun-27-2019, 01:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Tkinter] Defining a self made module's function to interact with the main .py variables? Gilush 9 4,500 Jun-08-2020, 09:08 AM
Last Post: Gilush

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020