Changeset 3e001f9 in sasview


Ignore:
Timestamp:
Apr 6, 2013 1:36:03 PM (11 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:
4bdd4fdb
Parents:
cb270ad2
Message:

Added tools, imageviwer and qrange cursors

Files:
5 added
7 edited

Legend:

Unmodified
Added
Removed
  • calculatorview/src/sans/perspectives/calculator/calculator.py

    r49a8843 r3e001f9  
    6666        gensans_help = "Generic SANS" 
    6767        pyconsole_help = "Python Console." 
     68        imageviewer_help = "Load an image file and display the image." 
    6869        #data_editor_help = "Meta Data Editor" 
    6970        return [("Data Operation",  
     
    8081                ("Generic Scattering Calculator",  
    8182                        gensans_help, self.on_gen_model), 
    82                 ("Python Shell/Editor", pyconsole_help, self.on_python_console)] 
     83                ("Python Shell/Editor", pyconsole_help, self.on_python_console), 
     84                ("Image Viewer", imageviewer_help, self.on_image_viewer),] 
    8385               
    8486    def on_edit_data(self, event): 
     
    162164        self.put_icon(frame) 
    163165        frame.Show(True)  
     166 
     167    def on_image_viewer(self, event): 
     168        """ 
     169        Get choose an image file dialog 
     170         
     171        :param event: menu event 
     172        """ 
     173        from sans.perspectives.calculator.image_viewer import ImageView 
     174        image_view = ImageView(parent=self.parent) 
     175        image_view.load() 
    164176         
    165177    def on_python_console(self, event): 
     
    193205                except: 
    194206                    pass       
    195    
    196      
  • calculatorview/src/sans/perspectives/calculator/gen_scatter_panel.py

    r968f72d r3e001f9  
    662662        output = self.sld_data   
    663663        #frame_size = wx.Size(470, 470)     
    664         self.plot_frame = PlotFrame(self, -1, 'testView') 
     664        self.plot_frame = PlotFrame(self.parent.parent, -1, 'testView') 
    665665        frame = self.plot_frame 
    666666        frame.Show(False) 
     
    17901790        return flag 
    17911791 
    1792 class SasGenWindow(wx.Frame): 
     1792class SasGenWindow(wx.MDIChildFrame): 
    17931793    """ 
    17941794    GEN SAS main window 
     
    18021802        kwds['title'] = title 
    18031803         
    1804         wx.Frame.__init__(self, parent, *args, **kwds) 
     1804        wx.MDIChildFrame.__init__(self, parent, *args, **kwds) 
    18051805        self.parent = parent 
    18061806        self.omfpanel = OmfPanel(parent=self) 
     
    20022002        """ 
    20032003        """ 
    2004         frame = PlotFrame(self, -1, 'testView', self.scale2d) 
     2004        frame = PlotFrame(self.parent, -1, 'testView', self.scale2d) 
    20052005        add_icon(self.parent, frame) 
    20062006        frame.add_plot(plot) 
  • calculatorview/src/sans/perspectives/calculator/help_panel.py

    r318b5bbb r3e001f9  
    8484            <li><a href ="pycrust_help.html"  
    8585            target ="showframe">Python Shell</a><br></li> 
     86            <li><a href ="load_image_help.html"  
     87            target ="showframe">Image Viewer</a><br></li> 
    8688            </ul> 
    8789            </body> 
  • fittingview/src/sans/perspectives/fitting/fitpage.py

    rcb270ad2 r3e001f9  
    1212from sans.guiframe.events import StatusEvent 
    1313from sans.guiframe.events import NewPlotEvent 
     14from sans.guiframe.events import PlotQrangeEvent 
    1415from sans.guiframe.dataFitting import check_data_validity 
    1516from sans.guiframe.utils import format_number 
     
    516517        self.qmin = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    517518                                    style=wx.TE_PROCESS_ENTER, 
    518                                     text_enter_callback=self._onQrangeEnter) 
     519                                    set_focus_callback=self.qrang_set_focus, 
     520                                    text_enter_callback=self._onQrangeEnter, 
     521                                    name='qmin') 
    519522        self.qmin.SetValue(str(self.qmin_x)) 
    520         self.qmin.SetToolTipString("Minimun value of Q in linear scale.") 
     523        q_tip = "Click outside of the axes\n to remove the lines." 
     524        qmin_tip = "Minimun value of Q.\n" 
     525        qmin_tip += q_tip 
     526        self.qmin.SetToolTipString(qmin_tip) 
    521527      
    522528        self.qmax = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 
    523529                                       style=wx.TE_PROCESS_ENTER, 
    524                                        text_enter_callback=self._onQrangeEnter) 
     530                                       set_focus_callback=self.qrang_set_focus, 
     531                                       text_enter_callback=self._onQrangeEnter, 
     532                                       name='qmax') 
    525533        self.qmax.SetValue(str(self.qmax_x)) 
    526         self.qmax.SetToolTipString("Maximum value of Q in linear scale.") 
     534        qmax_tip = "Maximum value of Q.\n" 
     535        qmax_tip += q_tip 
     536        self.qmax.SetToolTipString(qmax_tip) 
     537        self.qmin.Bind(wx.EVT_MOUSE_EVENTS, self.qrange_click) 
     538        self.qmax.Bind(wx.EVT_MOUSE_EVENTS, self.qrange_click) 
     539        self.qmin.Bind(wx.EVT_KEY_DOWN, self.on_key) 
     540        self.qmax.Bind(wx.EVT_KEY_DOWN, self.on_key) 
     541        self.qmin.Bind(wx.EVT_TEXT, self.on_qrange_text) 
     542        self.qmax.Bind(wx.EVT_TEXT, self.on_qrange_text) 
    527543        id = wx.NewId() 
    528544        self.reset_qrange = wx.Button(self, id, 'Reset', size=(77, 20)) 
     
    13181334        wx.PostEvent(self.parent, event) 
    13191335        self.state_change = False 
    1320           
     1336         
     1337    def qrang_set_focus(self, event=None):   
     1338        """ 
     1339        ON Qrange focus 
     1340        """ 
     1341        if event != None: 
     1342            event.Skip() 
     1343        #tcrtl = event.GetEventObject() 
     1344        self._validate_qrange(self.qmin, self.qmax) 
     1345         
     1346    def qrange_click(self, event): 
     1347        """ 
     1348        On Qrange textctrl click, make the qrange lines in the plot 
     1349        """ 
     1350        if event != None: 
     1351            event.Skip() 
     1352        if self.data.__class__.__name__ == "Data2D": 
     1353            return 
     1354        is_click = event.LeftDown() 
     1355        if is_click: 
     1356            d_id = self.data.id 
     1357            d_group_id = self.data.group_id 
     1358            act_ctrl = event.GetEventObject() 
     1359            wx.PostEvent(self.parent.parent,  
     1360                         PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id,  
     1361                                     group_id=d_group_id, leftdown=is_click, 
     1362                                     active=act_ctrl)) 
     1363             
     1364    def on_qrange_text(self, event): 
     1365        """ 
     1366        #On q range value updated. DO not combine with qrange_click(). 
     1367        """ 
     1368        if event != None: 
     1369            event.Skip() 
     1370        if self.data.__class__.__name__ == "Data2D": 
     1371            return 
     1372        act_ctrl = event.GetEventObject() 
     1373        d_id = self.data.id 
     1374        d_group_id = self.data.group_id 
     1375        wx.PostEvent(self.parent.parent,  
     1376                     PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id,  
     1377                                     group_id=d_group_id, leftdown=False,  
     1378                                     active=act_ctrl)) 
     1379        self._validate_qrange(self.qmin, self.qmax) 
     1380     
     1381    def on_key(self, event):    
     1382        """ 
     1383        On Key down 
     1384        """ 
     1385        event.Skip() 
     1386        if self.data.__class__.__name__ == "Data2D": 
     1387            return 
     1388        ctrl = event.GetEventObject() 
     1389        try: 
     1390            x_data = float(ctrl.GetValue()) 
     1391        except: 
     1392            return  
     1393        key = event.GetKeyCode() 
     1394        length = len(self.data.x) 
     1395        indx = (numpy.abs(self.data.x - x_data)).argmin() 
     1396        #return array.flat[idx] 
     1397        if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: 
     1398            indx += 1 
     1399            if indx >= length: 
     1400                indx = length - 1 
     1401        elif key == wx.WXK_PAGEDOWN or key == wx.WXK_NUMPAD_PAGEDOWN: 
     1402            indx -= 1 
     1403            if indx < 0: 
     1404                indx = 0 
     1405        else: 
     1406            return 
     1407        ctrl.SetValue(str(self.data.x[indx])) 
     1408        self._validate_qrange(self.qmin, self.qmax) 
     1409                
    13211410    def _onQrangeEnter(self, event): 
    13221411        """ 
     
    17991888                self._set_bookmark_flag(not self.batch_on) 
    18001889                self._keep.Enable(not self.batch_on) 
    1801                  
    1802             self._set_save_flag(True) 
    1803             self._set_preview_flag(True) 
     1890            if self.data.is_data:     
     1891                self._set_save_flag(True) 
     1892                self._set_preview_flag(True) 
    18041893 
    18051894            self._set_smear(data) 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter1D.py

    r318b5bbb r3e001f9  
    9393        ## Default locations 
    9494        #self._default_save_location = os.getcwd()  
    95         self.size = None        
     95        self.size = None   
     96        self.vl_ind = 0      
    9697        ## Graph         
    9798        #self.graph = Graph() 
     
    99100        self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    100101        self.graph.render(self) 
     102        self.cursor_id = None 
    101103         
    102104        # In resizing event 
     
    217219        wx.CallAfter(self.parent.disable_app_menu,self) 
    218220         
     221    def on_plot_qrange(self, event=None): 
     222        """ 
     223        On Qmin Qmax vertical line event 
     224        """ 
     225        if event == None: 
     226            return 
     227        event.Skip()  
     228        active_ctrl = event.active 
     229        if active_ctrl == None: 
     230            return 
     231        if event.id in self.plots.keys(): 
     232            # Set line position and color 
     233            colors = ['red', 'purple'] 
     234            self.cursor_id = event.id 
     235            ctrl = event.ctrl 
     236            if self.ly == None: 
     237                self.ly = [] 
     238                for ind_ly in range(len(colors)): 
     239                    self.ly.append(self.subplot.axvline(color=colors[ind_ly],  
     240                                                        lw=2.5, alpha=0.7)) 
     241                    self.ly[ind_ly].set_rasterized(True)       
     242            try: 
     243                # Display x,y in the status bar if possible 
     244                xval = float(active_ctrl.GetValue()) 
     245                position = self.get_data_xy_vals(xval) 
     246                if position != None: 
     247                    wx.PostEvent(self.parent, StatusEvent(status=position)) 
     248            except: 
     249                pass 
     250            if not event.leftdown: 
     251                # text event  
     252                try: 
     253                    is_moved = False 
     254                    for idx in range(len(self.ly)): 
     255                        val = float(ctrl[idx].GetValue()) 
     256                        # check if vline moved 
     257                        if self.ly[idx].get_xdata() != val: 
     258                            self.ly[idx].set_xdata(val) 
     259                            is_moved = True 
     260                    if is_moved: 
     261                        self.canvas.draw()  
     262                except: 
     263                    pass 
     264                event.Skip()  
     265                return 
     266            self.q_ctrl = ctrl 
     267            try: 
     268                pos_x_min = float(self.q_ctrl[0].GetValue()) 
     269            except: 
     270                pos_x_min = xmin 
     271            try: 
     272                pos_x_max = float(self.q_ctrl[1].GetValue()) 
     273            except: 
     274                pos_x_max = xmax 
     275            pos_x = [pos_x_min, pos_x_max] 
     276            for ind_ly in range(len(colors)): 
     277                self.ly[ind_ly].set_color(colors[ind_ly]) 
     278                self.ly[ind_ly].set_xdata(pos_x[ind_ly]) 
     279            self.canvas.draw() 
     280        else: 
     281            self.q_ctrl = None 
     282     
     283    def get_data_xy_vals(self, xval): 
     284        """ 
     285        Get x, y data values near x = x_val 
     286        """ 
     287        try: 
     288            x_data = self.plots[self.cursor_id].x 
     289            y_data = self.plots[self.cursor_id].y 
     290            indx = self._find_nearest(x_data, xval) 
     291            pos_x = x_data[indx] 
     292            pos_y = y_data[indx] 
     293            position = str(pos_x), str(pos_y) 
     294            return position 
     295        except: 
     296            return None 
     297            
     298    def _find_nearest(self, array, value): 
     299        """ 
     300        Find and return the nearest value in array to the value. 
     301        Used in cusor_line() 
     302        :Param array: numpy array 
     303        :Param value: float 
     304        """ 
     305        idx = (numpy.abs(array - value)).argmin() 
     306        return int(idx)#array.flat[idx] 
     307     
     308    def _check_line_positions(self, pos_x=None, nop=None): 
     309        """ 
     310        Check vertical line positions 
     311        :Param pos_x: position of the current line [float] 
     312        :Param nop: number of plots [int] 
     313        """ 
     314        ly = self.ly 
     315        ly0x = ly[0].get_xdata() 
     316        ly1x = ly[1].get_xdata() 
     317        self.q_ctrl[0].SetBackgroundColour('white') 
     318        self.q_ctrl[1].SetBackgroundColour('white') 
     319        if ly0x >= ly1x: 
     320            if self.vl_ind == 0: 
     321                ly[1].set_xdata(pos_x) 
     322                ly[1].set_zorder(nop) 
     323                self.q_ctrl[1].SetValue(str(pos_x)) 
     324                self.q_ctrl[0].SetBackgroundColour('pink') 
     325            elif self.vl_ind == 1: 
     326                ly[0].set_xdata(pos_x) 
     327                ly[0].set_zorder(nop) 
     328                self.q_ctrl[0].SetValue(str(pos_x)) 
     329                self.q_ctrl[1].SetBackgroundColour('pink') 
     330                 
     331    def _get_cusor_lines(self, event): 
     332        """ 
     333        Revmove or switch cursor line if drawn 
     334        :Param event: LeftClick mouse event 
     335        """   
     336        ax = event.inaxes 
     337        dclick = event.action == 'dclick' 
     338        if ax == None or dclick: 
     339            # remove the vline 
     340            self._check_zoom_plot() 
     341            self.canvas.draw() 
     342            self.q_ctrl = None 
     343            return  
     344        if self.ly != None and event.xdata != None: 
     345            # Selecting a new line if cursor lines are displayed already 
     346            dqmin = math.fabs(event.xdata - self.ly[0].get_xdata()) 
     347            dqmax = math.fabs(event.xdata - self.ly[1].get_xdata()) 
     348            is_qmax = dqmin > dqmax 
     349            if is_qmax: 
     350                self.vl_ind = 1 
     351            else: 
     352                self.vl_ind = 0  
     353                      
     354    def cusor_line(self, event): 
     355        """ 
     356        Move the cursor line to write Q range 
     357        """ 
     358        if self.q_ctrl == None: 
     359            return 
     360        #release a q range vline 
     361        if self.ly != None and not self.leftdown: 
     362            for ly in self.ly: 
     363                ly.set_alpha(0.7) 
     364                self.canvas.draw() 
     365            return 
     366        ax = event.inaxes 
     367        if ax == None or not hasattr(event, 'action'): 
     368            return 
     369        end_drag = event.action != 'drag' and event.xdata != None 
     370        nop = len(self.plots) 
     371        pos_x, pos_y = float(event.xdata), float(event.ydata) 
     372        try: 
     373            ly = self.ly 
     374            ly0x = ly[0].get_xdata() 
     375            ly1x = ly[1].get_xdata() 
     376            if ly0x == ly1x: 
     377                if ly[0].get_zorder() > ly[1].get_zorder(): 
     378                    self.vl_ind = 0 
     379                else: 
     380                    self.vl_ind = 1 
     381            vl_ind = self.vl_ind 
     382            x_data = self.plots[self.cursor_id].x 
     383            y_data = self.plots[self.cursor_id].y 
     384            xmin = x_data.min() 
     385            xmax = x_data.max() 
     386            indx = self._find_nearest(x_data, pos_x) 
     387            #pos_x = self._find_nearest(x_data, pos_x) 
     388            #indx = int(numpy.searchsorted(x_data, [pos_x])[0]) 
     389            # Need to hold LeftButton to drag 
     390            if end_drag: 
     391                if event.button: 
     392                    self._check_line_positions(pos_x, nop) 
     393                return    
     394            if indx >= len(x_data): 
     395                indx = len(x_data) - 1 
     396            pos_x = x_data[indx] 
     397            pos_y = y_data[indx] 
     398            if xmin == ly1x: 
     399                vl_ind = 1 
     400            elif xmax == ly0x: 
     401                vl_ind = 0 
     402            else: 
     403                ly[vl_ind].set_xdata(pos_x) 
     404                ly[vl_ind].set_zorder(nop + 1) 
     405                self._check_line_positions(pos_x, nop) 
     406            ly[vl_ind].set_xdata(pos_x) 
     407            ly[vl_ind].set_alpha(1.0) 
     408            ly[vl_ind].set_zorder(nop + 1) 
     409            self.canvas.draw() 
     410            self.q_ctrl[vl_ind].SetValue(str(pos_x)) 
     411        except: 
     412            pass 
     413                
    219414    def set_resizing(self, resizing=False): 
    220415        """ 
     
    340535        Display the position of the mouse on the statusbar 
    341536        """ 
     537        self._get_cusor_lines(event) 
     538        ax = event.inaxes 
    342539        PlotPanel.onLeftDown(self, event) 
    343         ax = event.inaxes 
     540 
    344541        if ax != None: 
    345542            try: 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter2D.py

    r657e52c r3e001f9  
    142142        self.default_zmin_ctl = self.zmin_2D 
    143143        self.default_zmax_ctl = self.zmax_2D 
    144         
     144 
     145    def on_plot_qrange(self, event=None): 
     146        """ 
     147        On Qmin Qmax vertical line event 
     148        """ 
     149        # Not implemented 
     150        if event == None: 
     151            return 
     152        event.Skip()  
     153                        
    145154    def onLeftDown(self, event):  
    146155        """ 
  • sansguiframe/src/sans/guiframe/local_perspectives/plotting/plotting.py

    r4752c31 r3e001f9  
    1515import sys 
    1616from sans.guiframe.events import EVT_NEW_PLOT 
     17from sans.guiframe.events import EVT_PLOT_QRANGE 
    1718from sans.guiframe.events import StatusEvent  
    1819from sans.guiframe.events import DeletePlotPanelEvent 
     
    8283        # Connect to plotting events 
    8384        self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event) 
     85        self.parent.Bind(EVT_PLOT_QRANGE, self._on_plot_qrange) 
    8486        # We have no initial panels for this plug-in 
    8587        return [] 
    86     
     88     
     89    def _on_plot_qrange(self, event= None): 
     90        """ 
     91        On Qmin Qmax vertical line event 
     92        """ 
     93        if event == None: 
     94            return 
     95        if event.id in self.plot_panels.keys(): 
     96            panel = self.plot_panels[event.id] 
     97        elif event.group_id in self.plot_panels.keys(): 
     98            panel = self.plot_panels[event.group_id] 
     99        else: 
     100            return 
     101        panel.on_plot_qrange(event) 
     102             
    87103    def _on_show_panel(self, event): 
    88104        """show plug-in panel""" 
Note: See TracChangeset for help on using the changeset viewer.