[Python-talk] Speaking of oops. How to call a method in another class in another file?
bruce.labitt at autoliv.com
bruce.labitt at autoliv.com
Tue Jul 28 14:43:27 EDT 2009
I'm plodding along with wxpython. I mostly have the graphic part set up.
Now I am trying to connect the display to bits of my program. The first
bit is to plot an existing data file. I used filepicker to get the full
file name. I don't quite understand how to invoke/use one of the methods
that I created in the class Xambig.
Xambig is in the file genwave.py. Inside of Xambig is a method named
plotMe.
class Xambig:
def __init__(self):
blah
def generateWaveform(self):
def runEngine(self):
def plotMe(self, mypath, myrange):
"""Reads binary file in mypath. Generates surface plot
using mayavi.
Range is restricted to myrange.
"""
MyForm is inside the file mygui1.py. MyForm is the main app.
import wx
import string, os
import genwave
class MyForm( wx.Frame, genwave.Xambig ):
def __init__(self, log, imgfile):
self.log = log
wx.Frame.__init__(self, None, -1, 'Frame Title')
self.idlecnt = 0
self.D = { a whole lot of stuff ... }
lots o stuff. events, binding, etc.
def onOK(self, event):
"""The user has pressed the Start Button. Read the log
and update the
dictionary. If the user has previously selected, 'Plot
existing' then plot the
datafile. The datafile name is stored in the dictionary
and must be
retrieved
"""
self.log.seek(0) # rewind log file
pointer
logList = self.log.readlines() # read log file
for myline in logList:
readkey = myline.split(', ')[0]
readval = myline.split(', ')[1]
self.D[readkey] = readval # overwrite
initial dictionary with log results
myrange = 150
filepath = self.D.get("Datafile Path") # get file path
plot = self.D.get("Plot Selection") # get the
selection
if ( plot =="Plot existing"):
p = genwave.Xambig()
plotme(p, filepath, myrange) ???
Runtime error is NameError: global name 'plotme' is not defined. Looking
for answers in the vast internet have not yielded too much. I hope this
is simple. Rick Werme's example code is great, but I couldn't infer what
to do from it. I learned a lot from doing this, but apparently not quite
enough yet.
Anyone got a suggestion? Besides "Step away from the terminal Sir"! This
has been quite a good learning experience overall. I'm pleased with the
overall project to date.
Bruce Labitt
Autoliv Electronics
1011B Pawtucket Blvd, PO Box 1858
Lowell, MA 01853
Email: bruce.labitt at autoliv.com.
Tel: (978) 674-6526
Fax: (978) 674-6581
******************************
Neither the footer nor anything else in this E-mail is intended to or constitutes an <br>electronic signature and/or legally binding agreement in the absence of an <br>express statement or Autoliv policy and/or procedure to the contrary.<br>This E-mail and any attachments hereto are Autoliv property and may contain legally <br>privileged, confidential and/or proprietary information.<br>The recipient of this E-mail is prohibited from distributing, copying, forwarding or in any way <br>disseminating any material contained within this E-mail without prior written <br>permission from the author. If you receive this E-mail in error, please <br>immediately notify the author and delete this E-mail. Autoliv disclaims all <br>responsibility and liability for the consequences of any person who fails to <br>abide by the terms herein. <br>
******************************
More information about the Python-talk
mailing list