Changeset 7434020 in sasview for sansguiframe


Ignore:
Timestamp:
Jan 17, 2012 3:07:33 PM (13 years ago)
Author:
Jae Cho <jhjcho@…>
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:
4e65505
Parents:
f706e09c
Message:

Added quickplot on data in datapanel

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

Legend:

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

    r98fdccd r7434020  
    387387            import MaskPanel as MaskDialog 
    388388         
    389         panel = MaskDialog(base=self, data=data, id=wx.NewId()) 
     389        panel = MaskDialog(parent=self.parent, base=self,  
     390                           data=data, id=wx.NewId()) 
    390391        #self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model) 
    391392        panel.ShowModal() 
     393     
     394    def on_plot_3d(self, event): 
     395        """ 
     396        Frozen image of 3D 
     397        """ 
     398        data = self._get_data_selection(event) 
     399        from sans.guiframe.local_perspectives.plotting.masking \ 
     400        import FloatPanel as Float3dDialog 
     401         
     402        panel = Float3dDialog(base=self, data=data,  
     403                              dimension=3, id=wx.NewId()) 
     404        panel.ShowModal()    
     405     
     406    def on_quick_plot(self, event): 
     407        """ 
     408        Frozen plot 
     409        """ 
     410        data = self._get_data_selection(event) 
     411        from sans.guiframe.local_perspectives.plotting.masking \ 
     412        import FloatPanel as QucikPlotDialog 
     413        if data.__class__.__name__ == "Data2D": 
     414            dimension = 2 
     415        else: 
     416            dimension = 1 
     417        panel = QucikPlotDialog(base=self, data=data,  
     418                                dimension=dimension, id=wx.NewId()) 
     419        panel.ShowModal()     
    392420         
    393421    def on_save_as(self, event): 
     
    426454        wx.EVT_MENU(self, id, self.on_save_as) 
    427455     
     456        self.quickplot_id = wx.NewId() 
     457        name = "Quick Plot" 
     458        msg = "Plot the current Data" 
     459        self.data_menu.Append(self.quickplot_id, name, msg) 
     460        wx.EVT_MENU(self, self.quickplot_id, self.on_quick_plot) 
     461     
     462        self.plot3d_id = wx.NewId() 
     463        name = "Quick 3DPlot (Slow)" 
     464        msg = "Plot3D the current 2D Data" 
     465        self.data_menu.Append(self.plot3d_id, name, msg) 
     466        wx.EVT_MENU(self, self.plot3d_id, self.on_plot_3d) 
     467             
    428468        self.editmask_id = wx.NewId() 
    429469        name = "Edit Mask" 
     
    431471        self.data_menu.Append(self.editmask_id, name, msg) 
    432472        wx.EVT_MENU(self, self.editmask_id, self.on_edit_data) 
    433  
     473         
    434474        tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory") 
    435475        tree_ctrl_theory_label.SetForegroundColour('blue') 
     
    474514            return 
    475515        if self.data_menu is not None: 
    476             menu_enable = (data_class_name == "Data2D" and is_data) 
    477             self.data_menu.Enable(self.editmask_id, menu_enable) 
     516            menu_enable = (data_class_name == "Data2D") 
     517            maskmenu_enable = (menu_enable and is_data) 
     518            self.data_menu.Enable(self.editmask_id, maskmenu_enable) 
     519            self.data_menu.Enable(self.plot3d_id, menu_enable) 
    478520            self.PopupMenu(self.data_menu)  
    479521         
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/masking.py

    r02aff3d r7434020  
    2525from danse.common.plottools.plottables import Graph 
    2626from binder import BindArtist 
    27 from sans.guiframe.dataFitting import Data2D 
     27from sans.guiframe.dataFitting import Data1D, Data2D 
    2828from boxMask import BoxMask 
    2929from sectorMask import SectorMask 
     
    5757                 data=None, id=-1, *args, **kwds): 
    5858        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
    59         kwds["size"] = wx.Size(_STATICBOX_WIDTH * 2, PANEL_SIZE)  
     59        kwds["size"] = wx.Size(_STATICBOX_WIDTH*0.8, PANEL_SIZE)  
    6060        wx.Dialog.__init__(self, parent, id=id,  *args, **kwds) 
    6161         
     
    508508            # when called by data panel 
    509509            event.Skip() 
     510            pass    
     511 
     512class FloatPanel(wx.Dialog): 
     513    """ 
     514    Provides the Mask Editor GUI. 
     515    """ 
     516    ## Internal nickname for the window, used by the AUI manager 
     517    window_name = "Plot" 
     518    ## Name to appear on the window title bar 
     519    window_caption = "Plot" 
     520    ## Flag to tell the AUI manager to put this panel in the center pane 
     521    CENTER_PANE = True 
     522    def __init__(self, parent=None, base=None,  
     523                 data=None, dimension=1, id=-1, *args, **kwds): 
     524        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
     525        kwds["size"] = wx.Size(_STATICBOX_WIDTH*1.3, PANEL_SIZE*1.3)  
     526        wx.Dialog.__init__(self, parent, id=id,  *args, **kwds) 
     527         
     528        if data != None: 
     529            #Font size  
     530            kwds = [] 
     531            self.SetWindowVariant(variant=FONT_VARIANT) 
     532            self.SetTitle("Plot " + data.name) 
     533            self.parent = base 
     534            self.data = data 
     535            self.str = self.data.__str__() 
     536            ## when 2 data have the same id override the 1 st plotted 
     537            self.name = self.data.name 
     538            self.dimension = dimension 
     539            # Panel for 2D plot 
     540            self.plotpanel = Maskplotpanel(self, -1, dimension, 
     541                                           style=wx.TRANSPARENT_WINDOW) 
     542             
     543            self.cmap = DEFAULT_CMAP 
     544            ## Create Artist and bind it 
     545            self.subplot = self.plotpanel.subplot 
     546            self._setup_layout() 
     547            if self.dimension == 1: 
     548                self.newplot = Data1D(x=data.x, y=data.y,  
     549                                      dx=data.dx, dy=data.dy) 
     550                self.newplot.name = data.name 
     551            else:     
     552                self.newplot = Data2D(image=self.data.data) 
     553                self.newplot.setValues(self.data) 
     554                 
     555            self.plotpanel.add_image(self.newplot)  
     556            self.Centre() 
     557            self.Layout() 
     558 
     559             
     560    def _setup_layout(self): 
     561        """ 
     562        Set up the layout 
     563        """ 
     564        #  panel 
     565        sizer = wx.GridBagSizer(10, 10) 
     566        if self.dimension == 3: 
     567            note = "Note: I am very SLOW.     Please be PATIENT...\n" 
     568            note_txt = wx.StaticText(self, -1, note)  
     569            note_txt.SetForegroundColour(wx.RED) 
     570            sizer.Add(note_txt, (0, 2), flag=wx.RIGHT|wx.BOTTOM, border=5) 
     571         
     572        sizer.Add(self.plotpanel, (1, 1), (9, 9),  
     573                  wx.EXPAND|wx.ALL, 15) 
     574 
     575        sizer.AddGrowableCol(3) 
     576        sizer.AddGrowableRow(2) 
     577         
     578        self.SetSizerAndFit(sizer) 
     579        self.Centre() 
     580        self.Show(True) 
     581         
     582    def set_plot_unfocus(self): 
     583        """ 
     584        Not implemented 
     585        """ 
     586        pass 
     587     
     588 
     589    def _draw_model(self, event): 
     590        """ 
     591         on_close, update the model2d plot 
     592        """ 
     593        pass 
     594         
     595    def freeze_axes(self): 
     596        """ 
     597        freeze axes 
     598        """ 
     599        self.plotpanel.axes_frozen = True 
     600         
     601    def thaw_axes(self): 
     602        """ 
     603        thaw axes 
     604        """ 
     605        self.plotpanel.axes_frozen = False        
     606     
     607    def OnClose(self, event): 
     608        """ 
     609        """ 
     610        try: 
     611            self.plotpanel.subplot.figure.clf() 
     612        except: 
     613            # when called by data panel 
     614            event.Skip() 
    510615            pass 
    511          
     616 
     617                 
    512618class Maskplotpanel(PlotPanel): 
    513619    """ 
     620    PlotPanel for Quick plot and masking plot 
    514621    """ 
    515     def __init__(self, parent, id=-1, color=None, dpi=None, **kwargs): 
     622    def __init__(self, parent, id=-1, dimension=2, color=None,  
     623                                            dpi=None, **kwargs): 
    516624        """ 
    517625        """ 
     
    522630        # Internal list of plottable names (because graph  
    523631        # doesn't have a dictionary of handles for the plottables) 
     632        self.dimension = dimension 
    524633        self.plots = {} 
    525634        self.graph = Graph() 
     635        #add axis labels 
     636        if self.dimension == 1: 
     637            self.graph.xaxis('\\rm{x} ', '') 
     638            self.graph.yaxis('\\rm{y} ', '') 
     639        if self.dimension == 2: 
     640            self.graph.xaxis('\\rm{Q}_{x} ', 'A^{-1}') 
     641            self.graph.yaxis('\\rm{Q}_{y} ', 'A^{-1}') 
    526642         
    527643    def add_toolbar(self): 
     
    531647        # Not implemented 
    532648        pass 
     649     
    533650    def on_set_focus(self, event): 
    534651        """ 
    535652        send to the parenet the current panel on focus 
    536653        """ 
    537         #change the panel background 
    538         #self.SetColor((170, 202, 255)) 
    539         self.draw()    
     654        if self.dimension == 3: 
     655            pass 
     656        else: 
     657            self.draw()    
    540658          
    541659    def add_image(self, plot): 
     
    549667        self.graph.add(plot) 
    550668        #add axes 
    551         self.graph.xaxis('\\rm{Q}_{x} ', 'A^{-1}') 
    552         self.graph.yaxis('\\rm{Q}_{y} ', 'A^{-1}') 
     669        if self.dimension == 1: 
     670            self.xaxis_label = '\\rm{x} ' 
     671            self.xaxis_unit = '' 
     672            self.yaxis_label = '\\rm{y} ' 
     673            self.yaxis_unit = '' 
    553674        #draw 
     675        # message 
     676        status_type = 'progress'  
     677        msg = 'Plotting...' 
     678        self._status_info(msg, status_type) 
     679        status_type = 'stop'            
     680         
    554681        self.graph.render(self) 
    555         self.subplot.figure.canvas.draw_idle() 
     682        if self.dimension == 3: 
     683            pass 
     684        else: 
     685            self.subplot.figure.canvas.draw_idle() 
     686        msg = 'Plotting Completed.' 
     687        self._status_info(msg, status_type) 
    556688         
    557689    def onMouseMotion(self, event): 
     
    560692        """ 
    561693        pass 
    562     
     694     
     695    def onWheel(self, event): 
     696        """ 
     697        """ 
     698        pass  
     699      
     700    def onLeftDown(self, event): 
     701        """ 
     702        Disables LeftDown 
     703        """ 
     704        pass 
     705     
     706    def onPick(self, event): 
     707        """ 
     708        Disables OnPick 
     709        """ 
     710        pass 
     711     
     712    def draw(self): 
     713        """ 
     714        Draw 
     715        """ 
     716        # message 
     717        status_type = 'progress'  
     718        msg = 'Plotting...' 
     719        self._status_info(msg, status_type) 
     720        status_type = 'stop'            
     721         
     722        if self.dimension == 3: 
     723            pass 
     724        else: 
     725           self.subplot.figure.canvas.draw_idle()  
     726         
     727        msg = 'Plotting Completed.' 
     728        self._status_info(msg, status_type) 
     729        
    563730    def onContextMenu(self, event): 
    564731        """ 
    565732        Default context menu for a plot panel 
    566733        """ 
    567         # Slicer plot popup menu 
     734        # Selective Slicer plot popup menu 
    568735        slicerpop = wx.Menu() 
    569736         
    570         id_cm = wx.NewId() 
    571         slicerpop.Append(id_cm, '&Toggle Linear/Log scale') 
    572         wx.EVT_MENU(self, id_cm, self._onToggleScale) 
     737        id = wx.NewId() 
     738        slicerpop.Append(id,'&Print Image', 'Print image') 
     739        wx.EVT_MENU(self, id, self.onPrint) 
     740 
     741        id = wx.NewId() 
     742        slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') 
     743        wx.EVT_MENU(self, id, self.OnCopyFigureMenu) 
     744         
     745        if self.dimension == 1: 
     746            id = wx.NewId() 
     747            slicerpop.Append(id, '&Change Scale') 
     748            wx.EVT_MENU(self, id, self._onProperties) 
     749        else: 
     750            slicerpop.AppendSeparator() 
     751            id_cm = wx.NewId() 
     752            slicerpop.Append(id_cm, '&Toggle Linear/Log scale') 
     753            wx.EVT_MENU(self, id_cm, self._onToggleScale) 
    573754                
    574755        pos = event.GetPosition() 
    575756        pos = self.ScreenToClient(pos) 
    576757        self.PopupMenu(slicerpop, pos) 
     758         
     759    def _status_info(self, msg = '', type = "update"): 
     760        """ 
     761        Status msg 
     762        """ 
     763        if type == "stop": 
     764            label = "Plotting..." 
     765            able = True 
     766        else:    
     767            label = "Wait..." 
     768            able = False 
     769        if self.parent.parent.parent != None: 
     770                wx.PostEvent(self.parent.parent.parent,  
     771                             StatusEvent(status = msg, type = type )) 
    577772 
    578773class ViewerFrame(wx.Frame): 
Note: See TracChangeset for help on using the changeset viewer.