[Tutor] [wxPython-users] passing file name from one script to theGUI class

Tiger12506 keridee at jayco.net
Tue Dec 4 01:59:30 CET 2007

I do not currently have wx installed, but I can see the errors...
I think some information will help you more than answers in this instance.

When you 'import clases_calling', what you are doing is creating a new 
namespace. Inside that namespace is the class 'funct'. In your code, you 
call the function 'clases_calling.func_call' which does not exist because it 
is hidden inside of the class 'funct'. To access this function you would 
have to 'clases_calling.funct.func_call(self)'. This is bad practice, and 
defeats the purpose of using a class. Which is understandable since the 
class 'funct' is not necessary here. All you need is a function that will 
return the new filename right? So, in the clases_calling module place a 
'getnewfilename' function which will return the new filename (no class in 
clases_calling) and in your 'readfile.py' call it by 
'clases_calling.getnewfilename()'. Also, when you try to call 'imagetobit' 
from your current 'func_call' function it will fail because in *this* module 
(clases_calling.py) you have it imported as 'MainWindow.imagetobit'. I would 
highly recommend *not* putting this code in this module anyway, intuitively 
it would belong in the 'OnRead' method right after the call to your new 
function 'getnewfilename'.

More errors to be... sigh.  Here we go.

In your function 'imagetobit' in readfile.py you should get an error because 
'self' is not defined. You have not put self in the argument list as you did 
in all the other methods of MainWindow. This also means that self.imageFile1 
will not be defined either, and should give you an error when trying to 
define it. If you adjust the imagetobit function so that it is a method of 
the class, we see that the imagename parameter is no longer necessary, as we 
can set the self.imageFile variable directly from one of the other 
functions. Also, I see code that looks very similar in the __init__  method 
of MainWindow and the function imagetobit. I suggest that you change this so 
that in the __init__ method you actually call self.imagetobit.

To summarize:
  1) Change clases_calling.py to be a single function that return the new 
filename as a string.
  2) Change MainWindow.OnRead so that it calls this new function first (I 
used clases_calling.getnewfilename()), then self.imagetobit(), and finally 
run the rest of the commented stuff you have there (Remembering that the 
Image redrawing has already been done in self.imagetobit() you can delete it 
 3) Change imagetobit so that it is a method of the class MainWindow, and 
remove the imagename parameter
 4) Change all references of self.imageFile1 to just self.imageFile. You do 
not need the extra.
 5) Change MainWindow.__init__ so that it calls self.imagetobit() 
immediately after you set the variable self.imageFile

And... I think that's everything. IMHO the important concept inherently 
missed in these two modules is that the names of the functions and variable 
inside are hidden behind the names. i.e.
import math  is used as math.sqrt, instead of just sqrt.


More information about the Tutor mailing list