Changeset dc79cfc in sasview for sansguiframe/src
- Timestamp:
- Sep 12, 2011 11:46:50 AM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 8aa5788
- Parents:
- 83eb1b52
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/src/sans/guiframe/gui_manager.py
r83eb1b52 rdc79cfc 294 294 time_str = time.strftime("%b %d %H;%M of %Y", t) 295 295 name = "Batch" + time_str 296 details = "File Generated by %s : %s .\n" % (APPLICATION_NAME,296 details = "File Generated by %s : %s" % (APPLICATION_NAME, 297 297 str(plugin_name)) 298 298 details += "on %s.\n" % time_str … … 314 314 self.batch_frame.Show(True) 315 315 316 def on_read_batch_tofile(self, event): 317 """ 318 Open a file dialog , extract the file to read and display values 319 into a grid 320 """ 321 path = None 322 if self._default_save_location == None: 323 self._default_save_location = os.getcwd() 324 325 dlg = wx.FileDialog(self, 326 "Choose a file", 327 self._default_save_location, "", 328 "(*.csv)|*.csv| Text Files (*.txt)|*.txt") 329 if dlg.ShowModal() == wx.ID_OK: 330 path = dlg.GetPath() 331 if path is not None: 332 self._default_save_location = os.path.dirname(path) 333 dlg.Destroy() 334 335 self.read_batch_tofile(file_name=path) 336 337 def read_batch_tofile(self, file_name): 338 """ 339 Extract value from file name and Display them into a grid 340 """ 341 if file_name is None or file_name.strip() == "": 342 return 343 data = {} 344 fd = open(file_name, 'r') 345 _, ext = os.path.splitext(file_name) 346 separator = "\t" 347 if ext.lower() == ".csv": 348 separator = "," 349 buffer = fd.read() 350 lines = buffer.split('\n') 351 column_names_line = "" 352 index = None 353 for index in range(len(lines)): 354 line = lines[index] 355 if line.find(separator) != -1: 356 #found the first line containing the label 357 column_names_line = line 358 first_data_index = index 359 break 360 if column_names_line.strip() == "" or index is None: 361 return 362 col_name_toks = column_names_line.split(separator) 363 c_index = 0 364 for col_index in range(len(col_name_toks)): 365 c_name = col_name_toks[col_index] 366 if c_name.strip() != "": 367 data[c_name] = [ lines[row].split(separator)[c_index] 368 for row in range(index + 1, len(lines)-1)] 369 c_index += 1 370 self.open_with_localapp(data=data) 371 316 372 def write_batch_tofile(self, data, file_name, details=""): 317 373 """ … … 329 385 separator = "," 330 386 fd.write(str(details)) 331 fd.write(separator)332 fd.write('\n')333 387 for col_name in data.keys(): 334 388 fd.write(str(col_name)) … … 1326 1380 wx.EVT_MENU(self, id, self._on_save_application) 1327 1381 self._file_menu.AppendSeparator() 1328 1382 self._file_menu.AppendSeparator() 1383 id = wx.NewId() 1384 hint = "Display content of the file into a grid" 1385 self._file_menu.Append(id, '&Open Batch Result', hint) 1386 wx.EVT_MENU(self, id, self.on_read_batch_tofile) 1387 self._file_menu.AppendSeparator() 1329 1388 id = wx.NewId() 1330 1389 self._file_menu.Append(id, '&Quit', 'Exit')
Note: See TracChangeset
for help on using the changeset viewer.