from wxPython.wx import * import os class VenueFileBrowser(wxPanel): ''' wxPython UI panel for downloading/uploading venue data. ''' def __init__(self, parent, id): ''' Initiate the panel. ''' wxPanel.__init__(self, parent, id) self.Populate() self.PopulateLocalList() def Populate(self): ''' Create all UI components. ''' sizer = wxBoxSizer(wxHORIZONTAL) self.localFiles = wxListBox(self, -1) self.remoteFiles = wxListBox(self, -1) buttonSizer = wxBoxSizer(wxVERTICAL) self.uploadButton = wxButton(self, wxNewId(), ">>") self.downloadButton = wxButton(self, wxNewId(), "<<") buttonSizer.Add(self.uploadButton, 0, wxBOTTOM, 5) buttonSizer.Add(self.downloadButton) sizer.Add(self.localFiles, 1, wxEXPAND | wxALL, 5) sizer.Add(buttonSizer, 0, wxCENTER| wxALL, 5) sizer.Add(self.remoteFiles, 1, wxEXPAND | wxALL, 5) self.SetSizer(sizer) self.SetAutoLayout(1) self.Layout() EVT_BUTTON(self, self.uploadButton.GetId(), self.Upload) EVT_BUTTON(self, self.downloadButton.GetId(), self.Download) def PopulateLocalList(self): """ Insert files from local directory into the list box. """ files = os.listdir(os.getcwd()) self.localFiles.InsertItems(files, 0) def Download(self, event): """ Invoked when the download button is pressed. The selected file will get uploaded to the venue. """ print 'download', self.remoteFiles.GetStringSelection() def Upload(self, event): """ Invoked when the upload button is pressed. The selected remote file will get downloaded to the local directory. """ print 'upload', self.localFiles.GetStringSelection() if __name__ == "__main__": # Create the wxPython application wxapp = wxPySimpleApp() wxInitAllImageHandlers() # Create the main frame frame = wxFrame(None, -1, "Venue File Browser") # Create the group chat panel chat = VenueFileBrowser(frame, -1) frame.Show() # Start the UI main thread wxapp.MainLoop()