Changeset 4e9583c in sasview


Ignore:
Timestamp:
Jul 22, 2010 12:24:33 PM (15 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:
cb463b4
Parents:
f5038c06
Message:

reverse guiframe

Location:
guiframe
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • guiframe/data_loader.py

    r3c44c66 r4e9583c  
    99from load_thread import DataReader 
    1010 
    11 from sans.guicomm.events import StatusEvent 
    12 from sans.guicomm.events import  NewStoreDataEvent 
    13 from sans.guicomm.events import NewPlotEvent 
    14  
     11from sans.guicomm.events import NewPlotEvent, StatusEvent 
    1512 
    1613def enable_add_data(existing_panel, new_plot): 
     
    4138def choose_data_file(parent, location=None): 
    4239    """ 
    43     return a list of file path to read 
    4440    """ 
    4541    path = None 
     
    5147    wlist = '|'.join(cards) 
    5248     
    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) 
    7750    if dlg.ShowModal() == wx.ID_OK: 
    7851        path = dlg.GetPath() 
     
    8053    dlg.Destroy() 
    8154     
    82     return [path] 
     55    return path 
    8356 
    8457def open_dialog_append_data(panel_name, data_name): 
     
    9871    else: 
    9972        return False 
    100  
     73    
     74 
     75def 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 
    101122 
    102123def load_error(error=None): 
     
    121142    wx.PostEvent(parent, StatusEvent(status="Load cancel..", info="warning", 
    122143                                                type="stop")) 
    123      
    124  
    125  
    126 def 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      
    141 def load_helper(parent , output, path): 
    142     """ 
    143     """ 
    144     filename = os.path.basename(path) 
    145     #print output.process 
    146     if not  output.__class__.__name__ == "list": 
    147         ## Creating a Data2D with output 
    148         if hasattr(output,'data'): 
    149             msg = "Loading 2D data: %s "%output.filename 
    150             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.filename 
    155             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 name 
    162         if output.filename is None or output.filename == "": 
    163             output.filename = str(filename) 
    164         ## name of the data allow to differentiate data when plotted 
    165         name = parse_name(name=output.filename, expression="_") 
    166         if not name in parent.indice_load_data.keys(): 
    167             parent.indice_load_data[name] = 0 
    168         else: 
    169             ## create a copy of the loaded data 
    170             parent.indice_load_data[name] += 1 
    171             name = name +"[%i]"%parent.indice_load_data[name] 
    172         
    173         new_plot.name = name 
    174         ## allow to highlight data when plotted 
    175         new_plot.interactive = True 
    176         ## when 2 data have the same id override the 1 st plotted 
    177         new_plot.id = name 
    178         ##group_id specify on which panel to plot this data 
    179         new_plot.group_id = name 
    180         new_plot.is_data = True 
    181         ##post data to plot 
    182         title = output.filename 
    183         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_focus 
    191                 panel_name = existing_panel.window_caption 
    192                 data_name = new_plot.name 
    193                 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 panel 
    196                         new_plot.group_id = existing_panel.group_id 
    197         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 data 
    201     else: 
    202         i=1 
    203         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.dx 
    209                 dxl = item.dxl 
    210                 dxw = item.dxw 
    211             except: 
    212                 dx = None 
    213                 dxl = None 
    214                 dxw = None 
    215  
    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 = dxl 
    220             new_plot.dxw = dxw 
    221             
    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] = 0 
    225             else: 
    226                 ## create a copy of the loaded data 
    227                  
    228                 #TODO: this is a very annoying feature. We should make this 
    229                 # an option. Excel doesn't do this. Why should we? 
    230                 # What is the requirement for this feature, and are the 
    231                 # counter arguments stronger? Is this feature developed 
    232                 # to please at least 80% of the users or a special few? 
    233                 parent.indice_load_data[name] += 1 
    234                 name = name + "(copy %i)"%parent.indice_load_data[name] 
    235                  
    236             new_plot.name = name 
    237             new_plot.interactive = True 
    238             new_plot.group_id = name 
    239             new_plot.id = name 
    240             new_plot.is_data = True 
    241          
    242             if hasattr(item,"title"): 
    243                 title = item.title.lstrip().rstrip() 
    244                 if title == "": 
    245                     title = str(name) 
    246             else: 
    247                 title = name 
    248             if hasattr(parent, "panel_on_focus") and not(parent.panel_on_focus is None): 
    249                 existing_panel  = parent.panel_on_focus 
    250                 panel_name = existing_panel.window_caption 
    251                 data_name = new_plot.name 
    252                 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 panel 
    255                         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      
    261144     
    262145def plot_data(parent, path): 
     
    274157     
    275158    # 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      
    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 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  
    318159    try: 
    319160        output = L.load(path) 
    320161    except: 
    321         raise 
    322         #load_error(sys.exc_value) 
     162        load_error(sys.exc_value) 
    323163        return 
    324164     
     
    441281            wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(title))) 
    442282            i+=1 
    443    
     283          
  • guiframe/data_manager.py

    r3c44c66 r4e9583c  
    4242        self.parent = parent 
    4343      
     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     
    4455    def on_get_data(self, data_list, plot=False): 
    4556        """ 
     
    5364        for data, path in data_list: 
    5465            if data.name not in self.available_data.keys(): 
    55                 self.available_data[data.name] = data, path 
     66                self.available_data[data.name] = (data, path) 
    5667                if plot: 
    57                     self.data_to_plot[data.name] = data, path 
     68                    self.data_to_plot[data.name] = (data, path) 
    5869           
    5970        return self.get_sorted_list() 
  • guiframe/gui_manager.py

    r3c44c66 r4e9583c  
    4141    # Didn't find local config, load the default  
    4242    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     
    5044from sans.guicomm.events import EVT_STATUS 
    5145from sans.guicomm.events import EVT_NEW_PLOT,EVT_SLICER_PARS_UPDATE 
    5246from 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 
     47import warnings 
     48warnings.simplefilter("ignore") 
     49 
     50import logging 
    5851 
    5952def quit_guiframe(parent=None): 
     
    175168        return self.perspective 
    176169     
    177     def on_perspective(self, event=None): 
     170    def on_perspective(self, event): 
    178171        """ 
    179172        Call back function for the perspective menu item. 
     
    233226        ## Application manager 
    234227        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         
    241229        ## Find plug-ins 
    242230        # Modify this so that we can specify the directory to look into 
     
    526514        self._mgr.RestoreMaximizedPane() 
    527515         
     516         
    528517        # Register for showing/hiding the panel 
     518         
    529519        wx.EVT_MENU(self, ID, self._on_view) 
    530520         
     
    543533         
    544534        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         
    557539        id = wx.NewId() 
    558540        self.filemenu.Append(id,'&Quit', 'Exit')  
     
    594576         
    595577        if n_perspectives>1: 
    596             list=[] 
    597578            p_menu = wx.Menu() 
    598579            for plug in self.plugins: 
     
    601582                    p_menu.Append(id, plug.sub_menu, "Switch to %s perspective" % plug.sub_menu) 
    602583                    wx.EVT_MENU(self, id, plug.on_perspective) 
    603                     list.append(plug) 
    604584            menubar.Append(p_menu,   '&Perspective') 
    605         self.data_panel.layout_perspective(list_of_perspective=list) 
     585  
    606586        # Tools menu 
    607587        # Go through plug-ins and find tools to populate the tools menu 
     
    717697         
    718698            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): 
    726701        """ 
    727702        """ 
    728703        path = self.choose_file() 
    729         if path is None or path[0] is None: 
     704        if path is None: 
    730705            return 
    731706         
    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            
    781711    def _onClose(self, event): 
    782712        """ 
     
    807737        except: 
    808738            pass 
    809         if self.data_panel is not None or not self.data_panel.IsBeingDeleted(): 
    810             self.data_panel.Destroy() 
     739         
    811740        import sys 
    812741        wx.Exit() 
     
    819748        flag = quit_guiframe(parent=self) 
    820749        if flag: 
    821             if self.data_panel is not None or not self.data_panel.IsBeingDeleted(): 
    822                 self.data_panel.Destroy() 
    823750            import sys 
    824751            wx.Frame.Close(self) 
     
    876803            dialog = aboutbox.DialogAbout(None, -1, "") 
    877804            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             
    879818    def set_manager(self, manager): 
    880819        """ 
     
    925864                if not self._mgr.GetPane(self.panels[item].window_name).IsShown(): 
    926865                    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) 
    929866            else: 
    930867                if self._mgr.GetPane(self.panels[item].window_name).IsShown(): 
     
    932869     
    933870        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): 
    944873        """  
    945874        Functionality that belongs elsewhere 
    946875        Should add a hook to specify the preferred file type/extension. 
    947876        """ 
     877        #TODO: clean this up 
     878        from data_loader import choose_data_file 
     879         
    948880        # 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: 
    958885            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)    
    960915            except: 
    961                 pass 
     916                raise 
     917                #pass 
    962918        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                   
    964926class DefaultPanel(wx.Panel): 
    965927    """ 
  • guiframe/local_perspectives/plotting/plotting.py

    rcb19af9f r4e9583c  
    1515import sys 
    1616from sans.guicomm.events import EVT_NEW_PLOT 
    17 from sans.guicomm.events import NewPlotEvent 
    18 from sans.guicomm.events import EVT_NEW_LOADED_DATA 
    1917from sans.guicomm.events import StatusEvent  
    2018 
    2119 
    22 class 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         """ 
    15420class Plugin: 
    15521    """ 
     
    19662        self.parent = parent 
    19763        # Connect to plotting events 
    198         self.parent.Bind(EVT_NEW_LOADED_DATA, self._on_plot) 
    19964        self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event) 
    20065        # We have no initial panels for this plug-in 
     
    22792        pass 
    22893     
    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     
    24695    def _on_plot_event(self, event): 
    24796        """ 
     
    329178        return 
    330179         
    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             pass 
    342         dialog.Destroy() 
    343          
    344         return 1 
    345    
    346 # end of class MyApp 
    347  
    348 if __name__ == "__main__": 
    349     app = MyApp(0) 
    350     app.MainLoop()       
Note: See TracChangeset for help on using the changeset viewer.