> From: Ignacio
> Sent: Friday, January 22, 2010 11:33 PM
> To: wxpython-users@googlegroups.com
> Subject: Re: [wxPython-users] Re: obtain data from a function inside a class
Well, the reason of why I’m using a different module, is because I like the default interface of matplotlib (I think it’s TkInter), it allows you to move the graph, save it to an image, zoom, etc.
However, I’m using wx as my GUI, so if I wanted to use matplotlib inside my code (that’s it import pylab), I’d have to define it’s own frame, etc, and the resault wouldn’t be as good as this
one (at least in my opinion).
And about the text file, I’m using it because it’s the only way I’ve found of using it, I simply couldn’t pass the variables between different files. Maybe if it was just pure python code
(without wx), I’d be able to, but when you use wx, if you define a class as ‘class … (wx.Frame):’, then the class becomes a subclass of wx, so I couldn’t access to a variable which is
inside a function inside that subclass.
However, if someone finds a better solution, I’m up for it…
Ignacio
Ignacio,
I have found that there are 2 workable ways of passing data between modules that are in different files:
- The lazy way, i.e. have a common data object file that all the others include/import with the data declared as global, (this works but I don’t like it - it is the same as having global variables in C/C++ - this is generally regarded as poor practice), this does mean that all of your files can access the data which is both good and bad - good for the functionality but bad for debugging if you have one line of code that is doing something you do not expect it can be a nightmare to debug.
- The, (in my opinion), better method of having a data object/class that is created by the top level program - the one with the wx.App in - and is passed into both, usually but not necessarily at initialization/creation, i.e. as a parameter to init - this it the equivalent to passing a data pointer in C/C++ - I have used this extensively and it works well and results in elegant code only the objects that have been passed the data object can access it. Of course the object passed does not have to be a pure data object, e.g. I have an application that makes extensive use of a single communications object - the communications are only initialized once, uses a single link per top level program but is accessible to all the message objects that are classed once each and then used by multiple top level programs at the same time.
I would recommend the second approach myself.
Steve
···
–
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en