我正在使用三个对话框(名称为:Box1,Box2和Box3),如下所示: -
基本计算是在Box1和Box2上进行的,如何在Box3上显示第三个对话框的计算总和?
@Rule
public final ExpectedException expectedException = ExpectedException.none();
@Test
public void testExceptionCause() throws Exception {
expectedException.expect(ExecutionException.class);
expectedException.expectCause(isA(CustomException.class));
throw new ExecutionException(new CustomException("My message!"));
}
正在Box1和Box2上执行简单算术,我希望结果的总和显示在第三个对话框上(Box3)
我该如何完成这项工作?
代码基于wxpython classic和python 2.7
答案 0 :(得分:1)
您需要通过 init 方法将从每个对话框收集的信息传递到下一个对话框。这是一个快速工作的例子
import wx
class Box1(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
size=wx.Size(500, 141), style=wx.DEFAULT_DIALOG_STYLE)
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer6 = wx.BoxSizer(wx.VERTICAL)
self.m_panel2 = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
bSizer8 = wx.BoxSizer(wx.HORIZONTAL)
bSizer42 = wx.BoxSizer(wx.VERTICAL)
self.m_staticText61 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item1", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText61.Wrap(-1)
bSizer42.Add(self.m_staticText61, 0, wx.ALL, 5)
self.m_staticText62 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item2", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText62.Wrap(-1)
bSizer42.Add(self.m_staticText62, 0, wx.ALL, 5)
bSizer8.Add(bSizer42, 0, wx.EXPAND, 5)
bSizer43 = wx.BoxSizer(wx.VERTICAL)
bSizer43.AddSpacer((80, 0), 1, wx.EXPAND, 5)
bSizer8.Add(bSizer43, 0, wx.EXPAND, 5)
bSizer11 = wx.BoxSizer(wx.VERTICAL)
self.item1 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"7.50", wx.DefaultPosition, wx.Size(-1, 20), 0)
bSizer11.Add(self.item1, 0, wx.ALL, 5)
self.item2 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"8.00", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer11.Add(self.item2, 0, wx.ALL, 5)
bSizer8.Add(bSizer11, 0, 0, 5)
self.m_panel2.SetSizer(bSizer8)
self.m_panel2.Layout()
bSizer8.Fit(self.m_panel2)
bSizer6.Add(self.m_panel2, 1, wx.EXPAND | wx.ALL, 5)
bSizer13 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText25 = wx.StaticText(self, wx.ID_ANY, u"Quatity:", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText25.Wrap(-1)
self.m_staticText25.SetFont(wx.Font(15, 70, 90, 92, False, wx.EmptyString))
bSizer13.Add(self.m_staticText25, 0, wx.ALL | wx.EXPAND, 5)
quantity_choiceChoices = [u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10"]
self.quantity_choice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, quantity_choiceChoices, 0)
self.quantity_choice.SetSelection(0)
bSizer13.Add(self.quantity_choice, 0, wx.ALL, 5)
self.ok_button = wx.Button(self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.ok_button, 1, wx.ALL | wx.EXPAND, 5)
self.cancel_button = wx.Button(self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.cancel_button, 1, wx.ALL, 5)
bSizer6.Add(bSizer13, 0, wx.EXPAND, 5)
self.SetSizer(bSizer6)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.cancelFunc)
self.ok_button.Bind(wx.EVT_BUTTON, self.okFunc)
self.cancel_button.Bind(wx.EVT_BUTTON, self.cancelFunc)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def cancelFunc(self, event):
self.Destroy()
def okFunc(self, event):
quatity_choice = int(self.quantity_choice.GetStringSelection())
price = 0
if self.item1.GetValue():
price = quatity_choice * 7.5
print price
if self.item2.GetValue():
price = quatity_choice * 8.0
print price
Box2(None, price).ShowModal()
class Box2(wx.Dialog):
def __init__(self, parent, price1):
self.price1 = price1
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
size=wx.Size(500, 141), style=wx.DEFAULT_DIALOG_STYLE)
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer6 = wx.BoxSizer(wx.VERTICAL)
self.m_panel2 = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL)
bSizer8 = wx.BoxSizer(wx.HORIZONTAL)
bSizer42 = wx.BoxSizer(wx.VERTICAL)
self.m_staticText61 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item3", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText61.Wrap(-1)
bSizer42.Add(self.m_staticText61, 0, wx.ALL, 5)
self.m_staticText62 = wx.StaticText(self.m_panel2, wx.ID_ANY, u"item4", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText62.Wrap(-1)
bSizer42.Add(self.m_staticText62, 0, wx.ALL, 5)
bSizer8.Add(bSizer42, 0, wx.EXPAND, 5)
bSizer43 = wx.BoxSizer(wx.VERTICAL)
bSizer43.AddSpacer((80, 0), 1, wx.EXPAND, 5)
bSizer8.Add(bSizer43, 0, wx.EXPAND, 5)
bSizer11 = wx.BoxSizer(wx.VERTICAL)
self.item3 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"1.50", wx.DefaultPosition, wx.Size(-1, 20), 0)
bSizer11.Add(self.item3, 0, wx.ALL, 5)
self.item4 = wx.RadioButton(self.m_panel2, wx.ID_ANY, u"2.00", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer11.Add(self.item4, 0, wx.ALL, 5)
bSizer8.Add(bSizer11, 0, 0, 5)
self.m_panel2.SetSizer(bSizer8)
self.m_panel2.Layout()
bSizer8.Fit(self.m_panel2)
bSizer6.Add(self.m_panel2, 1, wx.EXPAND | wx.ALL, 5)
bSizer13 = wx.BoxSizer(wx.HORIZONTAL)
self.m_staticText25 = wx.StaticText(self, wx.ID_ANY, u"Quatity:", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticText25.Wrap(-1)
self.m_staticText25.SetFont(wx.Font(15, 70, 90, 92, False, wx.EmptyString))
bSizer13.Add(self.m_staticText25, 0, wx.ALL | wx.EXPAND, 5)
add_quantity_choiceChoices = [u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"10"]
self.add_quantity_choice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
add_quantity_choiceChoices, 0)
self.add_quantity_choice.SetSelection(0)
bSizer13.Add(self.add_quantity_choice, 0, wx.ALL, 5)
self.ok_button = wx.Button(self, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.ok_button, 1, wx.ALL | wx.EXPAND, 5)
self.cancel_button = wx.Button(self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer13.Add(self.cancel_button, 1, wx.ALL, 5)
bSizer6.Add(bSizer13, 0, wx.EXPAND, 5)
self.SetSizer(bSizer6)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.cancelFunc)
self.ok_button.Bind(wx.EVT_BUTTON, self.okFunc)
self.cancel_button.Bind(wx.EVT_BUTTON, self.cancelFunc)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def cancelFunc(self, event):
self.Destroy()
def okFunc(self, event):
add_quatity_choice = int(self.add_quantity_choice.GetStringSelection())
add_price = 0
if self.item3.GetValue():
add_price = add_quatity_choice * 1.5
print add_price
if self.item4.GetValue():
add_price = add_quatity_choice * 2.0
print add_price
Box3(None, self.price1+add_price).ShowModal()
class Box3(wx.Dialog):
def __init__(self, parent, total):
self.total = total
wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
size=wx.Size(257, 165), style=wx.DEFAULT_DIALOG_STYLE)
self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)
bSizer13 = wx.BoxSizer(wx.VERTICAL)
self.totalText = wx.StaticText(self, wx.ID_ANY, u"Total is:", wx.DefaultPosition, wx.DefaultSize, 0)
self.totalText.Wrap(-1)
self.totalText.SetFont(wx.Font(20, 70, 90, 90, False, wx.EmptyString))
bSizer13.Add(self.totalText, 0, wx.ALL | wx.EXPAND, 5)
self.totalText1 = wx.StaticText(self, wx.ID_ANY, u"?", wx.DefaultPosition, wx.DefaultSize, 0)
self.totalText1.Wrap(-1)
self.totalText1.SetFont(wx.Font(20, 70, 90, 90, False, wx.EmptyString))
self.totalText1.SetLabel(str(total))
# How to I get the "price + add_price" printed above
bSizer13.Add(self.totalText1, 0, wx.ALL, 5)
self.SetSizer(bSizer13)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.Bind(wx.EVT_CLOSE, self.cancelFunc)
def __del__(self):
pass
# Virtual event handlers, overide them in your derived class
def cancelFunc(self, event):
self.Destroy()
app = wx.App(0)
Box1(None).Show()
app.MainLoop()