【发布时间】:2010-10-18 23:32:46
【问题描述】:
我有一个非常简单的 GUI,它接受两个参数,然后调用其他三个名为 DigitalFilter()、BeatByBeatVariables() 和 GetSummaryOfWholeTest() 的类。这是我第一次编写类,我需要语法方面的帮助。
具体来说,你能帮我继承吗?我希望在应用程序启动时调用 GUI 的类 MainWindow(wx.Frame)。然后,当用户在 GUI 中单击 self.button 时,我希望应用程序首先运行 myFilter=DigitalFilter(TestID,FilterTimePeriod),然后第二次运行 myBeatByBeat = BeatByBeatVariables(arg1,arg2),最后第三次运行 myTestSummary = GetSummaryOfWholeTest( argA,argB)
请注意,myBeatByBeat 在 myFilter 创建完成之前无法开始运行,因为 myFilter 的实例化会创建作为 myBeatByBeat 输入所需的 csv 文件。同样,在 myBeatByBeat 创建完成之前,myTest Summary 无法开始运行,因为 myBeatByBeat 的实例化会创建 csv 文件,这些文件需要作为 myTestSummary 的输入。
谁能告诉我用适当的继承来编写/实例化这些类的正确语法,以便每个类的工作将按照尊重其输入/输出关系的顺序完成?
我假设这里应该使用继承,但我不知道应该从什么继承。我也不知道我是否没有看到为代码提供必要的相互关系所必需的其他概念。
下面是相关代码的概要:
class DigitalFilter():
def __init__(self,TestID,FilterTimePeriod):
# All the code for the digital filter goes here.
# I am omitting this class' code for simplicity.
class BeatByBeatVariables():
def __init__(self,arg1,arg2):
# I am omitting this class' code for simplicity
class GetSummaryOfWholeTest():
def __init__(self,argA,ArgB):
# This class' code is omitted for simplicity
class MainWindow(wx.Frame):
def __init__(self, parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY,title, size = (500,500), style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
# Create self.editname and self.edithear in code that I am omitting for simplicity
self.button =wx.Button(self, label="Click here to filter the data", pos=(200, 125))
self.Bind(wx.EVT_BUTTON, self.OnClick,self.button)
def OnClick(self,event):
FilterTimePeriod = self.editname.GetValue()
TestID = self.edithear.GetValue()
myFilter=DigitalFilter(TestID,FilterTimePeriod)
myBeatByBeat = BeatByBeatVariables(arg1,arg2)
myTestSummary = GetSummaryOfWholeTest(argA,argB)
app = wx.PySimpleApp()
frame = MainWindow(None,-1,"Filtering Software. Version 1.0")
app.MainLoop()
注意:我使用的是 Python 2.6,因为我也在使用 numpy 和 sciepy
【问题讨论】:
标签: user-interface oop class inheritance wxpython