Changeset 2a62d5c in sasview
- Timestamp:
- Apr 20, 2011 7:51:12 PM (14 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:
- 2657df9
- Parents:
- d4d78c9
- Location:
- guiframe
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_panel.py
r3b11d0d r2a62d5c 11 11 This module provides Graphic interface for the data_manager module. 12 12 """ 13 import os 13 14 import wx 14 15 import sys … … 19 20 from sans.guiframe.dataFitting import Data2D 20 21 from sans.guiframe.panel_base import PanelBase 22 from sans.guiframe.events import StatusEvent 23 from DataLoader.loader import Loader 24 25 try: 26 # Try to find a local config 27 import imp 28 path = os.getcwd() 29 if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ 30 (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): 31 fObj, path, descr = imp.find_module('local_config', [path]) 32 config = imp.load_module('local_config', fObj, path, descr) 33 else: 34 # Try simply importing local_config 35 import local_config as config 36 except: 37 # Didn't find local config, load the default 38 import config 39 40 extension_list = [] 41 if config.APPLICATION_STATE_EXTENSION is not None: 42 extension_list.append(config.APPLICATION_STATE_EXTENSION) 43 EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list 21 44 22 45 PANEL_WIDTH = 180 … … 72 95 PanelBase.__init__(self) 73 96 self.SetupScrolling() 97 self.loader = Loader() 98 #Default location 99 self._default_save_location = None 74 100 self.all_data1d = True 75 101 self.parent = parent … … 84 110 self.do_layout() 85 111 self.Bind(wx.EVT_SHOW, self.on_close_page) 112 self.enable_remove() 113 self.enable_import() 86 114 87 115 def do_layout(self): … … 108 136 self.sizer5 = wx.BoxSizer(wx.VERTICAL) 109 137 110 self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL,10)111 self.vbox.Add(self.sizer1, 0, wx.EXPAND|wx.ALL,0)112 self.vbox.Add(self.sizer2, 0, wx.EXPAND|wx.ALL,10)113 self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL,10)114 self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,10)138 self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL,1) 139 self.vbox.Add(self.sizer1, 0, wx.EXPAND|wx.ALL,0) 140 self.vbox.Add(self.sizer2, 0, wx.EXPAND|wx.ALL,1) 141 self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL,1) 142 self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5) 115 143 116 144 self.SetSizer(self.vbox) … … 235 263 Layout widgets related to buttons 236 264 """ 265 self.bt_add = wx.Button(self, wx.NewId(), "Load Data") 266 self.bt_add.SetToolTipString("Add data from the application") 267 wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data) 268 self.bt_remove = wx.Button(self, wx.NewId(), "Remove Data") 269 self.bt_remove.SetToolTipString("Remove data from the application") 270 wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) 237 271 self.bt_import = wx.Button(self, wx.NewId(), "Send To") 238 272 self.bt_import.SetToolTipString("Send set of Data to active perspective") … … 250 284 self.bt_freeze.SetToolTipString("To trigger freeze a theory") 251 285 wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze) 252 253 self.bt_remove = wx.Button(self, wx.NewId(), "Remove Data")254 self.bt_remove.SetToolTipString("Remove data from the application")255 wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove)256 286 257 287 self.tctrl_perspective = wx.StaticText(self, -1, … … 274 304 ix = 0 275 305 iy = 0 306 self.sizer3.Add(self.bt_add,( iy, ix),(1,1), 307 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 308 ix += 1 309 self.sizer3.Add(self.bt_remove,( iy, ix),(1,1), 310 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 311 ix = 0 312 iy += 1 276 313 self.sizer3.Add(self.bt_import,( iy, ix),(1,1), 277 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)314 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 278 315 ix += 1 279 316 self.sizer3.Add(self.tctrl_perspective,(iy, ix),(1,1), … … 282 319 iy += 1 283 320 self.sizer3.Add(self.bt_append_plot,( iy, ix),(1,1), 284 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)321 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 285 322 ix += 1 286 323 self.sizer3.Add(self.cb_plotpanel,(iy, ix),(1,1), … … 289 326 iy += 1 290 327 self.sizer3.Add(self.bt_plot,( iy, ix),(1,1), 291 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)328 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 292 329 ix = 0 293 330 iy += 1 294 331 self.sizer3.Add(self.bt_freeze,( iy, ix),(1,1), 295 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 296 ix = 0 297 iy += 1 298 self.sizer3.Add(self.bt_remove,( iy, ix),(1,1), 299 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 300 301 302 332 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 333 303 334 def layout_batch(self): 304 335 """ 305 336 """ 306 337 return 307 338 self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode', 308 339 style=wx.RB_GROUP) … … 386 417 """ 387 418 if not list: 419 self.enable_remove() 388 420 return 389 421 # uncheck previous items … … 439 471 process.__str__()) 440 472 self.append_theory(state_id, theory_list) 473 self.enable_remove() 441 474 442 475 def _uncheck_all(self): … … 598 631 del self.list_cb_theory[data_id] 599 632 633 def load_error(self, error=None): 634 """ 635 Pop up an error message. 636 637 :param error: details error message to be displayed 638 """ 639 message = "The data file you selected could not be loaded.\n" 640 message += "Make sure the content of your file" 641 message += " is properly formatted.\n\n" 642 643 if error is not None: 644 message += "When contacting the DANSE team, mention the" 645 message += " following:\n%s" % str(error) 646 dial = wx.MessageDialog(self.parent, message, 'Error Loading File', 647 wx.OK | wx.ICON_EXCLAMATION) 648 dial.ShowModal() 649 650 def _load_data(self, event): 651 """ 652 Load data 653 """ 654 path = None 655 if self._default_save_location == None: 656 self._default_save_location = os.getcwd() 657 658 cards = self.loader.get_wildcards() 659 wlist = '|'.join(cards) 660 style = wx.OPEN|wx.FD_MULTIPLE 661 dlg = wx.FileDialog(self.parent, 662 "Choose a file", 663 self._default_save_location, "", 664 wlist, 665 style=style) 666 if dlg.ShowModal() == wx.ID_OK: 667 file_list = dlg.GetPaths() 668 if len(file_list) >= 0 and not(file_list[0]is None): 669 self._default_save_location = os.path.dirname(file_list[0]) 670 path = self._default_save_location 671 dlg.Destroy() 672 673 if path is None or not file_list or file_list[0] is None: 674 return 675 self.get_data(file_list) 676 677 def get_data(self, path, format=None): 678 """ 679 """ 680 message = "" 681 log_msg = '' 682 output = {} 683 error_message = "" 684 for p_file in path: 685 basename = os.path.basename(p_file) 686 root, extension = os.path.splitext(basename) 687 if extension.lower() in EXTENSIONS: 688 log_msg = "Data Loader cannot " 689 log_msg += "load: %s\n" % str(p_file) 690 log_msg += "Try File opening ...." 691 logging.info(log_msg) 692 continue 693 694 try: 695 temp = self.loader.load(p_file, format) 696 if temp.__class__.__name__ == "list": 697 for item in temp: 698 data = self.parent.create_gui_data(item, p_file) 699 output[data.id] = data 700 else: 701 data = self.parent.create_gui_data(temp, p_file) 702 output[data.id] = data 703 message = "Loading Data..." + str(p_file) + "\n" 704 self.load_update(output=output, message=message) 705 except: 706 error_message = "Error while loading Data: %s\n" % str(p_file) 707 error_message += str(sys.exc_value) + "\n" 708 self.load_update(output=output, message=error_message) 709 710 message = "Loading Data Complete! " 711 message += log_msg 712 self.load_complete(output=output, error_message=error_message, 713 message=message, path=path) 714 715 def load_update(self, output=None, message=""): 716 """ 717 print update on the status bar 718 """ 719 if message != "" and self.parent is not None: 720 wx.PostEvent(self.parent, StatusEvent(status=message, 721 type="progress", 722 info="warning")) 723 724 def load_complete(self, output, message="", error_message="", path=None): 725 """ 726 post message to status bar and return list of data 727 """ 728 if self.parent is not None: 729 wx.PostEvent(self.parent, StatusEvent(status=message, 730 info="warning", 731 type="stop")) 732 if error_message != "": 733 self.load_error(error_message) 734 if self.parent is not None: 735 self.parent.add_data(data_list=output) 736 600 737 def on_remove(self, event): 601 738 """ … … 635 772 self.parent.remove_data(data_id=data_to_remove, 636 773 theory_id=theory_to_remove) 774 self.enable_remove() 637 775 638 776 def on_import(self, event=None): … … 690 828 #perspective_font.SetWeight(wx.BOLD) 691 829 self.tctrl_perspective.SetClientSize((80,20))#SetFont(perspective_font) 692 830 self.enable_import() 831 693 832 def set_panel_on_focus(self, name): 694 833 """ … … 716 855 panel = combo.GetClientData(selection) 717 856 self.parent.on_set_plot_focus(panel) 718 719 857 858 def enable_remove(self): 859 """ 860 enable or disable remove button 861 """ 862 n_t = self.tree_ctrl.GetCount() 863 n_t_t = self.tree_ctrl_theory.GetCount() 864 865 if n_t + n_t_t <= 0: 866 self.bt_remove.Disable() 867 else: 868 self.bt_remove.Enable() 869 870 def enable_import(self): 871 """ 872 enable or disable send button 873 """ 874 if self.tctrl_perspective.GetLabelText() == "No Active Application": 875 self.bt_import.Disable() 876 else: 877 self.bt_import.Enable() 720 878 721 879 -
guiframe/gui_manager.py
r3554fd39 r2a62d5c 1113 1113 self._mgr.DetachPane(panel) 1114 1114 panel.Destroy() 1115 del self.panels[ID] 1116 del self.plot_panels[ID] 1115 if ID in self.panels.keys(): 1116 del self.panels[ID] 1117 if ID in self.plot_panels.keys(): 1118 del self.plot_panels[ID] 1117 1119 if self._data_panel is not None: 1118 1120 ind = self._data_panel.cb_plotpanel.FindString(str(caption)) 1119 1121 if ind != wx.NOT_FOUND: 1120 1122 self._data_panel.cb_plotpanel.Delete(ind) 1121 1123 self._mgr.Update() 1122 1124 … … 2051 2053 self.panel_on_focus = panel 2052 2054 self.set_panel_on_focus(None) 2055 print " on_set_plot_focus" 2053 2056 2054 2057 def _onDrawIdle(self, *args, **kwargs):
Note: See TracChangeset
for help on using the changeset viewer.