def on_click_save(self, event): """ Save change into a file """ if not self._data: return self.on_change_run(event=None) self.on_change_title(event=None) path = None wildcard = "CanSAS 1D files(*.xml)|*.xml" dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", wildcard , wx.SAVE) for data in self._data: if issubclass(data.__class__, Data2D): msg = "No conventional writing format for \n\n" msg += "Data2D at this time.\n" dlg = wx.MessageDialog(None, msg, 'Error Loading File', wx.OK | wx.ICON_EXCLAMATION) dlg.ShowModal() else: if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() mypath = os.path.basename(path) loader = Loader() format = ".xml" if os.path.splitext(mypath)[1].lower() == format: loader.save(path, data, format) try: self._default_save_location = os.path.dirname(path) except: pass dlg.Destroy() event.Skip()
def test_save_cansas_v1_0(self): filename = "isis_1_0_write_test.xml" xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) valid = xmlreader.validate_xml() self.assertTrue(valid) reader_generic = Loader() dataloader = reader_generic.load(self.isis_1_0) reader_cansas = Reader() cansasreader = reader_cansas.read(self.isis_1_0) for i in range(len(dataloader)): self._check_data(dataloader[i]) self._check_data(cansasreader[i]) reader_generic.save(filename, dataloader[i], None) reader2 = Reader() return_data = reader2.read(filename) written_data = return_data[0] xmlwrite = XMLreader(filename, self.schema_1_0) valid = xmlreader.validate_xml() self.assertTrue(valid) self._check_data(written_data)
def test_cansas_xml(self): filename = "isis_1_1_write_test.xml" xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) valid = xmlreader.validate_xml() xmlreader.set_processing_instructions() self.assertTrue(valid) fo = open(self.isis_1_1) str = fo.read() reader_generic = Loader() dataloader = reader_generic.load(self.isis_1_1) reader_cansas = Reader() cansasreader = reader_cansas.read(self.isis_1_1) for i in range(len(dataloader)): self._check_data(dataloader[i]) self._check_data_1_1(dataloader[i]) self._check_data(cansasreader[i]) self._check_data_1_1(cansasreader[i]) reader_generic.save(filename, dataloader[i], None) fo = open(filename) str = fo.read() reader2 = Loader() return_data = reader2.load(filename) written_data = return_data[0] self._check_data(written_data)