All pastes #394307 Raw Edit

Miscellany

public python v1 · immutable
·published 2007-03-14 05:46 UTC
rendered paste body
#coding=utf-8import wxfrom Backend import Database,Customerclass ID:    """ An object that returns unique identifiers """    _ids = {}    _n_ids = 1        @staticmethod    def get_id(s_key):        if ID._ids.__contains__(s_key):            return ID._ids[s_key]        else:            ID._ids[s_key] = ID._n_ids            ID._n_ids += 1            return ID._ids[s_key]class MainFrame(wx.Frame):          """ The main frame of the GUI """    def __init__(self, control):        wx.Frame.__init__(self, None)        self.control = control        self.SetTitle("Wx Test")        self.CreateStatusBar()              self.MakeMenu()        self.splitter = wx.SplitterWindow(self, -1, style=wx.SP_BORDER)        self.splitter.SetMinimumPaneSize(50)                tree_panel = wx.Panel(self.splitter, -1)        tree_box = wx.BoxSizer(wx.VERTICAL)                sort_choices = ["Sort by first name", "Sort by last name"]        sort_combo = wx.ComboBox(tree_panel,ID.get_id("sort_combo"), choices=sort_choices, style=wx.CB_SORT|wx.CB_READONLY, value=sort_choices[0]) #, (0,0), (-1,-1), choices=sort_choices, style=wx.CB_READONLY|wx.CB_SORT)                tree_box.Add(sort_combo, 0, wx.EXPAND)                  self.tree = wx.ListCtrl(tree_panel, -1, style=wx.LC_REPORT) #wx.TreeCtrl(tree_panel, -1, wx.DefaultPosition, (-1,-1), wx.TR_HIDE_ROOT | wx.TR_NO_BUTTONS | wx.TR_NO_LINES)        tree_box.Add(self.tree, 1, wx.EXPAND)        self.tree.InsertColumn(0, "First Name")        self.tree.InsertColumn(1, "Last Name")        self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id=ID.get_id("id_string"))        #tree.SetColumnWidth(0, 70)        #tree.SetColumnWidth(1, 70)        #root = tree.AddRoot("Customers")                tree_panel.SetSizer(tree_box)               self.notebook = wx.Notebook(self.splitter, ID.get_id("notebook")) #,style=wx.NB_TOP)            self.splitter.SplitVertically(tree_panel, self.notebook)        self.Refresh()            #def MakeEntryLabel(self    def MakeCustomerPage(self, customer):        """ Displays a customer's information in the GUI """        scroll = wx.ScrolledWindow(self.notebook)        panel = wx.Panel(scroll, -1)        return scroll           def OnNewCustomer(self, event):        c = Customer(" ", " ")  #uninitialized customer        person = self.control.findCustomer( (" ", " ") )        if len(person) > 0:            dlg = wx.MessageDialog(self, "The customer already exists.", "Error", wx.OK|wx.ICON_ERROR)            dlg.ShowModal()            dlg.Destroy()        else:            self.control.store(c)            self.Refresh()    def OnDelCustomer(self, event):##        c = #customer selected, to be filled in##        person = self.control.findCustomer( (c["first_name"], c["last_name"]) )##        self.control.deleteCustomer(c)##        self.Refresh()        pass    def OnNewCar(self, customer):        pass    def OnDelCar(self, customer, licensePlate):        pass    def Refresh(self):        self.tree.DeleteAllItems()        ppl = self.control.findAllCustomers()        for i in range(len(ppl)):            person = ppl[i]            self.tree.InsertStringItem(i, person[0])            self.tree.SetStringItem(i, 1, person[1])            def MakeMenu(self):        filemenu = wx.Menu()        new_submenu = wx.Menu()        new_submenu.Append(ID.get_id("new_customer"), "Customer", "")        new_submenu.Append(ID.get_id("new_car"), "Vehicle", "")             filemenu.AppendMenu(ID.get_id("new"), "New ...", new_submenu)        del_submenu = wx.Menu()        del_submenu.Append(ID.get_id("del_customer"), "Customer", "")        del_submenu.Append(ID.get_id("del_car"), "Vehicle", "")          filemenu.AppendMenu(ID.get_id("del"), "Delete ...", new_submenu)                filemenu.Append(ID.get_id("quit"), "&Quit\tCtrl-Q", "Quit")                editmenu = wx.Menu()        editmenu.Append(ID.get_id("undo"), "&Undo\tCtrl+Z", "Undo")        editmenu.Append(ID.get_id("redo"), "&Redo\tCtrl+Shift+Z", "Redo")        editmenu.AppendSeparator()        editmenu.Append(ID.get_id("cut"), "&Cut\tCtrl+X", "Cut")        editmenu.Append(ID.get_id("copy"), "&Copy\tCtrl+C", "Copy")        editmenu.Append(ID.get_id("paste"), "&Paste\tCtrl+V", "Paste")                menubar = wx.MenuBar()        menubar.Append(filemenu, "&File")        menubar.Append(editmenu, "&Edit")        self.SetMenuBar(menubar)                self.Bind(wx.EVT_MENU, self.OnQuit, id=ID.get_id("quit"))               self.Bind(wx.EVT_MENU, self.OnNewCustomer, id=ID.get_id("new_customer"))        self.Bind(wx.EVT_MENU, self.OnDelCustomer, id=ID.get_id("del_customer"))        self.Bind(wx.EVT_MENU, self.OnNewCar, id=ID.get_id("new_customer"))        self.Bind(wx.EVT_MENU, self.OnDelCar, id=ID.get_id("del_customer"))    def OnSelChanged(self, event):        item = event.GetItem()        print item        self.display.SetLabel(self.tree.GetItemText(item))    def OnQuit(self, event):        self.Close()class Application(wx.App):    def __init__(self):        wx.App.__init__(self, 0)##        self.db = Database("records.db")##        self.frame = MainFrame(self)    def OnInit(self):        self.db = Database("records.db")        self.frame = MainFrame(self)        self.frame.Show(True)        self.SetTopWindow(self.frame)        return True    #the following are Controller fuctions    def addCar(self, c, car):        return self.db.addCar(c, car)    def delCar(self, c, plate):        return self.db.delCar(c, plate)    def store(self, c):        return self.db.store(c)    def deleteCustomer(self, c):        return self.db.delete(c)    def findCar(self, plate):        return self.db.findCar(plate)    def findCustomer(self, predTuple):   #predlist in from (firstName, lastName)        preds = (("first_name", predTuple[0]),("last_name", predTuple[1]))        return self.db.find(preds)    def findAllCustomers(self):        return self.db.find( () )    if __name__ == "__main__":                      Application().MainLoop()