def updateTree(self): """ Rebuilds the tree from the current state of the DataStore. """ self.tree.DeleteAllItems() self.root = self.tree.AddRoot("Project") self.tree.SetPyData(self.root, None) self.tree.SetItemImage(self.root, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(self.root, self.fldropenidx, wx.TreeItemIcon_Expanded) dataTree = self.tree.AppendItem(self.root, "Data Sets") self.tree.SetPyData(dataTree, DATA_SET_ITEM) self.tree.SetItemImage(dataTree, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(dataTree, self.fldropenidx, wx.TreeItemIcon_Expanded) figsTree = self.tree.AppendItem(self.root, "Figure Sets") self.tree.SetPyData(figsTree, FIGURE_SET_ITEM) self.tree.SetItemImage(figsTree, self.fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(figsTree, self.fldropenidx, wx.TreeItemIcon_Expanded) # create tree self.buildDataTree(dataTree, DataStore.getData(), []) self.buildFigureTree(figsTree, FigureStore.getFigures()) self.tree.Expand(self.root) if self.dataTreeExpanded: self.tree.Expand(dataTree) if self.figureTreeExpanded: self.tree.Expand(figsTree)
def OnLoadState(self, event): from data.io import loadState if len(DataStore.getData()) > 0: dlgWarn = wx.MessageDialog(self, 'This action may overwrite currently loaded datasets and/or plots.\n\nContinue anyway?', 'Warning', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING) if dlgWarn.ShowModal() == wx.ID_NO: dlgWarn.Destroy() return dlgWarn.Destroy() formats = "FIND Project File (*.find)|*.find" dlg = wx.FileDialog(self, "Select saved project", self.dirname, "", formats, wx.FD_OPEN) if dlg.ShowModal() == wx.ID_OK: try: loadState(dlg.Directory, dlg.Filename) except error.ProjectLoadingError: return # Load all Figures with Subplot instances from the stored dicts for fID in FigureStore.getFigures(): fig = FigureStore.get(fID) splots = [] for plot in fig.subplots: s = dv.Subplot() s.load(plot) s.parent = self.facsPlotPanel.figure splots.append(s) fig.subplots = splots currFigure = FigureStore.getSelectedFigure() self.facsPlotPanel.subplots = currFigure.subplots self.facsPlotPanel.SelectedSubplotIndex = currFigure.selectedSubplot self.facsPlotPanel.updateAxes(currFigure.axes, False) self.facsPlotPanel.updateSubplotGrid(currFigure.grid[0], currFigure.grid[1], True) self.chkLinked.Value = self.facsPlotPanel.CurrentSubplotLinked labels = DataStore.getCurrentDataSet().labels if DataStore.getCurrentDataSet() is not None else [] self.updateAxesList(labels, currFigure.axes) self.treeCtrlPanel.updateTree() self.statusbar.SetStatusText("Project loaded from %s" % dlg.Path, 0) dlg.Destroy()
def saveState(dir, filename): """ Save a representation of the system state: All the loaded data sets, their clusterings, any transformations or analyses (future), and all plots. The state is saved in JSON format based on a dict of the following form: data: list of IDs binfile: the filename of the binary file used to store all the actual data data-dID: dict of settings belonging to a FacsData instance clust-dID-cID: a dict of attributes belonging to a clustering figures: list of figureID strings fig-ID: A dict for each figure keyed on the ID. The subplot attribute here is replaced with a list of fig-ID-p-ID strings for locating subplot dicts fig-ID-p-ID: A dict for each subplot in each figure keyed on fig ID and plot ID. current-data: data ID current-figure: figure ID """ store = shelve.open(os.path.join(dir, filename)) #store = dbopen(os.path.join(dir, filename), 'c', format='csv') # The actual numeric data will be stored in a separate binary file using # the numpy savez() method allowing for efficient storage/retrieval of data binfile = '%s.npz' % filename bindata = {} store['data'] = DataStore.getData().keys() store['binfile'] = binfile for dID in DataStore.getData(): fdata = DataStore.get(dID) dStr = 'data-%i' % dID dfname = fdata.filename if (fdata.filename is not '') else binfile bindata[dStr] = fdata.data store[dStr] = {'filename': dfname, 'displayname': fdata.displayname, 'labels': fdata.labels, 'annotations': fdata.annotations, 'analysis': fdata.analysis, 'ID': fdata.ID, 'parent': fdata.parent, 'children': fdata.children, 'selDims': fdata.selDims, 'clustering': fdata.clustering.keys(), 'nodeExpanded': fdata.nodeExpanded, 'selectedClustering': fdata.selectedClustering} # clusterings for cID in fdata.clustering: cStr = 'clust-%i-%i' % (dID, cID) csett = {'method': fdata.methodIDs[cID], 'opts': fdata.clusteringOpts[cID], 'clusteringSelDims': fdata.clusteringSelDims[cID], 'infoExpanded': fdata.infoExpanded[cID]} store[cStr] = csett bindata[cStr] = fdata.clustering[cID] # figures sfigs = [] for figID in FigureStore.getFigures(): fig = FigureStore.get(figID) fStr = 'fig-%i' % figID d = dict(fig.__dict__) splots = packSubplots(store, figID, fig.subplots) d['subplots'] = splots store[fStr] = d sfigs.append(fStr) store['figures'] = list(sfigs) # other store['current-data'] = DataStore.getCurrentIndex() store['current-figure'] = FigureStore.getSelectedIndex() # write out settings data store.close() # write out numeric data to binary file np.savez(os.path.join(dir, binfile), **bindata)