下面的代码很不完整。但我想检查一些东西是否有错误......事情是当我编译它时......它启动后没有任何反应。我在这里做错什么了吗?我还检查了任务管理器并在后台看到它,但 gui 从未弹出。
from wx import *
import Order as o
import OrderItem as oi
import Customer as c
import Item as i
class OrderMain ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Orders", pos = wx.DefaultPosition, size = wx.Size( 517,486 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.Size( -1,-1 ), wx.DefaultSize )
bSizer3 = wx.BoxSizer( wx.VERTICAL )
#create the order item here
self.ord = o.Order()
self.list = wx.ListCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LC_REPORT )
self.list.SetMinSize( wx.Size( 500,300 ) )
self.list.SetMaxSize( wx.Size( 1000,800 ) )
self.list.InsertColumn(0,"Order ID")
self.list.InsertColumn(1,"Customer ID")
self.list.InsertColumn(2,"Order Price")
self.list.InsertColumn(3,"Order Date")
self.list.Bind(EVT_LIST_ITEM_SELECTED,self.GetSelectedItems)
self.refresh_list(None)
bSizer3.Add( self.list, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
bSizer4 = wx.BoxSizer( wx.HORIZONTAL )
self.m_button20 = wx.Button( self, wx.ID_ANY, u"Add Order", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_button20.Bind(wx.EVT_BUTTON, self.add_entry)
bSizer4.Add( self.m_button20, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
self.m_button21 = wx.Button( self, wx.ID_ANY, u"Update Record", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_button21.Bind(wx.EVT_BUTTON, self.show_entry)
bSizer4.Add( self.m_button21, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
bSizer3.Add( bSizer4, 1, wx.EXPAND, 5 )
self.SetSizer( bSizer3 )
self.Layout()
self.Centre( wx.BOTH )
def refresh_list(self, event):
"""Place the names of each ItemEntry into the list"""
self.index = 0
self.entrydict = {}
self.list.DeleteAllItems()
for entry in self.ord.list_entries():
self.list.InsertStringItem(self.index,entry.Order_ID)
self.list.SetStringItem(self.index,1,entry.Cust_ID)
self.list.SetStringItem(self.index,2,str(entry.Order_Price))
self.list.SetStringItem(self.index,3,str(entry.Order_Date))
self.entrydict[self.index] = entry
self.index += 1
def GetSelectedItems(self, event):
""" Gets the selected items for the list control.
Selection is returned as a list of selected indices,
low to high.
"""
selection = []
self.index = self.list.GetFirstSelected()
selection.append(self.index)
while len(selection) != self.list.GetSelectedItemCount():
self.index = self.list.GetNextSelected(self.index)
selection.append(self.index)
return self.index
def add_entry(self, event):
"""Add a new entry to the Order_Date ite"""
# start out with blank, generic ItemEntry
entry = o.OrderEntry("","","0","")
self.endiag = OrderDetail(self,entry)
self.endiag.ShowModal()
self.ord.add_entry(entry.Order_ID,
entry.Cust_ID,
str(entry.Order_Price),
str(entry.Order_Date) )
self.refresh_list(None)
def show_entry(self, event):
"""updates the details of the currently selected entry"""
e_id = self.index
entry = self.ord.list_entries()[e_id]
self.endiag2 = OrderDetailU(self , entry)
self.endiag2.ShowModal()
self.refresh_list(None)
def __del__( self ):
pass
class OrderDetail ( wx.Dialog ):
def __init__( self, parent ,entry):
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Order Details", pos = wx.DefaultPosition, size = wx.Size( 500,500 ), style = wx.DEFAULT_DIALOG_STYLE )
self.SetSizeHintsSz( wx.Size( 500,500 ), wx.DefaultSize )
self.entry = entry
bSizer22 = wx.BoxSizer( wx.VERTICAL )
self.ordite = oi.OrderItem()
self.cust = c.Customer()
gSizer6 = wx.GridSizer( 2, 2, 0, 0 )
self.ordite=oi.OrderItem()
self.m_staticText28 = wx.StaticText( self, wx.ID_ANY, u"Order ID", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText28.Wrap( -1 )
gSizer6.Add( self.m_staticText28, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.Order_ID = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,TE_PROCESS_ENTER )
self.Order_ID.Bind(EVT_LIST_ITEM_SELECTED, self.setID)
self.Order_ID.SetMinSize( wx.Size( 200,-1 ) )
gSizer6.Add( self.Order_ID, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )
self.m_staticText29 = wx.StaticText( self, wx.ID_ANY, u"Customer", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText29.Wrap( -1 )
gSizer6.Add( self.m_staticText29, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
m_choice1Choices = self.cust.list_entries()
self.Cust_ID = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( 200,-1 ), m_choice1Choices, 0 )
self.Cust_ID.SetSelection( 0 )
gSizer6.Add( self.Cust_ID, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, u"Order Price", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText18.Wrap( -1 )
gSizer6.Add( self.m_staticText18, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )
self.computePrice()
self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, str(self.entry.Order_Price), wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText19.Wrap( -1 )
gSizer6.Add( self.m_staticText19, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )
self.m_staticText33 = wx.StaticText( self, wx.ID_ANY, u"Date", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText33.Wrap( -1 )
gSizer6.Add( self.m_staticText33, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )
self.Order_Date = wx.DatePickerCtrl( self, wx.ID_ANY, wx.DefaultDateTime, wx.DefaultPosition, wx.DefaultSize, wx.DP_DEFAULT )
gSizer6.Add( self.Order_Date, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
bSizer22.Add( gSizer6, 1, wx.EXPAND, 5 )
bSizer24 = wx.BoxSizer( wx.VERTICAL )
self.m_staticText32 = wx.StaticText( self, wx.ID_ANY, u"Items", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText32.Wrap( -1 )
bSizer24.Add( self.m_staticText32, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.list2 = wx.ListCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,100 ), wx.LC_REPORT|wx.LC_SORT_DESCENDING )
self.list2.InsertColumn(0,"Item ID")
self.list2.InsertColumn(1,"Item Price")
self.list2.InsertColumn(2,"Item Qty")
self.list2.Bind(EVT_LIST_ITEM_SELECTED,self.GetSelectedItems2)
self.refresh_list2(None)
bSizer24.Add( self.list2, 0, wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
gSizer7 = wx.GridSizer( 2, 2, 0, 0 )
self.m_button17 = wx.Button( self, wx.ID_ANY, u"Add Item", wx.DefaultPosition, wx.Size( 100,-1 ), 0 )
gSizer7.Add( self.m_button17, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.m_button18 = wx.Button( self, wx.ID_ANY, u"Delete Item", wx.DefaultPosition, wx.Size( 100,-1 ), 0 )
gSizer7.Add( self.m_button18, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
bSizer24.Add( gSizer7, 1, wx.EXPAND, 5 )
bSizer22.Add( bSizer24, 1, wx.EXPAND, 5 )
gSizer8 = wx.GridSizer( 2, 2, 0, 0 )
self.m_button19 = wx.Button( self, wx.ID_ANY, u"Ok", wx.DefaultPosition, wx.Size( 100,-1 ), 0 )
gSizer8.Add( self.m_button19, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.m_button20 = wx.Button( self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.Size( 100,-1 ), 0 )
gSizer8.Add( self.m_button20, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
bSizer22.Add( gSizer8, 1, wx.EXPAND, 5 )
self.SetSizer( bSizer22 )
self.Layout()
self.Centre( wx.BOTH )
def setID(self, event):
entry.Order_ID = str(self.Order_ID.GetValue())
return self.Order_ID
def closeDial(self,event):
"""Closes the Dialog"""
self.Destroy()
def ComputePrice(self,event):
for entry in self.ordite.list_entries():
if self.ordite.OrderItemEntry.Order_ID == self.entry.Order_ID:
self.entry.Order_Price = self.entry.Order_Price + self.ordite.OrderItemEntry.Item_Price
return self.entry.Order_Price
def refresh_list2(self, event):
"""Place the names of each ItemEntry into the list"""
self.index2 = 0
self.entrydict = {}
self.list2.DeleteAllItems()
for entry in self.ordite.list_entries():
if self.ordite.OrderItemEntry.Order_ID==self.entry.Order_ID:
self.list2.InsertStringItem(self.index,entry.Order_ID)
self.list2.SetStringItem(self.index,1,entry.Item_ID)
self.list2.SetStringItem(self.index,2,str(entry.Item_Price))
self.list2.SetStringItem(self.index,3,str(entry.Item_Qty))
self.entrydict[self.index2] = entry
self.index2 += 1
def GetSelectedItems2(self, event):
""" Gets the selected items for the list control.
Selection is returned as a list of selected indices,
low to high.
"""
selection2 = []
self.index2 = self.list2.GetFirstSelected()
selection.append(self.index2)
while len(selection2) != self.list2.GetSelectedItemCount():
self.index = self.list2.GetNextSelected(self.index2)
selection2.append(self.index2)
return self.index2
def add_item(self, event):
"""Add a new entry to the Order_Date ite"""
# start out with blank, generic Entry
entryit = oi.OrderItemEntry("","","","")
self.endiag = AddItemOrder(self,entryit)
self.endiag.ShowModal()
self.ordite.add_entry(entry.Order_ID,
entry.Cust_ID,
str(entry.Order_Price),
str(entry.Order_Date) )
self.refresh_list(None)
def ok(self, event):
"""sets the details of the current entry"""
self.entry.set_details( str(self.Order_ID.GetValue()),
str(self.Cust_ID.GetValue()),
str(self.Order_Price.GetValue()),
str(self.Order_Date) )
self.Destroy()
def __del__( self ):
pass
class AddItemOrder ( wx.Dialog ):
def __init__( self, parent,entryit ):
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Add Item", pos = wx.DefaultPosition, size = wx.Size( 285,173 ), style = wx.DEFAULT_DIALOG_STYLE )
self.entryit = entryit
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer25 = wx.BoxSizer( wx.VERTICAL )
gSizer9 = wx.GridSizer( 2, 2, 0, 0 )
self.m_staticText34 = wx.StaticText( self, wx.ID_ANY, u"Item ID", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText34.Wrap( -1 )
gSizer9.Add( self.m_staticText34, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )
m_choice2Choices = i.list_entries()
self.Item_ID = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_choice2Choices, 0 )
self.Item_ID.SetSelection( 0 )
gSizer9.Add( self.Item_ID, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.m_staticText35 = wx.StaticText( self, wx.ID_ANY, u"Item Qty", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText35.Wrap( -1 )
gSizer9.Add( self.m_staticText35, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )
self.Item_Qty = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 120,-1 ), 0 )
gSizer9.Add( self.Item_Qty, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )
bSizer25.Add( gSizer9, 1, wx.EXPAND, 5 )
self.m_button19 = wx.Button( self, wx.ID_ANY, u"Ok", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer25.Add( self.m_button19, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, 5 )
self.SetSizer( bSizer25 )
self.Layout()
self.Centre( wx.BOTH )
def __del__( self ):
pass
def main():
ex = wx.App()
OrderMain(None)
ex.MainLoop()
if __name__ == '__main__':
main()