from wxPython.wx import * import os import sys if sys.platform=="darwin": import pyGlobus.ioc from AccessGrid.DataStoreClient import GetVenueDataStore from AccessGrid.Toolkit import CmdlineApplication class VenueFileBrowser(wxPanel): ''' wxPython UI panel for downloading/uploading venue data. ''' def __init__(self, parent, id): ''' Initiate the panel. ''' wxPanel.__init__(self, parent, id) # Initialize AG application app = CmdlineApplication() args = app.Initialize() # Create data store interface venueUrl = "https://localhost:8000/Venues/default" self.dataStoreClient = GetVenueDataStore(venueUrl) self.Populate() self.PopulateLocalList() self.PopulateRemoteList() 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. """ self.localFiles.Clear() files = os.listdir(os.getcwd()) self.localFiles.InsertItems(files, 0) def PopulateRemoteList(self): """ Insert files from remote directory into the list box. """ self.remoteFiles.Clear() # Get data from venue self.dataStoreClient.LoadData() # Get file names that matches a specific pattern files = self.dataStoreClient.QueryMatchingFiles("*") for r in files: print r self.remoteFiles.InsertItems(files, 0) def Download(self, event): """ Invoked when the download button is pressed. The selected file will get uploaded to the venue. """ fileName = self.remoteFiles.GetStringSelection() # Download a file from venue self.dataStoreClient.Download(fileName, fileName) self.PopulateLocalList() def Upload(self, event): """ Invoked when the upload button is pressed. The selected remote file will get downloaded to the local directory. """ fileName = self.localFiles.GetStringSelection() # Upload a file to venue self.dataStoreClient.Upload(fileName) self.PopulateRemoteList() 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()