def __init__(self, parent, ID): wx.Panel.__init__(self, parent, ID) Registry.add("CONTACT", self) Result.addListener(self) self.grid = ContactGrid(self, -1) gridBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Contact List"), wx.HORIZONTAL) gridBox.Add(self.grid, 1, wx.GROW|wx.ALIGN_CENTER|wx.ALL, 3) self.physicalAddress = Address(self, "HOME_PHYSICAL", Colors.HOME) self.postalAddress = Address(self, "HOME_POSTAL", Colors.HOME) self.workPhysicalAddress = Address(self, "WORK_PHYSICAL", Colors.WORK) self.workPostalAdress = Address(self, "WORK_POSTAL", Colors.WORK) # register the widgets for later access self.addWidgets = {"HOME_PHYSICAL": self.physicalAddress, "HOME_POSTAL": self.postalAddress, "WORK_PHYSICAL": self.workPhysicalAddress, "WORK_POSTAL": self.workPostalAdress} agrid = wx.GridSizer(1, 2, 3, 3) agrid.AddMany([(self.physicalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3), (self.workPhysicalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3), (self.postalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3), (self.workPostalAdress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)]) #agrid.AddGrowableRow(0, 1) #agrid.AddGrowableRow(1, 1) #agrid.SetFlexibleDirection(wx.HORIZONTAL|wx.VERTICAL) # save saveBtn = wx.Button(self, wx.ID_SAVE) self.Bind(wx.EVT_BUTTON, self.__saveData, saveBtn) # new newBtn = wx.Button(self, wx.ID_NEW) self.Bind(wx.EVT_BUTTON, self.new, newBtn) btnBox = wx.BoxSizer(wx.HORIZONTAL) btnBox.Add(newBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3) btnBox.Add(saveBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(gridBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3) sizer.Add(agrid, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3) sizer.Add(btnBox, 0, wx.ALIGN_CENTER|wx.ALL, 3) self.SetSizer(sizer)
class ContactPanel(wx.Panel): """Contacts""" def __init__(self, parent, ID): wx.Panel.__init__(self, parent, ID) Registry.add("CONTACT", self) Result.addListener(self) self.grid = ContactGrid(self, -1) gridBox = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Contact List"), wx.HORIZONTAL) gridBox.Add(self.grid, 1, wx.GROW|wx.ALIGN_CENTER|wx.ALL, 3) self.physicalAddress = Address(self, "HOME_PHYSICAL", Colors.HOME) self.postalAddress = Address(self, "HOME_POSTAL", Colors.HOME) self.workPhysicalAddress = Address(self, "WORK_PHYSICAL", Colors.WORK) self.workPostalAdress = Address(self, "WORK_POSTAL", Colors.WORK) # register the widgets for later access self.addWidgets = {"HOME_PHYSICAL": self.physicalAddress, "HOME_POSTAL": self.postalAddress, "WORK_PHYSICAL": self.workPhysicalAddress, "WORK_POSTAL": self.workPostalAdress} agrid = wx.GridSizer(1, 2, 3, 3) agrid.AddMany([(self.physicalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3), (self.workPhysicalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3), (self.postalAddress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3), (self.workPostalAdress, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3)]) #agrid.AddGrowableRow(0, 1) #agrid.AddGrowableRow(1, 1) #agrid.SetFlexibleDirection(wx.HORIZONTAL|wx.VERTICAL) # save saveBtn = wx.Button(self, wx.ID_SAVE) self.Bind(wx.EVT_BUTTON, self.__saveData, saveBtn) # new newBtn = wx.Button(self, wx.ID_NEW) self.Bind(wx.EVT_BUTTON, self.new, newBtn) btnBox = wx.BoxSizer(wx.HORIZONTAL) btnBox.Add(newBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3) btnBox.Add(saveBtn, 0, wx.ALIGN_CENTER|wx.ALL, 3) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(gridBox, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3) sizer.Add(agrid, 1, wx.ALIGN_CENTER|wx.GROW|wx.ALL, 3) sizer.Add(btnBox, 0, wx.ALIGN_CENTER|wx.ALL, 3) self.SetSizer(sizer) def new(self, evt): """ new contact""" self.grid.addNewRow() def __saveData(self, evt): """ save the data""" # telephone numbers data = self.grid.getData() CONN.saveContacts(self.file_number, data) # addresses adata = [] for k, w in self.addWidgets.items(): lines = w.getLines().strip() code = w.getCode().strip() if lines or code: adata.append((k, lines, code)) CONN.saveAddress(self.file_number, adata) def reload(self, data=None): """ load data""" if data: self.file_number = data["file_number"] # contact numbers contacts = CONN.getContacts(self.file_number) self.grid.setData(contacts) # addresses for k, w in self.addWidgets.items(): w.setLines('') w.setCode('') addresses = CONN.getAddresses(self.file_number) print addresses for ad in addresses: desc = ad['description'] if self.addWidgets.has_key(desc): w = self.addWidgets[desc] w.setLines(ad["lines"]) w.setCode(ad["code"])