Changeset 176fbf1 in sasview
- Timestamp:
- Dec 30, 2011 3:33:16 PM (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:
- c067d12
- Parents:
- 2365c0b
- Location:
- sansguiframe/src/sans/guiframe
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/src/sans/guiframe/data_panel.py
r31f3222b r176fbf1 364 364 wx.PostEvent(self.parent, 365 365 NewBatchEvent(enable=True)) 366 366 367 def _get_data_selection(self, event): 368 """ 369 Get data selection from the right click 370 """ 371 selection = event.GetSelection() 372 id, _, _ = self.FindFocus().GetSelection().GetData() 373 data_list, theory_list = \ 374 self.parent._data_manager.get_by_id(id_list=[id]) 375 if data_list: 376 data = data_list.values()[0] 377 else: 378 data = theory_list.values()[0][0] 379 return data 380 367 381 def on_edit_data(self, event): 368 382 """ 369 383 Pop Up Data Editor 370 384 """ 371 selection = event.GetSelection() 372 id, _, _ = self.tree_ctrl.GetSelection().GetData() 373 data_list, _= self.parent._data_manager.get_by_id(id_list=[id]) 374 375 data = data_list.values()[0] 385 data = self._get_data_selection(event) 376 386 from sans.guiframe.local_perspectives.plotting.masking \ 377 387 import MaskPanel as MaskDialog … … 380 390 #self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model) 381 391 panel.ShowModal() 392 393 def on_save_as(self, event): 394 """ 395 Save data as a file 396 """ 397 data = self._get_data_selection(event) 398 path = None 399 default_name = data.name 400 if default_name.count('.') > 0: 401 default_name = default_name.split('.')[0] 402 default_name += "_out" 403 if self.parent != None: 404 if issubclass(data.__class__, Data1D): 405 self.parent.save_data1d(data, default_name) 406 elif issubclass(data.__class__, Data2D): 407 self.parent.save_data2d(data, default_name) 408 else: 409 print "unable to save this type of data" 382 410 383 411 def layout_data_list(self): … … 389 417 self.tree_ctrl = DataTreeCtrl(parent=self, style=wx.SUNKEN_BORDER) 390 418 self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item) 391 self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_MENU, self.on_right_click )419 self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_MENU, self.on_right_click_data) 392 420 ## Create context menu for page 393 421 self.data_menu = wx.Menu() 394 422 id = wx.NewId() 423 name = "Save As" 424 msg = "Save Theory/Data as a file" 425 self.data_menu.Append(id, name, msg) 426 wx.EVT_MENU(self, id, self.on_save_as) 427 428 self.editmask_id = wx.NewId() 395 429 name = "Edit Mask" 396 msg = "Edit the currentData"397 self.data_menu.Append( id, name, msg)398 wx.EVT_MENU(self, id, self.on_edit_data)399 430 msg = "Edit Mask for the current 2D Data" 431 self.data_menu.Append(self.editmask_id, name, msg) 432 wx.EVT_MENU(self, self.editmask_id, self.on_edit_data) 433 400 434 tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory") 401 435 tree_ctrl_theory_label.SetForegroundColour('blue') … … 404 438 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, 405 439 self.on_check_item) 440 self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU, 441 self.on_right_click_theory) 406 442 self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10) 407 443 self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND|wx.ALL, 10) … … 409 445 self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10) 410 446 411 412 def on_right_click(self, event): 447 def on_right_click_theory(self, event): 448 """ 449 On click theory data 450 """ 451 if self.data_menu is not None: 452 self.data_menu.Enable(self.editmask_id, False) 453 self.PopupMenu(self.data_menu) 454 455 def on_right_click_data(self, event): 413 456 """ 414 457 Allow Editing Data 415 458 """ 416 459 selection = event.GetSelection() 417 _, data_class_name, _ = self.tree_ctrl.GetSelection().GetData() 418 if data_class_name == "Data2D" and self.data_menu is not None: 460 is_data = True 461 try: 462 id, data_class_name, _ = self.tree_ctrl.GetSelection().GetData() 463 data_list, _ = \ 464 self.parent._data_manager.get_by_id(id_list=[id]) 465 if not data_list: 466 is_data = False 467 except: 468 return 469 if self.data_menu is not None: 470 menu_enable = (data_class_name == "Data2D" and is_data) 471 self.data_menu.Enable(self.editmask_id, menu_enable) 419 472 self.PopupMenu(self.data_menu) 420 473 -
sansguiframe/src/sans/guiframe/gui_manager.py
re9f6979 r176fbf1 2433 2433 except: 2434 2434 pass 2435 2435 2436 def save_data1d(self, data, fname): 2437 """ 2438 Save data dialog 2439 """ 2440 default_name = fname 2441 wildcard = "Text files (*.txt)|*.txt|"\ 2442 "CanSAS 1D files(*.xml)|*.xml" 2443 path = None 2444 dlg = wx.FileDialog(self, "Choose a file", 2445 self._default_save_location, 2446 default_name, wildcard , wx.SAVE) 2447 2448 if dlg.ShowModal() == wx.ID_OK: 2449 path = dlg.GetPath() 2450 # ext_num = 0 for .txt, ext_num = 1 for .xml 2451 # This is MAC Fix 2452 ext_num = dlg.GetFilterIndex() 2453 if ext_num == 0: 2454 format = '.txt' 2455 else: 2456 format = '.xml' 2457 path = os.path.splitext(path)[0] + format 2458 mypath = os.path.basename(path) 2459 2460 #TODO: This is bad design. The DataLoader is designed 2461 #to recognize extensions. 2462 # It should be a simple matter of calling the . 2463 #save(file, data, '.xml') method 2464 # of the sans.dataloader.loader.Loader class. 2465 from sans.dataloader.loader import Loader 2466 #Instantiate a loader 2467 loader = Loader() 2468 format = ".txt" 2469 if os.path.splitext(mypath)[1].lower() == format: 2470 # Make sure the ext included in the file name 2471 # especially on MAC 2472 fName = os.path.splitext(path)[0] + format 2473 self._onsaveTXT(data, fName) 2474 format = ".xml" 2475 if os.path.splitext(mypath)[1].lower() == format: 2476 # Make sure the ext included in the file name 2477 # especially on MAC 2478 fName = os.path.splitext(path)[0] + format 2479 loader.save(fName, data, format) 2480 try: 2481 self._default_save_location = os.path.dirname(path) 2482 except: 2483 pass 2484 dlg.Destroy() 2485 2486 2487 def _onsaveTXT(self, data, path): 2488 """ 2489 Save file as txt 2490 :TODO: Refactor and remove this method. See TODO in _onSave. 2491 """ 2492 if not path == None: 2493 out = open(path, 'w') 2494 has_errors = True 2495 if data.dy == None or data.dy == []: 2496 has_errors = False 2497 # Sanity check 2498 if has_errors: 2499 try: 2500 if len(data.y) != len(data.dy): 2501 has_errors = False 2502 except: 2503 has_errors = False 2504 if has_errors: 2505 if data.dx != None and data.dx != []: 2506 out.write("<X> <Y> <dY> <dX>\n") 2507 else: 2508 out.write("<X> <Y> <dY>\n") 2509 else: 2510 out.write("<X> <Y>\n") 2511 2512 for i in range(len(data.x)): 2513 if has_errors: 2514 if data.dx != None and data.dx != []: 2515 out.write("%g %g %g %g\n" % (data.x[i], 2516 data.y[i], 2517 data.dy[i], 2518 data.dx[i])) 2519 else: 2520 out.write("%g %g %g\n" % (data.x[i], 2521 data.y[i], 2522 data.dy[i])) 2523 else: 2524 out.write("%g %g\n" % (data.x[i], 2525 data.y[i])) 2526 out.close() 2527 2528 def save_data2d(self, data, fname): 2529 """ 2530 Save data2d dialog 2531 """ 2532 default_name = fname 2533 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT" 2534 dlg = wx.FileDialog(self, "Choose a file", 2535 self._default_save_location, 2536 default_name, wildcard , wx.SAVE) 2537 2538 if dlg.ShowModal() == wx.ID_OK: 2539 path = dlg.GetPath() 2540 # ext_num = 0 for .txt, ext_num = 1 for .xml 2541 # This is MAC Fix 2542 ext_num = dlg.GetFilterIndex() 2543 if ext_num == 0: 2544 format = '.dat' 2545 else: 2546 format = '' 2547 path = os.path.splitext(path)[0] + format 2548 mypath = os.path.basename(path) 2549 2550 #TODO: This is bad design. The DataLoader is designed 2551 #to recognize extensions. 2552 # It should be a simple matter of calling the . 2553 #save(file, data, '.xml') method 2554 # of the DataLoader.loader.Loader class. 2555 from sans.dataloader.loader import Loader 2556 #Instantiate a loader 2557 loader = Loader() 2558 2559 format = ".dat" 2560 if os.path.splitext(mypath)[1].lower() == format: 2561 # Make sure the ext included in the file name 2562 # especially on MAC 2563 fileName = os.path.splitext(path)[0] + format 2564 loader.save(fileName, data, format) 2565 try: 2566 self._default_save_location = os.path.dirname(path) 2567 except: 2568 pass 2569 dlg.Destroy() 2570 2436 2571 def set_current_perspective(self, perspective): 2437 2572 """ -
sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter1D.py
r45b6bfb r176fbf1 608 608 #self.graph.render(self) 609 609 #self.subplot.figure.canvas.draw_idle() 610 611 612 613 def _onsaveTXT(self, path): 614 """ 615 Save file as txt 616 617 :TODO: Refactor and remove this method. See TODO in _onSave. 610 611 def _onSave(self, evt): 612 """ 613 Save a data set to a text file 614 615 :param evt: Menu event 618 616 619 617 """ 620 618 data = self.plots[self.graph.selected_plottable] 621 622 if not path == None: 623 out = open(path, 'w') 624 has_errors = True 625 if data.dy == None or data.dy == []: 626 has_errors = False 627 # Sanity check 628 if has_errors: 629 try: 630 if len(data.y) != len(data.dy): 631 has_errors = False 632 except: 633 has_errors = False 634 if has_errors: 635 if data.dx != None and data.dx != []: 636 out.write("<X> <Y> <dY> <dX>\n") 637 else: 638 out.write("<X> <Y> <dY>\n") 639 else: 640 out.write("<X> <Y>\n") 641 642 for i in range(len(data.x)): 643 if has_errors: 644 if data.dx != None and data.dx != []: 645 out.write("%g %g %g %g\n" % (data.x[i], 646 data.y[i], 647 data.dy[i], 648 data.dx[i])) 649 else: 650 out.write("%g %g %g\n" % (data.x[i], 651 data.y[i], 652 data.dy[i])) 653 else: 654 out.write("%g %g\n" % (data.x[i], 655 data.y[i])) 656 out.close() 657 try: 658 self._default_save_location = os.path.dirname(path) 659 self.parent._default_save_location = self._default_save_location 660 except: 661 pass 662 663 def _onSave(self, evt): 664 """ 665 Save a data set to a text file 666 667 :param evt: Menu event 668 669 """ 670 671 path = None 672 wildcard = "Text files (*.txt)|*.txt|"\ 673 "CanSAS 1D files(*.xml)|*.xml" 674 default_name = self.plots[self.graph.selected_plottable].label 619 default_name = data.label 675 620 if default_name.count('.') > 0: 676 621 default_name = default_name.split('.')[0] 677 622 default_name += "_out" 678 623 if self.parent != None: 679 self._default_save_location = self.parent._default_save_location 680 dlg = wx.FileDialog(self, "Choose a file", 681 self._default_save_location, 682 default_name, wildcard , wx.SAVE) 683 684 if dlg.ShowModal() == wx.ID_OK: 685 path = dlg.GetPath() 686 # ext_num = 0 for .txt, ext_num = 1 for .xml 687 # This is MAC Fix 688 ext_num = dlg.GetFilterIndex() 689 if ext_num == 0: 690 format = '.txt' 691 else: 692 format = '.xml' 693 path = os.path.splitext(path)[0] + format 694 mypath = os.path.basename(path) 695 696 #TODO: This is bad design. The DataLoader is designed 697 #to recognize extensions. 698 # It should be a simple matter of calling the . 699 #save(file, data, '.xml') method 700 # of the sans.dataloader.loader.Loader class. 701 from sans.dataloader.loader import Loader 702 #Instantiate a loader 703 loader = Loader() 704 data = self.plots[self.graph.selected_plottable] 705 format = ".txt" 706 if os.path.splitext(mypath)[1].lower() == format: 707 # Make sure the ext included in the file name 708 # especially on MAC 709 fName = os.path.splitext(path)[0] + format 710 self._onsaveTXT(fName) 711 format = ".xml" 712 if os.path.splitext(mypath)[1].lower() == format: 713 # Make sure the ext included in the file name 714 # especially on MAC 715 fName = os.path.splitext(path)[0] + format 716 loader.save(fName, data, format) 717 try: 718 self._default_save_location = os.path.dirname(path) 719 self.parent._default_save_location = self._default_save_location 720 except: 721 pass 722 dlg.Destroy() 624 self.parent.save_data1d(data, default_name) 723 625 724 626 def _add_more_tool(self): -
sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter2D.py
rb837e1f r176fbf1 757 757 default_name += "_out" 758 758 if id in self.action_ids: 759 760 759 path = None 761 wildcard = "IGOR/DAT 2D file in Q_map (*.dat)|*.DAT" 762 dlg = wx.FileDialog(self, "Choose a file", 763 self._default_save_location, 764 default_name, wildcard , wx.SAVE) 765 766 if dlg.ShowModal() == wx.ID_OK: 767 path = dlg.GetPath() 768 # ext_num = 0 for .txt, ext_num = 1 for .xml 769 # This is MAC Fix 770 ext_num = dlg.GetFilterIndex() 771 if ext_num == 0: 772 format = '.dat' 773 else: 774 format = '' 775 path = os.path.splitext(path)[0] + format 776 mypath = os.path.basename(path) 777 778 #TODO: This is bad design. The DataLoader is designed 779 #to recognize extensions. 780 # It should be a simple matter of calling the . 781 #save(file, data, '.xml') method 782 # of the DataLoader.loader.Loader class. 783 from sans.dataloader.loader import Loader 784 #Instantiate a loader 785 loader = Loader() 786 data = self.data2D 787 788 format = ".dat" 789 if os.path.splitext(mypath)[1].lower() == format: 790 # Make sure the ext included in the file name 791 # especially on MAC 792 fName = os.path.splitext(path)[0] + format 793 loader.save(fName, data, format) 794 try: 795 self._default_save_location = os.path.dirname(path) 796 self.parent._default_save_location = \ 797 self._default_save_location 798 except: 799 pass 800 dlg.Destroy() 760 self.parent.save_data2d(self.data2D, default_name) 761
Note: See TracChangeset
for help on using the changeset viewer.