Changeset 3c44c66 in sasview


Ignore:
Timestamp:
Jul 20, 2010 12:36:35 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
cb19af9f
Parents:
1b17a64
Message:

working on guiframe

Files:
3 added
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • guicomm/events.py

    rd2f1595 r3c44c66  
    11import wx.lib.newevent 
     2#send  data to data manager 
     3(NewStoreDataEvent, EVT_NEW_STORE_DATA) = wx.lib.newevent.NewEvent() 
     4# send data to other perspectives 
     5(NewLoadedDataEvent, EVT_NEW_LOADED_DATA) = wx.lib.newevent.NewEvent() 
    26# plot data 
    37(NewPlotEvent, EVT_NEW_PLOT) = wx.lib.newevent.NewEvent() 
  • guiframe/data_loader.py

    rd955bf19 r3c44c66  
    99from load_thread import DataReader 
    1010 
    11 from sans.guicomm.events import NewPlotEvent, StatusEvent 
     11from sans.guicomm.events import StatusEvent 
     12from sans.guicomm.events import  NewStoreDataEvent 
     13from sans.guicomm.events import NewPlotEvent 
     14 
    1215 
    1316def enable_add_data(existing_panel, new_plot): 
     
    3841def choose_data_file(parent, location=None): 
    3942    """ 
     43    return a list of file path to read 
    4044    """ 
    4145    path = None 
     
    4751    wlist = '|'.join(cards) 
    4852     
    49     dlg = wx.FileDialog(parent, "Choose a file", location, "", wlist, wx.OPEN) 
     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 
     63def 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) 
    5077    if dlg.ShowModal() == wx.ID_OK: 
    5178        path = dlg.GetPath() 
     
    5380    dlg.Destroy() 
    5481     
    55     return path 
     82    return [path] 
    5683 
    5784def open_dialog_append_data(panel_name, data_name): 
     
    7198    else: 
    7299        return False 
    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 
     100 
    122101 
    123102def load_error(error=None): 
     
    143122                                                type="stop")) 
    144123     
    145 def plot_data(parent, path): 
    146     """ 
    147     Use the DataLoader loader to created data to plot. 
    148      
    149     :param path: the path of the data to load 
    150      
    151     """ 
    152     from sans.guicomm.events import NewPlotEvent, StatusEvent 
    153     from DataLoader.loader import  Loader 
    154     
    155     # Instantiate a loader  
    156     L = Loader() 
    157      
    158     # Load data  
    159     try: 
    160         output = L.load(path) 
    161     except: 
    162         load_error(sys.exc_value) 
    163         return 
    164      
    165     # Notify user if the loader completed the load but no data came out 
    166     if output == None: 
    167         load_error("The data file appears to be empty.") 
    168         return 
    169    
    170       
     124 
     125 
     126def read_data(parent, path): 
     127    """ 
     128    Create a list of data to read 
     129    """ 
     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     
     141def load_helper(parent , output, path): 
     142    """ 
     143    """ 
    171144    filename = os.path.basename(path) 
    172      
     145    #print output.process 
    173146    if not  output.__class__.__name__ == "list": 
    174147        ## Creating a Data2D with output 
    175148        if hasattr(output,'data'): 
    176             msg = "Loading 2D data: %s"%output.filename 
     149            msg = "Loading 2D data: %s "%output.filename 
    177150            wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 
    178151            new_plot = Data2D(image=None, err_image=None) 
    179152       
    180153        else: 
    181             msg = "Loading 1D data: %s"%output.filename 
     154            msg = "Loading 1D data: %s "%output.filename 
    182155            wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 
    183156            new_plot = Data1D(x=[], y=[], dx=None, dy=None) 
     
    222195                        #add this plot the an existing panel 
    223196                        new_plot.group_id = existing_panel.group_id 
    224         wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=title)) 
     197        return [(new_plot, path)] 
     198        #wx.PostEvent(parent, NewStoreDataEvent(data=new_plot)) 
    225199         
    226200    ## the output of the loader is a list , some xml files contain more than one data 
    227201    else: 
    228202        i=1 
     203        temp=[] 
    229204        for item in output: 
    230             msg = "Loading 1D data: %s"%str(item.run[0]) 
     205            msg = "Loading 1D data: %s "%str(item.run[0]) 
    231206            wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 
    232207            try: 
     
    279254                        #add this plot the an existing panel 
    280255                        new_plot.group_id = existing_panel.group_id 
     256            temp.append((new_plot, path)) 
     257            #wx.PostEvent(parent, NewStoreDataEvent(data=new_plot)) 
     258            i+=1 
     259        return temp 
     260     
     261     
     262def plot_data(parent, path): 
     263    """ 
     264    Use the DataLoader loader to created data to plot. 
     265     
     266    :param path: the path of the data to load 
     267     
     268    """ 
     269    from sans.guicomm.events import NewPlotEvent, StatusEvent 
     270    from DataLoader.loader import  Loader 
     271    
     272    # Instantiate a loader  
     273    L = Loader() 
     274     
     275    # 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 out 
     291    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.filename 
     294        wx.PostEvent(parent, StatusEvent(status=msg, info="warning", type="stop")) 
     295        return 
     296    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.filename 
     300    wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 
     301    return result 
     302     
     303     
     304def 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 load 
     309     
     310    """ 
     311    from sans.guicomm.events import NewPlotEvent, StatusEvent 
     312    from DataLoader.loader import  Loader 
     313    
     314    # Instantiate a loader  
     315    L = Loader() 
     316     
     317    # Load data  
     318    try: 
     319        output = L.load(path) 
     320    except: 
     321        raise 
     322        #load_error(sys.exc_value) 
     323        return 
     324     
     325    # Notify user if the loader completed the load but no data came out 
     326    if output == None: 
     327        load_error("The data file appears to be empty.") 
     328        return 
     329   
     330      
     331    filename = os.path.basename(path) 
     332     
     333    if not  output.__class__.__name__ == "list": 
     334        ## Creating a Data2D with output 
     335        if hasattr(output,'data'): 
     336            msg = "Loading 2D data: %s"%output.filename 
     337            wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 
     338            new_plot = Data2D(image=None, err_image=None) 
     339       
     340        else: 
     341            msg = "Loading 1D data: %s"%output.filename 
     342            wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 
     343            new_plot = Data1D(x=[], y=[], dx=None, dy=None) 
     344             
     345        new_plot.copy_from_datainfo(output)  
     346        output.clone_without_data(clone=new_plot)       
     347       
     348        ## data 's name 
     349        if output.filename is None or output.filename == "": 
     350            output.filename = str(filename) 
     351        ## name of the data allow to differentiate data when plotted 
     352        name = parse_name(name=output.filename, expression="_") 
     353        if not name in parent.indice_load_data.keys(): 
     354            parent.indice_load_data[name] = 0 
     355        else: 
     356            ## create a copy of the loaded data 
     357            parent.indice_load_data[name] += 1 
     358            name = name +"[%i]"%parent.indice_load_data[name] 
     359        
     360        new_plot.name = name 
     361        ## allow to highlight data when plotted 
     362        new_plot.interactive = True 
     363        ## when 2 data have the same id override the 1 st plotted 
     364        new_plot.id = name 
     365        ##group_id specify on which panel to plot this data 
     366        new_plot.group_id = name 
     367        new_plot.is_data = True 
     368        ##post data to plot 
     369        title = output.filename 
     370        if hasattr(new_plot,"title"): 
     371            title = str(new_plot.title.lstrip().rstrip()) 
     372            if title == "": 
     373                title = str(name) 
     374        else: 
     375            title = str(name) 
     376        if hasattr(parent, "panel_on_focus") and not(parent.panel_on_focus is None): 
     377                existing_panel  = parent.panel_on_focus 
     378                panel_name = existing_panel.window_caption 
     379                data_name = new_plot.name 
     380                if enable_add_data(existing_panel, new_plot): 
     381                    if open_dialog_append_data(panel_name, data_name): 
     382                        #add this plot the an existing panel 
     383                        new_plot.group_id = existing_panel.group_id 
     384        wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=title)) 
     385         
     386    ## the output of the loader is a list , some xml files contain more than one data 
     387    else: 
     388        i=1 
     389        for item in output: 
     390            msg = "Loading 1D data: %s"%str(item.run[0]) 
     391            wx.PostEvent(parent, StatusEvent(status=msg, info="info", type="stop")) 
     392            try: 
     393                dx = item.dx 
     394                dxl = item.dxl 
     395                dxw = item.dxw 
     396            except: 
     397                dx = None 
     398                dxl = None 
     399                dxw = None 
     400 
     401            new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy) 
     402            new_plot.copy_from_datainfo(item) 
     403            item.clone_without_data(clone=new_plot) 
     404            new_plot.dxl = dxl 
     405            new_plot.dxw = dxw 
     406            
     407            name = parse_name(name=str(item.run[0]), expression="_") 
     408            if not name in parent.indice_load_data.keys(): 
     409                parent.indice_load_data[name] = 0 
     410            else: 
     411                ## create a copy of the loaded data 
     412                 
     413                #TODO: this is a very annoying feature. We should make this 
     414                # an option. Excel doesn't do this. Why should we? 
     415                # What is the requirement for this feature, and are the 
     416                # counter arguments stronger? Is this feature developed 
     417                # to please at least 80% of the users or a special few? 
     418                parent.indice_load_data[name] += 1 
     419                name = name + "(copy %i)"%parent.indice_load_data[name] 
     420                 
     421            new_plot.name = name 
     422            new_plot.interactive = True 
     423            new_plot.group_id = name 
     424            new_plot.id = name 
     425            new_plot.is_data = True 
     426         
     427            if hasattr(item,"title"): 
     428                title = item.title.lstrip().rstrip() 
     429                if title == "": 
     430                    title = str(name) 
     431            else: 
     432                title = name 
     433            if hasattr(parent, "panel_on_focus") and not(parent.panel_on_focus is None): 
     434                existing_panel  = parent.panel_on_focus 
     435                panel_name = existing_panel.window_caption 
     436                data_name = new_plot.name 
     437                if enable_add_data(existing_panel, new_plot): 
     438                    if open_dialog_append_data(panel_name, data_name): 
     439                        #add this plot the an existing panel 
     440                        new_plot.group_id = existing_panel.group_id 
    281441            wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(title))) 
    282442            i+=1 
    283           
     443   
  • guiframe/gui_manager.py

    rd955bf19 r3c44c66  
    4141    # Didn't find local config, load the default  
    4242    import config 
    43      
     43  
     44import warnings 
     45warnings.simplefilter("ignore") 
     46import logging   
     47  
     48from sans.guicomm.events import NewPlotEvent 
     49from sans.guicomm.events import NewLoadedDataEvent 
    4450from sans.guicomm.events import EVT_STATUS 
    4551from sans.guicomm.events import EVT_NEW_PLOT,EVT_SLICER_PARS_UPDATE 
    4652from sans.guicomm.events import EVT_ADD_MANY_DATA 
    47 import warnings 
    48 warnings.simplefilter("ignore") 
    49  
    50 import logging 
     53from sans.guicomm.events import StatusEvent 
     54 
     55 
     56from data_manager import DataManager 
     57from data_panel import DataFrame 
    5158 
    5259def quit_guiframe(parent=None): 
     
    168175        return self.perspective 
    169176     
    170     def on_perspective(self, event): 
     177    def on_perspective(self, event=None): 
    171178        """ 
    172179        Call back function for the perspective menu item. 
     
    226233        ## Application manager 
    227234        self.app_manager = None 
    228          
     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) 
    229241        ## Find plug-ins 
    230242        # Modify this so that we can specify the directory to look into 
     
    514526        self._mgr.RestoreMaximizedPane() 
    515527         
    516          
    517528        # Register for showing/hiding the panel 
    518          
    519529        wx.EVT_MENU(self, ID, self._on_view) 
    520530         
     
    533543         
    534544        id = wx.NewId() 
    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          
     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() 
    539557        id = wx.NewId() 
    540558        self.filemenu.Append(id,'&Quit', 'Exit')  
     
    576594         
    577595        if n_perspectives>1: 
     596            list=[] 
    578597            p_menu = wx.Menu() 
    579598            for plug in self.plugins: 
     
    582601                    p_menu.Append(id, plug.sub_menu, "Switch to %s perspective" % plug.sub_menu) 
    583602                    wx.EVT_MENU(self, id, plug.on_perspective) 
     603                    list.append(plug) 
    584604            menubar.Append(p_menu,   '&Perspective') 
    585   
     605        self.data_panel.layout_perspective(list_of_perspective=list) 
    586606        # Tools menu 
    587607        # Go through plug-ins and find tools to populate the tools menu 
     
    697717         
    698718            self._mgr.Update() 
    699     
    700     def _on_open(self, event): 
     719        
     720    def _on_display_data(self, event): 
     721        """ 
     722        """ 
     723        self.data_panel.Show(True) 
     724         
     725    def _on_open_file(self, event): 
    701726        """ 
    702727        """ 
    703728        path = self.choose_file() 
    704         if path is None: 
     729        if path is None or path[0] is None: 
    705730            return 
    706731         
    707         from data_loader import plot_data 
    708         if path and os.path.isfile(path): 
    709             plot_data(self, path) 
    710             
     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     
    711781    def _onClose(self, event): 
    712782        """ 
     
    737807        except: 
    738808            pass 
    739          
     809        if self.data_panel is not None or not self.data_panel.IsBeingDeleted(): 
     810            self.data_panel.Destroy() 
    740811        import sys 
    741812        wx.Exit() 
     
    748819        flag = quit_guiframe(parent=self) 
    749820        if flag: 
     821            if self.data_panel is not None or not self.data_panel.IsBeingDeleted(): 
     822                self.data_panel.Destroy() 
    750823            import sys 
    751824            wx.Frame.Close(self) 
     
    803876            dialog = aboutbox.DialogAbout(None, -1, "") 
    804877            dialog.ShowModal()             
    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              
     878         
    818879    def set_manager(self, manager): 
    819880        """ 
     
    864925                if not self._mgr.GetPane(self.panels[item].window_name).IsShown(): 
    865926                    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) 
    866929            else: 
    867930                if self._mgr.GetPane(self.panels[item].window_name).IsShown(): 
     
    869932     
    870933        self._mgr.Update() 
    871          
    872     def choose_file(self, path=None): 
     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): 
    873944        """  
    874945        Functionality that belongs elsewhere 
    875946        Should add a hook to specify the preferred file type/extension. 
    876947        """ 
    877         #TODO: clean this up 
    878         from data_loader import choose_data_file 
    879          
    880948        # Choose a file path 
    881         if path==None: 
    882             path = choose_data_file(self, self._default_save_location) 
    883              
    884         if not path==None: 
     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: 
    885958            try: 
    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)    
     959                self._default_save_location = os.path.dirname(path[0]) 
    915960            except: 
    916                 raise 
    917                 #pass 
     961                pass 
    918962        return path 
    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                    
     963  
    926964class DefaultPanel(wx.Panel): 
    927965    """ 
  • guiframe/local_perspectives/plotting/Plotter1D.py

    rd955bf19 r3c44c66  
    8181        self.graph.render(self) 
    8282    
     83    def set_data(self, list=[]): 
     84        """ 
     85        """ 
     86        pass 
     87     
     88     
    8389    def _reset(self): 
    8490        """ 
  • guiframe/local_perspectives/plotting/plotting.py

    rd955bf19 r3c44c66  
    1515import sys 
    1616from sans.guicomm.events import EVT_NEW_PLOT 
     17from sans.guicomm.events import NewPlotEvent 
     18from sans.guicomm.events import EVT_NEW_LOADED_DATA 
    1719from sans.guicomm.events import StatusEvent  
    1820 
    1921 
     22class PlottingDialog(wx.Dialog): 
     23    """ 
     24    Dialog to display plotting option 
     25    """ 
     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 = parent 
     31        self.panel_on_focus = panel_on_focus 
     32        self.list_of_data = list_of_data 
     33        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 interface 
     42        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            return 
     81        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            return  
     92        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            return  
     120        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        """ 
    20154class Plugin: 
    21155    """ 
     
    62196        self.parent = parent 
    63197        # Connect to plotting events 
     198        self.parent.Bind(EVT_NEW_LOADED_DATA, self._on_plot) 
    64199        self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event) 
    65200        # We have no initial panels for this plug-in 
     
    92227        pass 
    93228     
    94      
     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   
    95244    def _on_plot_event(self, event): 
    96245        """ 
     
    178327        return 
    179328         
     329class Data(object):  
     330    def __init__(self, name): 
     331        self.name = str(name) 
     332class MyApp(wx.App): 
     333    def OnInit(self): 
     334        wx.InitAllImageHandlers() 
     335        list =[Data(name="Data1D")]#, 
     336                                   # Data(name="Data2D"),Data(name="Data3D")] 
     337        dialog = PlottingDialog(list_of_data=list) 
     338        if dialog.ShowModal() == wx.ID_OK: 
     339            pass 
     340        dialog.Destroy() 
     341         
     342        return 1 
     343   
     344# end of class MyApp 
     345 
     346if __name__ == "__main__": 
     347    app = MyApp(0) 
     348    app.MainLoop()       
  • invariantview/perspectives/invariant/invariant_panel.py

    r4e1c362 r3c44c66  
    113113        return flag 
    114114     
    115     def set_data(self, data): 
     115    def set_data(self, list=[], state=None): 
     116        """ 
     117        Receive  a list of data from gui_manager to compute invariant 
     118        """ 
     119        if list==[]: 
     120            msg = "Please select data for Invariant perspective.\n" 
     121            dial = wx.MessageDialog(None, msg, 'Error Loading File',  
     122                                    wx.OK | wx.ICON_EXCLAMATION) 
     123            dial.ShowModal()  
     124            return 
     125        elif len(list) == 1: 
     126            data, filepath = list[0] 
     127            if data.__class__.__name__ == "Data2D": 
     128                msg = "Invariant cannot be computed for Data2D.\n" 
     129                msg += "Please load another file.\n" 
     130                dial = wx.MessageDialog(None, msg, 'Error Loading File',  
     131                                        wx.OK | wx.ICON_EXCLAMATION) 
     132                dial.ShowModal()  
     133            else: 
     134                 self.set_current_data(data=data) 
     135        else: 
     136            msg = " Invariant cannot be computed for more than one data.\n" 
     137            msg += "Please load only file.\n" 
     138            dial = wx.MessageDialog(None, msg, 'Error Loading File',  
     139                                    wx.OK | wx.ICON_EXCLAMATION) 
     140            dial.ShowModal()  
     141     
     142    def set_current_data(self, data): 
    116143        """ 
    117144        Set the data 
    118145         
    119         : return: True/False; if False, it will not set_data 
     146        : return: True/False; if False, it will not set_current_data 
    120147        """ 
    121148        # warn the users 
     
    178205            self.state = IState() 
    179206        else: 
    180             if not self.set_data(data): 
     207            if not self.set_current_data(data): 
    181208                return 
    182209            self.new_state = True 
     
    826853    def _reset_state_list(self,data=None): 
    827854        """ 
    828         Reset the state_list just before data was loading: Used in 'set_data()' 
     855        Reset the state_list just before data was loading: Used in 'set_current_data()' 
    829856        """ 
    830857        #if data == None: return 
     
    17031730 
    17041731        data.name = data.filename 
    1705         self.panel.set_data(data) 
     1732        self.panel.set_current_data(data) 
    17061733        self.Centre() 
    17071734        self.Show(True) 
  • prview/perspectives/pr/inversion_panel.py

    r1b17a64 r3c44c66  
    297297        """ 
    298298        if list==[]: 
     299            msg = "Please select data for Pr perspective.\n" 
     300            dial = wx.MessageDialog(None, msg, 'Error Loading File',  
     301                                    wx.OK | wx.ICON_EXCLAMATION) 
     302            dial.ShowModal()  
    299303            return 
    300304        elif len(list) == 1: 
  • sansview/perspectives/fitting/basepage.py

    re3d1423 r3c44c66  
    4444        #Set window's font size  
    4545        self.SetWindowVariant(variant=FONT_VARIANT) 
     46        
    4647        ## parent of the page 
    4748        self.parent = parent 
     
    160161        ## layout 
    161162        self.set_layout() 
    162         
     163         
    163164    class ModelTextCtrl(wx.TextCtrl): 
    164165        """ 
     
    233234        def _silent_kill_focus(self,event): 
    234235            """ 
    235             do nothing to kill focus 
     236            Save the state of the page 
    236237            """ 
     238             
    237239            event.Skip() 
    238240            pass 
     
    803805        self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 
    804806        self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 
    805      
    806  
     807        #save chisqr 
     808        self.state.tcChi = self.tcChi.GetValue() 
     809         
    807810    def save_current_state_fit(self): 
    808811        """ 
     
    10081011        ## draw the model with previous parameters value 
    10091012        self._onparamEnter_helper() 
     1013        #reset the value of chisqr when not consistent with the value computed 
     1014        self.tcChi.SetValue(str(self.state.tcChi)) 
    10101015        ## reset context menu items 
    10111016        self._reset_context_menu() 
     1017         
    10121018        ## set the value of the current state to the state given as parameter 
    10131019        self.state = state.clone()  
  • sansview/perspectives/fitting/fitpage.py

    r0b12abb5 r3c44c66  
    19361936            self.tcChi.SetValue(str(format_number(output))) 
    19371937 
    1938             self.state.tcChi =self.tcChi 
     1938            self.state.tcChi = self.tcChi.GetValue() 
    19391939        except: 
    19401940            pass   
  • sansview/perspectives/fitting/fitpanel.py

    r0b12abb5 r3c44c66  
    200200        self.Center() 
    201201         
     202    def set_data(self, list=[]): 
     203        """ 
     204        Receive a list of data and create new  
     205        """ 
     206        if list==[]: 
     207            msg = "Please select data for Fitting perspective.\n" 
     208            dial = wx.MessageDialog(None, msg, 'Error Loading File',  
     209                                    wx.OK | wx.ICON_EXCLAMATION) 
     210            dial.ShowModal()  
     211            return  
     212        for data, path in list: 
     213            self.manager.add_fit_page(data=data) 
     214             
    202215    def set_state(self, state): 
    203216        """ 
     
    415428                return panel  
    416429            else: 
    417                 for name, panel in self.opened_pages.values(): 
    418                     #Don't return any panel is the exact same page is created 
    419                     if name == page_info.window_name: 
     430                for value in self.opened_pages.values(): 
     431                    if page_info.window_name == str(value[0]): 
     432                        #Don't return any panel is the exact same page is created 
    420433                        return None 
    421                     else: 
    422                         panel = self.add_page(page_info=page_info) 
    423                         return panel         
     434                panel = self.add_page(page_info=page_info) 
     435                return panel         
    424436        else: 
    425437            #a new type of page is created 
  • sansview/perspectives/fitting/pagestate.py

    r3ad91de r3c44c66  
    362362        rep += "model  : %s\n\n"% str(self.model) 
    363363        rep += "number parameters(self.parameters): %s\n"%len(self.parameters) 
    364         rep += self._repr_helper( list=self.parameters, rep=rep) 
     364        rep = self._repr_helper( list=self.parameters, rep=rep) 
    365365        rep += "number orientation parameters" 
    366366        rep += "(self.orientation_params): %s\n"%len(self.orientation_params) 
    367         rep += self._repr_helper( list=self.orientation_params, rep=rep) 
     367        rep = self._repr_helper( list=self.orientation_params, rep=rep) 
    368368        rep += "number dispersity parameters" 
    369369        rep += "(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp) 
    370         rep += self._repr_helper( list=self.orientation_params_disp, rep=rep) 
     370        rep = self._repr_helper( list=self.orientation_params_disp, rep=rep) 
    371371         
    372372        return rep 
     
    11381138                output[0].filename = state.file 
    11391139                state.data = output[0] 
    1140                 state.data.name = state.data_name 
     1140                state.data.name = output[0].filename #state.data_name 
    11411141                state.data.id = state.data_id 
    11421142                state.data.id = state.data_id 
     
    11821182            fitstate.toXML(file=filename) 
    11831183         
    1184 """      
    1185 Example: :: 
     1184 
    11861185   
    1187     if __name__ == "__main__": 
    1188         state = PageState(parent=None) 
    1189         state.toXML() 
    1190         print "state", state 
     1186if __name__ == "__main__": 
     1187    state = PageState(parent=None) 
     1188    #state.toXML() 
     1189    """ 
    11911190     
    1192 """ 
     1191    file = open("test_state", "w") 
     1192    pickle.dump(state, file) 
     1193    print pickle.dumps(state) 
     1194    state.data_name = "hello---->" 
     1195    pickle.dump(state, file) 
     1196    file = open("test_state", "r") 
     1197    new_state= pickle.load(file) 
     1198    print "new state", new_state 
     1199    new_state= pickle.load(file) 
     1200    print "new state", new_state 
     1201    #print "state", state 
     1202    """ 
     1203    import bsddb 
     1204    import pickle 
     1205    db= bsddb.btopen('file_state.db', 'c') 
     1206    val = (pickle.dumps(state), "hello", "hi") 
     1207    db['state1']= pickle.dumps(val) 
     1208    print pickle.loads(db['state1']) 
     1209    state.data_name = "hello---->22" 
     1210    db['state2']= pickle.dumps(state) 
     1211    state.data_name = "hello---->2" 
     1212    db['state3']= pickle.dumps(state) 
     1213    del db['state3'] 
     1214    state.data_name = "hello---->3" 
     1215    db['state4']= pickle.dumps(state) 
     1216    new_state = pickle.loads(db['state1']) 
     1217    #print db.last() 
     1218    db.set_location('state2') 
     1219    state.data_name = "hello---->5" 
     1220    db['aastate5']= pickle.dumps(state) 
     1221    db.keys().sort() 
     1222    print pickle.loads(db['state2']) 
     1223   
     1224    db.close() 
  • sansview/welcome_panel.py

    refea0bd r3c44c66  
    6666            self.parent.on_close_welcome_panel() 
    6767        event.Veto()  
    68     
     68         
     69    def set_data(self, list=[]): 
     70        """ 
     71        """ 
     72        pass 
     73     
     74     
    6975class WelcomePage(wx.Panel): 
    7076    """ 
     
    127133        self.SetSizer(sizer_main) 
    128134        self.Fit() 
    129  
     135         
     136    def set_data(self, list=[]): 
     137        """ 
     138        """ 
     139        pass 
    130140 
    131141class ViewApp(wx.App): 
  • theoryview/perspectives/theory/model_panel.py

    r74755ff r3c44c66  
    363363        wx.PostEvent(self.parent, event) 
    364364               
    365                  
     365    def set_data(self, list=[], state=None): 
     366        """ 
     367        Receive  a list of data from gui_manager to plot theory 
     368        """ 
     369        if list==[]: 
     370            msg = "Please select data for Theory perspective.\n" 
     371            dial = wx.MessageDialog(None, msg, 'Error Loading File',  
     372                                    wx.OK | wx.ICON_EXCLAMATION) 
     373            dial.ShowModal()  
     374            return 
     375        else : 
     376            msg = "Theory perspective does not allow Data.\n" 
     377            msg += "Please import theory or go the theory perspective.\n" 
     378            dial = wx.MessageDialog(None, msg, 'Error Loading File',  
     379                                    wx.OK | wx.ICON_EXCLAMATION) 
     380            dial.ShowModal()  
     381      
    366382    def reset_page(self, state): 
    367383        """ 
Note: See TracChangeset for help on using the changeset viewer.