Changeset 940aca7 in sasview for sansguiframe/src


Ignore:
Timestamp:
May 19, 2012 10:17:02 AM (12 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
baa915c
Parents:
d225e32
Message:

Merge 2.1.1 into trunk

Location:
sansguiframe/src/sans/guiframe
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • sansguiframe/src/sans/guiframe/gui_manager.py

    r6306f2f r940aca7  
    452452            return 
    453453        _, ext = os.path.splitext(name) 
    454         fd = open(file_name, 'w') 
     454        try: 
     455            fd = open(file_name, 'w') 
     456        except: 
     457            # On Permission denied: IOError 
     458            temp_dir = get_user_directory() 
     459            temp_file_name = os.path.join(temp_dir, name) 
     460            fd = open(temp_file_name, 'w') 
    455461        separator = "\t" 
    456462        if ext.lower() == ".csv": 
     
    491497            excel_app.Visible = 1 
    492498        except: 
    493             msg = "Error occured when calling Excel\n" 
    494             msg += "Check that Excel in installed in this machine or \n" 
    495             msg += "Check that %s really exists.\n" % str(file_name) 
     499            msg = "Error occured when calling Excel.\n" 
     500            msg += "Check that Excel installed in this machine or \n" 
     501            msg += "check that %s really exists.\n" % str(file_name) 
    496502            wx.PostEvent(self, StatusEvent(status=msg, 
    497503                                             info="error")) 
     
    10311037        return menu_list 
    10321038         
    1033          
     1039    def get_current_context_menu(self, plotpanel=None): 
     1040        """ 
     1041        Get the context menu items made available  
     1042        by the current plug-in.  
     1043        This function is used by the plotting module 
     1044        """ 
     1045        if plotpanel is None: 
     1046            return 
     1047        menu_list = [] 
     1048        item = self._current_perspective 
     1049        if item != None: 
     1050            menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 
     1051        return menu_list 
     1052             
    10341053    def on_panel_close(self, event): 
    10351054        """ 
     
    25982617                if has_errors: 
    25992618                    if data.dx != [] and data.dx[i] != None: 
    2600                         out.write("%g  %g  %g  %g\n" % (data.x[i],  
    2601                                                     data.y[i], 
    2602                                                     data.dy[i], 
    2603                                                     data.dx[i])) 
     2619                        if  data.dx[i] != None: 
     2620                            out.write("%g  %g  %g  %g\n" % (data.x[i],  
     2621                                                        data.y[i], 
     2622                                                        data.dy[i], 
     2623                                                        data.dx[i])) 
     2624                        else: 
     2625                            out.write("%g  %g  %g\n" % (data.x[i],  
     2626                                                        data.y[i], 
     2627                                                        data.dy[i])) 
    26042628                    else: 
    26052629                        out.write("%g  %g  %g\n" % (data.x[i],  
  • sansguiframe/src/sans/guiframe/gui_statusbar.py

    r199fdec r940aca7  
    238238        clear the progress bar 
    239239        """ 
    240         flag = False 
    241         if (self.nb_start <= self.nb_stop) or \ 
    242             (self.nb_progress <= self.nb_stop): 
    243             flag = True 
     240        flag = True 
     241        # Why we do this? 
     242        #if (self.nb_start <= self.nb_stop) or \ 
     243        #    (self.nb_progress <= self.nb_stop): 
     244        #    flag = True 
    244245        return flag 
    245246     
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/AnnulusSlicer.py

    r13382fc7 r940aca7  
    167167 
    168168        new_plot.group_id = "AnnulusPhi" + self.base.data2D.name 
    169         new_plot.id = None 
    170         #new_plot.is_data= True 
     169        new_plot.id = "AnnulusPhi" + self.base.data2D.name 
     170        new_plot.is_data= True 
    171171        new_plot.xtransform = "x" 
    172172        new_plot.ytransform = "y" 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter1D.py

    r78919f45 r940aca7  
    4141DEFAULT_BEAM = 0.005 
    4242BIN_WIDTH = 1 
    43  
     43IS_MAC = (sys.platform == 'darwin') 
    4444 
    4545class ModelPanel1D(PlotPanel, PanelBase): 
     
    174174        # It was found that wx >= 2.9.3 sends an event even if no size changed. 
    175175        # So manually recode the size (=x_size) and compare here. 
     176        # Massy code to work around:< 
     177        if self.parent._mgr != None: 
     178            max_panel = self.parent._mgr.GetPane(self) 
     179            if max_panel.IsMaximized(): 
     180                self.parent._mgr.RestorePane(max_panel) 
     181                max_panel.Maximize() 
    176182        if self.x_size != None: 
    177183            if self.x_size == self.GetSize(): 
     
    286292            try: 
    287293                self._onEVT_FUNC_PROPERTY() 
     294                if IS_MAC: 
     295                    # MAC: forcing to plot 2D avg 
     296                    self.canvas._onDrawIdle() 
    288297            except: 
    289298                msg=" Encountered singular points..." 
     
    409418                if plot != self.plots[self.graph.selected_plottable]: 
    410419                    continue 
     420                 
     421            id = wx.NewId() 
     422            plot_menu.Append(id, "&DataInfo", name) 
     423            wx.EVT_MENU(self, id, self. _onDataShow) 
     424            id = wx.NewId() 
     425            plot_menu.Append(id, "&Save Points as a File", name) 
     426            wx.EVT_MENU(self, id, self._onSave) 
     427            plot_menu.AppendSeparator() 
     428             
    411429            #add menu of other plugins 
    412             item_list = self.parent.get_context_menu(self) 
     430            item_list = self.parent.get_current_context_menu(self) 
    413431               
    414432            if (not item_list == None) and (not len(item_list) == 0): 
     
    425443                        pass 
    426444                plot_menu.AppendSeparator() 
    427                  
    428             id = wx.NewId() 
    429             plot_menu.Append(id, "&DataInfo", name) 
    430             wx.EVT_MENU(self, id, self. _onDataShow) 
    431             id = wx.NewId() 
    432             plot_menu.Append(id, "&Save Points as a File", name) 
    433             wx.EVT_MENU(self, id, self._onSave) 
    434             plot_menu.AppendSeparator() 
     445             
    435446            if self.parent.ClassName.count('wxDialog') == 0:  
    436447                id = wx.NewId() 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter2D.py

    r2778c4f r940aca7  
    321321        if len(self.data2D.detector) == 1:         
    322322             
    323             item_list = self.parent.get_context_menu(self) 
     323            item_list = self.parent.get_current_context_menu(self) 
    324324            if (not item_list == None) and (not len(item_list) == 0) and\ 
    325325                self.data2D.name.split(" ")[0] != 'Residuals':   
     
    631631            new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    632632 
    633         new_plot.group_id = "Circ avg " + self.data2D.name 
     633        new_plot.group_id = "2daverage" + self.data2D.name 
    634634        new_plot.id = "Circ avg " + self.data2D.name 
    635635        new_plot.is_data = True 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/SectorSlicer.py

    r789ffc6 r940aca7  
    183183            new_plot.yaxis("\\rm{Residuals} ", "/") 
    184184 
    185         new_plot.group_id = "SectorQ" + self.base.data2D.name 
    186         new_plot.id = None 
     185        new_plot.group_id = "2daverage" + self.base.data2D.name 
     186        new_plot.id = "SectorQ" + self.base.data2D.name 
    187187        new_plot.is_data = True 
    188188        self.base.parent.update_theory(data_id=data, \ 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/SlicerParameters.py

    r8c347a6 r940aca7  
    8787                    ctl.SetValue(format_number(str(params[item]))) 
    8888                    self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) 
    89                     ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 
    9089                    self.parameters.append([item, ctl]) 
    9190                    self.bck.Add(ctl, (iy, ix), (1, 1),  
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/boxSlicer.py

    r13382fc7 r940aca7  
    198198            new_plot.yaxis("\\rm{Residuals} ", "/") 
    199199             
    200         new_plot.group_id = str(self.averager.__name__) + self.base.data2D.name 
    201         #new_plot.id = str(self.averager.__name__) 
    202         #new_plot.is_data= True 
     200        new_plot.group_id = "2daverage" + self.base.data2D.name 
     201        new_plot.id = (self.averager.__name__) + self.base.data2D.name 
     202        new_plot.is_data= True 
    203203        self.base.parent.update_theory(data_id=self.base.data2D.id, \ 
    204204                                       theory=new_plot) 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/plotting.py

    r48832ac r940aca7  
    276276         
    277277        """ 
     278        action_check = False 
    278279        if hasattr(event, 'action'): 
    279             group_id = event.group_id 
    280             if group_id in self.plot_panels.keys(): 
    281                 #remove data from panel 
    282                 if event.action.lower().strip() == 'remove': 
    283                     id = event.id 
    284                     return self.remove_plot(group_id, id) 
    285                 if event.action.lower().strip() == 'hide': 
    286                     return self.hide_panel(group_id) 
    287                 if event.action.lower().strip() == 'delete': 
    288                     panel = self.plot_panels[group_id] 
    289                     uid = panel.uid 
    290                     return self.parent.delete_panel(uid) 
    291                 if event.action.lower().strip() == "clear": 
    292                     return self.clear_panel_by_id(group_id) 
     280            action_string = event.action.lower().strip() 
     281            if action_string == 'check': 
     282                action_check = True 
     283            else: 
     284                group_id = event.group_id 
     285                if group_id in self.plot_panels.keys(): 
     286                    #remove data from panel 
     287                    if action_string == 'remove': 
     288                        id = event.id 
     289                        return self.remove_plot(group_id, id) 
     290                    if action_string == 'hide': 
     291                        return self.hide_panel(group_id) 
     292                    if action_string == 'delete': 
     293                        panel = self.plot_panels[group_id] 
     294                        uid = panel.uid 
     295                        return self.parent.delete_panel(uid) 
     296                    if action_string == "clear": 
     297                        return self.clear_panel_by_id(group_id) 
     298                     
    293299        if not hasattr(event, 'plot'):     
    294300            return 
    295301        title = None 
    296302        if hasattr(event, 'title'): 
    297             title = 'Graph'#event.title 
    298                  
     303            title = 'Graph'#event.title       
    299304        data = event.plot 
    300         group_id = data.group_id 
    301              
    302         if group_id in self.plot_panels.keys(): 
     305        group_id = data.group_id     
     306        if group_id in self.plot_panels.keys(): 
     307            if action_check: 
     308                # Check if the plot already exist. if it does, do nothing. 
     309                if data.id in self.plot_panels[group_id].plots.keys(): 
     310                    return  
    303311            #update a panel graph  
    304312            panel = self.plot_panels[group_id] 
     
    309317                new_panel = self.create_1d_panel(data, group_id) 
    310318            else: 
     319                # Need to make the group_id consistent with 1D thus no if below 
     320                if len(self.plot_panels.values()) > 0: 
     321                    for p_group_id in self.plot_panels.keys(): 
     322                        p_plot = self.plot_panels[p_group_id] 
     323                        if data.id in p_plot.plots.keys(): 
     324                            p_plot.plots[data.id] = data 
     325                            self.plot_panels[group_id] = p_plot 
     326                            if group_id != p_group_id: 
     327                                del self.plot_panels[p_group_id] 
     328                                if p_group_id in data.list_group_id: 
     329                                    data.list_group_id.remove(p_group_id) 
     330                                if group_id not in data.list_group_id: 
     331                                    data.list_group_id.append(group_id) 
     332                            p_plot.group_id = group_id 
     333                            return 
     334                 
    311335                new_panel = self.create_2d_panel(data, group_id) 
    312             self.create_panel_helper(new_panel, data, group_id, title) 
    313              
     336            self.create_panel_helper(new_panel, data, group_id, title)  
    314337        return 
    315338 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/profile_dialog.py

    r2d443fd r940aca7  
    5353            self.SetTitle("Scattering Length Density Profile") 
    5454            self.parent = parent 
     55            self._mgr = None 
    5556            self.data = data 
    5657            self.str = self.data.__str__() 
     
    7576            self.newplot.dy = None 
    7677            self.newplot.name = 'SLD' 
     78            self.newplot.id = self.newplot.name 
    7779            self.plotpanel.add_image(self.newplot)  
    7880            self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF ,  
     
    8183                                                max(data_plot.x) + _X_OFF) 
    8284            #self.Centre() 
     85            self.plotpanel.resizing = False 
     86            self.plotpanel.canvas.set_resizing(self.plotpanel.resizing) 
     87            self.plotpanel.subplot.figure.canvas.draw_idle() 
    8388            self.Layout() 
    8489 
     
    175180        self.parent.parent.parent.on_change_caption(name, old_caption, new_caption) 
    176181     
     182    def disable_app_menu(self, panel): 
     183        """ 
     184        Disable menu bar 
     185        """ 
     186        # Not implemented! 
     187        return 
    177188     
    178189class SLDplotpanel(PlotPanel): 
     
    203214        self.yaxis_label = '' 
    204215        self.yaxis_unit = '' 
     216        self.resizing = True 
    205217         
    206218    def add_image(self, plot): 
     
    208220        Add image(Theory1D) 
    209221        """ 
    210         self.plots[plot.name] = plot 
    211         self.plots[plot.name].is_data = False 
    212         #init graph 
    213         #self.gaph = Graph() 
     222        self.plots[plot.id] = plot 
     223        self.plots[plot.id].is_data = True 
    214224        #add plot 
    215225        self.graph.add(plot) 
     
    222232        self.yaxis_unit = '10^{-6}A^{-2}' 
    223233        self.graph.yaxis(self.yaxis_label, self.yaxis_unit) 
     234        #self.subplot.figure.canvas.draw_idle() 
     235        # For latter scale changes  
     236        self.plots[plot.id].xaxis('\\rm{%s} '% x1_label, 'A') 
     237        self.plots[plot.id].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}') 
    224238        #draw 
    225239        self.graph.render(self) 
    226         self.subplot.figure.canvas.draw_idle() 
    227                  
    228         # For latter scale changes  
    229         self.plots[plot.name].xaxis('\\rm{%s} '% x1_label, 'A') 
    230         self.plots[plot.name].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}') 
    231240         
    232241    def on_set_focus(self, event): 
     
    257266        """ 
    258267        pass 
    259      
     268                            
    260269    def _onSave(self, evt): 
    261270        """ 
     
    265274         
    266275        """ 
    267         
    268         path = None 
    269         wildcard = "Text files (*.txt)|*.txt|"\ 
    270                     "CanSAS 1D files(*.xml)|*.xml"  
    271         default_name = "sld_profile" 
     276        menu = evt.GetEventObject() 
     277        id = evt.GetId() 
     278        self.set_selected_from_menu(menu, id) 
     279        data = self.plots[self.graph.selected_plottable] 
     280        default_name = data.label 
     281        if default_name.count('.') > 0: 
     282            default_name = default_name.split('.')[0] 
     283        default_name += "_out" 
    272284        if self.parent != None: 
    273             self._default_save_location = self.parent.parent._default_save_location 
    274         dlg = wx.FileDialog(self, "Choose a file", 
    275                             self._default_save_location, 
    276                             default_name, wildcard , wx.SAVE) 
    277         
    278         if dlg.ShowModal() == wx.ID_OK: 
    279             path = dlg.GetPath() 
    280             # ext_num = 0 for .txt, ext_num = 1 for .xml 
    281             # This is MAC Fix 
    282             ext_num = dlg.GetFilterIndex() 
    283             if ext_num == 0: 
    284                 format = '.txt' 
    285             else: 
    286                 format = '.xml' 
    287             path = os.path.splitext(path)[0] + format 
    288             mypath = os.path.basename(path) 
    289              
    290             #TODO: This is bad design. The DataLoader is designed  
    291             #to recognize extensions. 
    292             # It should be a simple matter of calling the . 
    293             #save(file, data, '.xml') method 
    294             # of the sans.dataloader.loader.Loader class. 
    295             from sans.dataloader.loader import  Loader 
    296             #Instantiate a loader  
    297             loader = Loader()  
    298             data = self.parent.data 
    299             format = ".txt" 
    300             if os.path.splitext(mypath)[1].lower() == format: 
    301                 # Make sure the ext included in the file name 
    302                 # especially on MAC 
    303                 fName = os.path.splitext(path)[0] + format 
    304                 self._onsaveTXT(fName) 
    305             format = ".xml" 
    306             if os.path.splitext(mypath)[1].lower() == format: 
    307                 # Make sure the ext included in the file name 
    308                 # especially on MAC 
    309                 fName = os.path.splitext(path)[0] + format 
    310                 loader.save(fName, data, format) 
    311             try: 
    312                 self._default_save_location = os.path.dirname(path) 
    313                 self.parent.parent._default_save_location = self._default_save_location 
    314             except: 
    315                 pass     
    316         dlg.Destroy() 
    317           
     285            # What an ancestor! 
     286            fit_panel = self.parent.parent.parent 
     287            fit_panel.parent.save_data1d(data, default_name) 
     288              
    318289class ViewerFrame(wx.Frame): 
    319290    """ 
  • sansguiframe/src/sans/guiframe/media/Graph_help.html

    rd874092 r940aca7  
    77<li><a href="#reset">Reset Graph</a></li> 
    88<li><a href="#hide">Hide/Show/Delete Graph</a></li> 
     9<li><a href="#info">Data Info</a></li> 
    910<li><a href="#save">Save plot Image</a></li> 
    1011<li><a href="#savedata">Save Data</a></li> 
    1112<li><a href="#drag">Drag plot</a></li> 
    12 <li><a href="#select">Select Data</a></li> 
    1313<li><a href="#zoom">Zoom In/Out</a></li> 
    1414<li><a href="#remove">Remove Data</a></li> 
     
    3333<h5><a name="hide">Hide/Show/Delete Graph</a></h5> 
    3434<p> 
    35         To Hide, click the Hide (closed eye) button in the tool bar.<br> 
     35        To Hide, click the Hide (bar) button in the tool bar.<br> 
    3636        To Show, select the the 'Show' menuitem in the 'Graph' menu in the menu bar.<br> 
    3737        To Delete, click the 'x' button in the title bar.<br> 
     
    4343        Right click on plot. Context menu will pop-up select save image [file name].A dialog 
    4444        window opens and write a the name of the file to save and click on <b>Save Image.</b> 
     45</p> 
     46 
     47<h5><a name="info"> Data Info</a></h5> 
     48<p> 
     49        From the context menu, select 'Data Info' to see the data information dialog panel. 
    4550</p> 
    4651 
Note: See TracChangeset for help on using the changeset viewer.