Changeset 4e9583c in sasview
- Timestamp:
- Jul 22, 2010 12:24:33 PM (15 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:
- cb463b4
- Parents:
- f5038c06
- Location:
- guiframe
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_loader.py
r3c44c66 r4e9583c 9 9 from load_thread import DataReader 10 10 11 from sans.guicomm.events import StatusEvent 12 from sans.guicomm.events import NewStoreDataEvent 13 from sans.guicomm.events import NewPlotEvent 14 11 from sans.guicomm.events import NewPlotEvent, StatusEvent 15 12 16 13 def enable_add_data(existing_panel, new_plot): … … 41 38 def choose_data_file(parent, location=None): 42 39 """ 43 return a list of file path to read44 40 """ 45 41 path = None … … 51 47 wlist = '|'.join(cards) 52 48 53 dlg = wx.FileDialog(parent, "Choose a file", location, "", wlist, 54 style=wx.OPEN|wx.MULTIPLE|wx.CHANGE_DIR) 55 if dlg.ShowModal() == wx.ID_OK: 56 path = dlg.GetPaths() 57 if path: 58 mypath = os.path.basename(path[0]) 59 dlg.Destroy() 60 61 return path 62 63 def choose_data_folder(parent, location=None): 64 """ 65 return a list of folder to read 66 """ 67 path = None 68 if location == None: 69 location = os.getcwd() 70 71 l = Loader() 72 cards = l.get_wildcards() 73 wlist = '|'.join(cards) 74 75 dlg = wx.DirDialog(parent, "Choose a directory", location, 76 style=wx.DD_DEFAULT_STYLE) 49 dlg = wx.FileDialog(parent, "Choose a file", location, "", wlist, wx.OPEN) 77 50 if dlg.ShowModal() == wx.ID_OK: 78 51 path = dlg.GetPath() … … 80 53 dlg.Destroy() 81 54 82 return [path]55 return path 83 56 84 57 def open_dialog_append_data(panel_name, data_name): … … 98 71 else: 99 72 return False 100 73 74 75 def load_ascii_1D(path): 76 """ 77 Load a 1D ascii file, with errors 78 """ 79 if path and os.path.isfile(path): 80 81 file_x = numpy.zeros(0) 82 file_y = numpy.zeros(0) 83 file_dy = numpy.zeros(0) 84 file_dx = numpy.zeros(0) 85 86 input_f = open(path,'r') 87 buff = input_f.read() 88 lines = buff.split('\n') 89 90 has_dy = False 91 has_dx = False 92 93 for line in lines: 94 try: 95 toks = line.split() 96 x = float(toks[0]) 97 y = float(toks[1]) 98 if len(toks)==3: 99 has_dy = True 100 errdy = float(toks[2]) 101 else: 102 errdy = 0.0 103 if len(toks) == 4: 104 has_dx = True 105 errdx = float(toks[3]) 106 else: 107 errdx = 0.0 108 file_x = numpy.append(file_x, x) 109 file_y = numpy.append(file_y, y) 110 file_dy = numpy.append(file_dy, dyerr) 111 file_dx = numpy.append(file_dx, dxerr) 112 except: 113 print "READ ERROR", line 114 115 if has_dy == False: 116 file_dy = None 117 if has_dx == False: 118 file_dx = None 119 120 return file_x, file_y, file_dy, file_dx 121 return None, None, None, None 101 122 102 123 def load_error(error=None): … … 121 142 wx.PostEvent(parent, StatusEvent(status="Load cancel..", info="warning", 122 143 type="stop")) 123 124 125 126 def read_data(parent, path):127 """128 Create a list of data to read129 """130 list = []131 if path is not None and len(path) > 0:132 for p in path:133 if os.path.isdir(p):134 list = [os.path.join(os.path.abspath(p), file) for file in os.listdir(p) ]135 136 if os.path.isfile(p):137 list.append(p)138 139 return plot_data(parent, numpy.array(list))140 141 def load_helper(parent , output, path):142 """143 """144 filename = os.path.basename(path)145 #print output.process146 if not output.__class__.__name__ == "list":147 ## Creating a Data2D with output148 if hasattr(output,'data'):149 msg = "Loading 2D data: %s "%output.filename150 wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop"))151 new_plot = Data2D(image=None, err_image=None)152 153 else:154 msg = "Loading 1D data: %s "%output.filename155 wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop"))156 new_plot = Data1D(x=[], y=[], dx=None, dy=None)157 158 new_plot.copy_from_datainfo(output)159 output.clone_without_data(clone=new_plot)160 161 ## data 's name162 if output.filename is None or output.filename == "":163 output.filename = str(filename)164 ## name of the data allow to differentiate data when plotted165 name = parse_name(name=output.filename, expression="_")166 if not name in parent.indice_load_data.keys():167 parent.indice_load_data[name] = 0168 else:169 ## create a copy of the loaded data170 parent.indice_load_data[name] += 1171 name = name +"[%i]"%parent.indice_load_data[name]172 173 new_plot.name = name174 ## allow to highlight data when plotted175 new_plot.interactive = True176 ## when 2 data have the same id override the 1 st plotted177 new_plot.id = name178 ##group_id specify on which panel to plot this data179 new_plot.group_id = name180 new_plot.is_data = True181 ##post data to plot182 title = output.filename183 if hasattr(new_plot,"title"):184 title = str(new_plot.title.lstrip().rstrip())185 if title == "":186 title = str(name)187 else:188 title = str(name)189 if hasattr(parent, "panel_on_focus") and not(parent.panel_on_focus is None):190 existing_panel = parent.panel_on_focus191 panel_name = existing_panel.window_caption192 data_name = new_plot.name193 if enable_add_data(existing_panel, new_plot):194 if open_dialog_append_data(panel_name, data_name):195 #add this plot the an existing panel196 new_plot.group_id = existing_panel.group_id197 return [(new_plot, path)]198 #wx.PostEvent(parent, NewStoreDataEvent(data=new_plot))199 200 ## the output of the loader is a list , some xml files contain more than one data201 else:202 i=1203 temp=[]204 for item in output:205 msg = "Loading 1D data: %s "%str(item.run[0])206 wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop"))207 try:208 dx = item.dx209 dxl = item.dxl210 dxw = item.dxw211 except:212 dx = None213 dxl = None214 dxw = None215 216 new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy)217 new_plot.copy_from_datainfo(item)218 item.clone_without_data(clone=new_plot)219 new_plot.dxl = dxl220 new_plot.dxw = dxw221 222 name = parse_name(name=str(item.run[0]), expression="_")223 if not name in parent.indice_load_data.keys():224 parent.indice_load_data[name] = 0225 else:226 ## create a copy of the loaded data227 228 #TODO: this is a very annoying feature. We should make this229 # an option. Excel doesn't do this. Why should we?230 # What is the requirement for this feature, and are the231 # counter arguments stronger? Is this feature developed232 # to please at least 80% of the users or a special few?233 parent.indice_load_data[name] += 1234 name = name + "(copy %i)"%parent.indice_load_data[name]235 236 new_plot.name = name237 new_plot.interactive = True238 new_plot.group_id = name239 new_plot.id = name240 new_plot.is_data = True241 242 if hasattr(item,"title"):243 title = item.title.lstrip().rstrip()244 if title == "":245 title = str(name)246 else:247 title = name248 if hasattr(parent, "panel_on_focus") and not(parent.panel_on_focus is None):249 existing_panel = parent.panel_on_focus250 panel_name = existing_panel.window_caption251 data_name = new_plot.name252 if enable_add_data(existing_panel, new_plot):253 if open_dialog_append_data(panel_name, data_name):254 #add this plot the an existing panel255 new_plot.group_id = existing_panel.group_id256 temp.append((new_plot, path))257 #wx.PostEvent(parent, NewStoreDataEvent(data=new_plot))258 i+=1259 return temp260 261 144 262 145 def plot_data(parent, path): … … 274 157 275 158 # Load data 276 msg = ""277 list_of_data = []278 for p in path:279 try:280 list_of_data.append((L.load(p), p))281 except:282 p_msg = "Loading... " + str(sys.exc_value)283 wx.PostEvent(parent, StatusEvent(status=p_msg, info="warning"))284 msg += (str(sys.exc_value)+"\n")285 if msg.lstrip().rstrip() != "":286 load_error(msg)287 288 #output = map(L.load, path)289 290 # Notify user if the loader completed the load but no data came out291 if len(list_of_data) == 0 or numpy.array(list_of_data).all() is None:292 load_error("The data file appears to be empty.")293 msg = "Loading complete: %s"%output.filename294 wx.PostEvent(parent, StatusEvent(status=msg, info="warning", type="stop"))295 return296 result =[]297 for output , path in list_of_data:298 result += load_helper(parent=parent, output=output, path=path)299 msg = "Loading complete: %s"%output.filename300 wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop"))301 return result302 303 304 def old_plot_data(parent, path):305 """306 Use the DataLoader loader to created data to plot.307 308 :param path: the path of the data to load309 310 """311 from sans.guicomm.events import NewPlotEvent, StatusEvent312 from DataLoader.loader import Loader313 314 # Instantiate a loader315 L = Loader()316 317 # Load data318 159 try: 319 160 output = L.load(path) 320 161 except: 321 raise 322 #load_error(sys.exc_value) 162 load_error(sys.exc_value) 323 163 return 324 164 … … 441 281 wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(title))) 442 282 i+=1 443 283 -
guiframe/data_manager.py
r3c44c66 r4e9583c 42 42 self.parent = parent 43 43 44 def get_data(self, data_list={}): 45 """ 46 return 47 """ 48 if not data_list: 49 return self.available_data.values() 50 for data, path in data_list: 51 if data.name not in self.available_data.keys(): 52 self.available_data[data.name] = (data, path) 53 return self.available_data.values() 54 44 55 def on_get_data(self, data_list, plot=False): 45 56 """ … … 53 64 for data, path in data_list: 54 65 if data.name not in self.available_data.keys(): 55 self.available_data[data.name] = data, path66 self.available_data[data.name] = (data, path) 56 67 if plot: 57 self.data_to_plot[data.name] = data, path68 self.data_to_plot[data.name] = (data, path) 58 69 59 70 return self.get_sorted_list() -
guiframe/gui_manager.py
r3c44c66 r4e9583c 41 41 # Didn't find local config, load the default 42 42 import config 43 44 import warnings 45 warnings.simplefilter("ignore") 46 import logging 47 48 from sans.guicomm.events import NewPlotEvent 49 from sans.guicomm.events import NewLoadedDataEvent 43 50 44 from sans.guicomm.events import EVT_STATUS 51 45 from sans.guicomm.events import EVT_NEW_PLOT,EVT_SLICER_PARS_UPDATE 52 46 from sans.guicomm.events import EVT_ADD_MANY_DATA 53 from sans.guicomm.events import StatusEvent 54 55 56 from data_manager import DataManager 57 from data_panel import DataFrame 47 import warnings 48 warnings.simplefilter("ignore") 49 50 import logging 58 51 59 52 def quit_guiframe(parent=None): … … 175 168 return self.perspective 176 169 177 def on_perspective(self, event =None):170 def on_perspective(self, event): 178 171 """ 179 172 Call back function for the perspective menu item. … … 233 226 ## Application manager 234 227 self.app_manager = None 235 ## data manager 236 self.data_manager = DataManager(parent=self) 237 ## panel to display available data 238 self.data_panel = DataFrame(parent=self, list=[]) 239 self.data_panel.set_manager(manager=self.data_manager) 240 self.data_panel.set_owner(owner=self) 228 241 229 ## Find plug-ins 242 230 # Modify this so that we can specify the directory to look into … … 526 514 self._mgr.RestoreMaximizedPane() 527 515 516 528 517 # Register for showing/hiding the panel 518 529 519 wx.EVT_MENU(self, ID, self._on_view) 530 520 … … 543 533 544 534 id = wx.NewId() 545 self.filemenu.Append(id, '&Load File', 'Load data file(s) into the application') 546 wx.EVT_MENU(self, id, self._on_open_file) 547 id = wx.NewId() 548 self.filemenu.Append(id, '&Load Folder', 'Load data folder into the application') 549 wx.EVT_MENU(self, id, self._on_open_folder) 550 551 self.filemenu.AppendSeparator() 552 id = wx.NewId() 553 self.filemenu.Append(id, '&Available Data', 'Data available in the application') 554 wx.EVT_MENU(self, id, self._on_display_data) 555 556 self.filemenu.AppendSeparator() 535 self.filemenu.Append(id, '&Load Data', 'Load data file into the application') 536 wx.EVT_MENU(self, id, self._on_open) 537 #self.filemenu.AppendSeparator() 538 557 539 id = wx.NewId() 558 540 self.filemenu.Append(id,'&Quit', 'Exit') … … 594 576 595 577 if n_perspectives>1: 596 list=[]597 578 p_menu = wx.Menu() 598 579 for plug in self.plugins: … … 601 582 p_menu.Append(id, plug.sub_menu, "Switch to %s perspective" % plug.sub_menu) 602 583 wx.EVT_MENU(self, id, plug.on_perspective) 603 list.append(plug)604 584 menubar.Append(p_menu, '&Perspective') 605 self.data_panel.layout_perspective(list_of_perspective=list)585 606 586 # Tools menu 607 587 # Go through plug-ins and find tools to populate the tools menu … … 717 697 718 698 self._mgr.Update() 719 720 def _on_display_data(self, event): 721 """ 722 """ 723 self.data_panel.Show(True) 724 725 def _on_open_file(self, event): 699 700 def _on_open(self, event): 726 701 """ 727 702 """ 728 703 path = self.choose_file() 729 if path is None or path[0] is None:704 if path is None: 730 705 return 731 706 732 from data_loader import read_data 733 if os.path.isfile(path[0]): 734 data = read_data(self, path) 735 data = self.data_manager.on_get_data(data_list=data) 736 self.data_panel.load_list(list=data) 737 self.data_panel.Show(True) 738 739 def _on_open_folder(self, event): 740 """ 741 """ 742 path = self.choose_file(folder=True) 743 msg = "Loading .... " 744 event = StatusEvent(status=msg, info="info", type="progress") 745 self._on_status_event( evt=event) 746 if path is None or path[0] is None: 747 msg = "Loading stopped.... " 748 event = StatusEvent(status=msg, info="info", type="stop") 749 self._on_status_event( evt=event) 750 return 751 from data_loader import read_data 752 if os.path.isdir(path[0]): 753 data = read_data(self, path) 754 data = self.data_manager.on_get_data(data_list=data) 755 self.data_panel.load_list(list=data) 756 self.data_panel.Show(True) 757 758 def post_data(self, list_of_data, perspective=None,plot=False): 759 """ 760 Receive a list of data from data_manager to send to a current 761 active perspective. if plot is True sends the list of data to plotting 762 perspective 763 """ 764 if perspective is not None: 765 for plug in self.plugins: 766 if len(plug.get_perspective()) > 0: 767 id = wx.NewId() 768 if plug.sub_menu == perspective: 769 plug.on_perspective(event=None) 770 if plot: 771 wx.PostEvent(self, NewLoadedDataEvent(plots=list_of_data)) 772 return 773 if self.defaultPanel is not None and \ 774 self._mgr.GetPane(self.panels["default"].window_name).IsShown(): 775 self.on_close_welcome_panel() 776 777 for item in self.panels: 778 if self._mgr.GetPane(self.panels[item].window_name).IsShown(): 779 self.panels[item].set_data(list=list_of_data) 780 707 from data_loader import plot_data 708 if path and os.path.isfile(path): 709 plot_data(self, path) 710 781 711 def _onClose(self, event): 782 712 """ … … 807 737 except: 808 738 pass 809 if self.data_panel is not None or not self.data_panel.IsBeingDeleted(): 810 self.data_panel.Destroy() 739 811 740 import sys 812 741 wx.Exit() … … 819 748 flag = quit_guiframe(parent=self) 820 749 if flag: 821 if self.data_panel is not None or not self.data_panel.IsBeingDeleted():822 self.data_panel.Destroy()823 750 import sys 824 751 wx.Frame.Close(self) … … 876 803 dialog = aboutbox.DialogAbout(None, -1, "") 877 804 dialog.ShowModal() 878 805 806 def _onreloaFile(self, event): 807 """ 808 load a data previously opened 809 """ 810 from data_loader import plot_data 811 for item in self.filePathList: 812 id, menuitem_name , path, title = item 813 if id == event.GetId(): 814 if path and os.path.isfile(path): 815 plot_data(self, path) 816 break 817 879 818 def set_manager(self, manager): 880 819 """ … … 925 864 if not self._mgr.GetPane(self.panels[item].window_name).IsShown(): 926 865 self._mgr.GetPane(self.panels[item].window_name).Show() 927 list_of_data = self.data_manager.get_selected_data()928 self.panels[item].set_data(list=list_of_data)929 866 else: 930 867 if self._mgr.GetPane(self.panels[item].window_name).IsShown(): … … 932 869 933 870 self._mgr.Update() 934 935 if self.data_panel is not None: 936 for plug in self.plugins: 937 if len(plug.get_perspective()) > 0: 938 for panel in plug.get_perspective(): 939 if panel in panels: 940 self.data_panel.set_perspective(plug.sub_menu) 941 break 942 943 def choose_file(self, path=None, folder=False): 871 872 def choose_file(self, path=None): 944 873 """ 945 874 Functionality that belongs elsewhere 946 875 Should add a hook to specify the preferred file type/extension. 947 876 """ 877 #TODO: clean this up 878 from data_loader import choose_data_file 879 948 880 # Choose a file path 949 if path is None: 950 if folder: 951 from data_loader import choose_data_folder 952 path = choose_data_folder(self, self._default_save_location) 953 else: 954 from data_loader import choose_data_file 955 path = choose_data_file(self, self._default_save_location) 956 957 if path is not None: 881 if path==None: 882 path = choose_data_file(self, self._default_save_location) 883 884 if not path==None: 958 885 try: 959 self._default_save_location = os.path.dirname(path[0]) 886 self._default_save_location = os.path.dirname(path) 887 888 #self.n_fileOpen += 1 889 if self.n_fileOpen==1: 890 pos= self.filemenu.GetMenuItemCount()-1 891 #self.filemenu.InsertSeparator(pos ) 892 893 id = wx.NewId() 894 filename= os.path.basename(path) 895 dir= os.path.split(self._default_save_location)[1] 896 title= str(os.path.join(dir,filename )) 897 menuitem_name = str(self.n_fileOpen)+". "+ title 898 position= self.filemenu.GetMenuItemCount()-2 899 #self.filemenu.Insert(id=id, pos= position,text=menuitem_name,help=str(path) ) 900 #self.filePathList.append(( id, menuitem_name, path, title)) 901 #wx.EVT_MENU(self, id, self._onreloaFile) 902 903 ## construct menu item for open file 904 if self.n_fileOpen == self.n_maxfileopen +1: 905 ## reach the maximun number of path to store 906 self.n_fileOpen = 0 907 id, menuitem_name , path, title = self.filePathList[0] 908 self.filemenu.Delete(id) 909 self.filePathList.pop(0) 910 for item in self.filePathList: 911 id, menuitem_name , path, title = item 912 self.n_fileOpen += 1 913 label = str(self.n_fileOpen)+". "+ title 914 #self.filemenu.FindItemById(id).SetItemLabel(label) 960 915 except: 961 pass 916 raise 917 #pass 962 918 return path 963 919 920 def load_ascii_1D(self, path): 921 """ 922 """ 923 from data_loader import load_ascii_1D 924 return load_ascii_1D(path) 925 964 926 class DefaultPanel(wx.Panel): 965 927 """ -
guiframe/local_perspectives/plotting/plotting.py
rcb19af9f r4e9583c 15 15 import sys 16 16 from sans.guicomm.events import EVT_NEW_PLOT 17 from sans.guicomm.events import NewPlotEvent18 from sans.guicomm.events import EVT_NEW_LOADED_DATA19 17 from sans.guicomm.events import StatusEvent 20 18 21 19 22 class PlottingDialog(wx.Dialog):23 """24 Dialog to display plotting option25 """26 def __init__(self, parent=None, panel_on_focus=None, list_of_data=[]):27 """28 """29 wx.Dialog.__init__(self, parent=parent,title="Plotting", size=(300, 280))30 self.parent = parent31 self.panel_on_focus = panel_on_focus32 self.list_of_data = list_of_data33 self.define_structure()34 self.layout_plot_on_panel(list_of_data=self.list_of_data)35 self.layout_data_name(list_of_data=self.list_of_data)36 self.layout_button()37 38 def define_structure(self):39 """40 """41 #Dialog interface42 vbox = wx.BoxSizer(wx.VERTICAL)43 self.sizer_data = wx.BoxSizer(wx.HORIZONTAL)44 45 self.sizer_selection = wx.BoxSizer(wx.VERTICAL)46 self.sizer_button = wx.BoxSizer(wx.HORIZONTAL)47 vbox.Add(self.sizer_data)48 vbox.Add(self.sizer_selection)49 vbox.Add(self.sizer_button)50 self.SetSizer(vbox)51 self.Centre()52 53 def layout_button(self):54 """55 """56 self.bt_ok = wx.Button(self, wx.NewId(), "Ok", (30, 10))57 self.bt_ok.SetToolTipString("plot data")58 wx.EVT_BUTTON(self, self.bt_ok.GetId(), self.on_ok)59 60 self.sizer_button.AddMany([((40,40), 0,61 wx.LEFT|wx.ADJUST_MINSIZE, 100 ),62 (self.bt_ok, 0, wx.ALL,10)])63 64 def layout_data_name(self, list_of_data=[]):65 """66 """67 self.data_tcl = wx.TextCtrl(self, -1,size=(260,80), style=wx.TE_MULTILINE)68 hint_data = "Data to plot."69 self.data_tcl.SetToolTipString(hint_data)70 self.data_tcl.SetEditable(False)71 for item in list_of_data:72 self.data_tcl.AppendText(item.name+"\n")73 74 self.sizer_data.AddMany([(self.data_tcl, 1, wx.ALL, 10)])75 76 def layout_plot_on_panel(self, list_of_data=[]):77 """78 """79 if len(list_of_data) == 0:80 return81 elif len(list_of_data) ==1:82 self.layout_single_data(list_of_data=list_of_data)83 else:84 self.layout_multiple(list_of_data=list_of_data)85 86 def layout_single_data(self, list_of_data=[]):87 """88 """89 self.sizer_selection.Clear(True)90 if self.panel_on_focus is None and list_of_data < 1:91 return92 else:93 name = "Plot data on new panel"94 self.rb_single_data_panel = wx.RadioButton(self, -1,name,95 style=wx.RB_GROUP)96 msg = "Each data will be plotted separately on a new panel"97 self.rb_single_data_panel.SetToolTipString(msg)98 self.rb_single_data_panel.SetValue(True)99 self.Bind(wx.EVT_RADIOBUTTON, self.on_choose_panel,100 id=self.rb_single_data_panel.GetId())101 self.rb_panel_on_focus = wx.RadioButton(self, -1,"No Panel on Focus")102 msg = "All Data will be appended to panel on focus"103 self.rb_panel_on_focus.SetToolTipString(msg)104 self.rb_panel_on_focus.Disable()105 self.Bind(wx.EVT_RADIOBUTTON, self.on_choose_panel,106 id=self.rb_panel_on_focus.GetId())107 if self.panel_on_focus is not None:108 self.rb_panel_on_focus.Enable()109 self.rb_panel_on_focus.SetLabel(str(panel.window_name))110 self.sizer_selection.AddMany([(self.rb_single_data_panel,111 1, wx.ALL, 10),112 (self.rb_panel_on_focus,1, wx.ALL, 10)])113 114 def layout_multiple(self, list_of_data=[]):115 """116 """117 self.sizer_selection.Clear(True)118 if self.panel_on_focus is None and list_of_data <= 1:119 return120 name = "Plot each data separately"121 self.rb_single_data_panel = wx.RadioButton(self, -1,name,122 style=wx.RB_GROUP)123 msg = "Each data will be plotted separately on a new panel"124 self.rb_single_data_panel.SetToolTipString(msg)125 self.rb_single_data_panel.SetValue(True)126 self.Bind(wx.EVT_RADIOBUTTON, self.on_choose_panel,127 id=self.rb_single_data_panel.GetId())128 name = "Append all to new panel"129 self.rb_new_panel = wx.RadioButton(self, -1,name)130 msg = "All Data will be appended to a new panel"131 self.rb_new_panel.SetToolTipString(msg)132 self.Bind(wx.EVT_RADIOBUTTON, self.on_choose_panel,133 id=self.rb_new_panel.GetId())134 self.rb_panel_on_focus = wx.RadioButton(self, -1,"No Panel on Focus")135 msg = "All Data will be appended to panel on focus"136 self.rb_panel_on_focus.SetToolTipString(msg)137 self.rb_panel_on_focus.Disable()138 self.Bind(wx.EVT_RADIOBUTTON, self.on_choose_panel,139 id=self.rb_panel_on_focus.GetId())140 if self.panel_on_focus is not None:141 self.rb_panel_on_focus.Enable()142 self.rb_panel_on_focus.SetLabel(str(panel.window_name))143 144 self.sizer_selection.AddMany([(self.rb_single_data_panel,145 1, wx.LEFT|wx.RIGHT|wx.BOTTOM, 10),146 (self.rb_new_panel, 1, wx.LEFT|wx.RIGHT|wx.BOTTOM, 10),147 (self.rb_panel_on_focus, 1, wx.LEFT|wx.RIGHT|wx.BOTTOM, 10),])148 def on_ok(self, event):149 """150 """151 def on_choose_panel(self, event):152 """153 """154 20 class Plugin: 155 21 """ … … 196 62 self.parent = parent 197 63 # Connect to plotting events 198 self.parent.Bind(EVT_NEW_LOADED_DATA, self._on_plot)199 64 self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event) 200 65 # We have no initial panels for this plug-in … … 227 92 pass 228 93 229 def _on_plot(self, event): 230 """ 231 check the contains of event. 232 if it is a list of data to plot plot each one at the time 233 """ 234 list_of_data1d = [] 235 if hasattr(event, "plots"): 236 for plot, path in event.plots: 237 print "plotting _on_plot" 238 if plot.__class__.__name__ == "Data2D": 239 wx.PostEvent(self.parent, 240 NewPlotEvent(plot=plot, title=plot.name)) 241 else: 242 list_of_data1d.append((plot, path)) 243 wx.PostEvent(self.parent, 244 NewPlotEvent(plot=plot, title=plot.name)) 245 94 246 95 def _on_plot_event(self, event): 247 96 """ … … 329 178 return 330 179 331 class Data(object):332 def __init__(self, name):333 self.name = str(name)334 class MyApp(wx.App):335 def OnInit(self):336 wx.InitAllImageHandlers()337 list =[Data(name="Data1D")]#,338 # Data(name="Data2D"),Data(name="Data3D")]339 dialog = PlottingDialog(list_of_data=list)340 if dialog.ShowModal() == wx.ID_OK:341 pass342 dialog.Destroy()343 344 return 1345 346 # end of class MyApp347 348 if __name__ == "__main__":349 app = MyApp(0)350 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.