source: sasview/src/sas/guiframe/local_perspectives/plotting/slicerpanel.py @ c039589

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since c039589 was 27ab091, checked in by krzywon, 10 years ago

Fixed the issue outlined in trac ticket #349. The box sum panel did not
seem to allow focus when changing the values for the sum from the panel.
A simple evt.Skip() was all that was necessary.

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[d955bf19]1
[aa1b747]2
3import wx
4import wx.lib.newevent
[32c0841]5#from copy import deepcopy
[79492222]6from sas.guiframe.utils import format_number
7from sas.guiframe.events import SlicerParameterEvent
8from sas.guiframe.events import EVT_SLICER_PARS
9from sas.guiframe.events import EVT_SLICER
[0d9dae8]10
[79492222]11from sas.guiframe.panel_base import PanelBase
[aa1b747]12
[691643c]13class SlicerPanel(wx.Panel, PanelBase):
[d955bf19]14    """
15    Panel class to show the slicer parameters
16    """
[aa1b747]17    #TODO: show units
18    #TODO: order parameters properly
[27ab091]19    ## Internal name for the AUI manager
[aa1b747]20    window_name = "Slicer panel"
21    ## Title to appear on top of the window
22    window_caption = "Slicer Panel"
23    CENTER_PANE = False
24   
[32c0841]25    def __init__(self, parent, id=-1, type=None, base=None,
26                params=None, *args, **kwargs):
27        wx.Panel.__init__(self, parent, id, *args, **kwargs)
[691643c]28        PanelBase.__init__(self)
[12aa9b5]29        ##  Initialization of the class     
[32c0841]30        self.base = base
31        if params is None:
32            params = {}
[54cc36a]33        self.params = params
[ae84427]34        self.parent = base.parent
35        self.frame = None
[54cc36a]36        self.type = type
[aa1b747]37        self.listeners = []
38        self.parameters = []
[32c0841]39        self.bck = wx.GridBagSizer(5, 5)
[aa1b747]40        self.SetSizer(self.bck)
[32c0841]41        if type == None and params == None: 
42            label = "Right-click on 2D plot for slicer options" 
43            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT)
44            self.bck.Add(title, (0, 0), (1, 2), 
45                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
[54cc36a]46        else:
[32c0841]47            self.set_slicer(type, params)
[12aa9b5]48        ## Bindings
[aa1b747]49        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER)
50        self.parent.Bind(EVT_SLICER_PARS, self.onParamChange)
51
52    def onEVT_SLICER(self, event):
53        """
[d955bf19]54        Process EVT_SLICER events
55        When the slicer changes, update the panel
56       
57        :param event: EVT_SLICER event
58       
[aa1b747]59        """
60        event.Skip()
[32c0841]61        if event.obj_class == None:
[12aa9b5]62            self.set_slicer(None, None) 
[aa1b747]63        else:
64            self.set_slicer(event.type, event.params)
65       
66    def set_slicer(self, type, params):
67        """
[d955bf19]68        Rebuild the panel
[aa1b747]69        """
70        self.bck.Clear(True) 
71        self.type = type 
[32c0841]72        if type == None:
73            label = "Right-click on 2D plot for slicer options"
74            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT)
75            self.bck.Add(title, (0, 0), (1, 2), 
76                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
[54cc36a]77        else:
[27ab091]78            title_text = str(type) + "Parameters"
79            title = wx.StaticText(self, -1, title_text, 
[32c0841]80                                  style=wx.ALIGN_LEFT)
81            self.bck.Add(title, (0, 0), (1, 2), 
82                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
[aa1b747]83            n = 1
84            self.parameters = []
85            keys = params.keys()
86            keys.sort()
87            for item in keys:
[d555416]88                if not item.lower() in ["num_points", "avg", "avg_error", "sum",
89                                         "sum_error"]:
[0d9dae8]90                    n += 1
91                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
[32c0841]92                    self.bck.Add(text, (n-1, 0), 
93                            flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
94                    ctl = wx.TextCtrl(self, -1, size=(80, 20), 
95                                      style=wx.TE_PROCESS_ENTER)
[88989768]96                    hint_msg = "Modify the value of %s to change " % item
97                    hint_msg += "the 2D slicer"
[32c0841]98                    ctl.SetToolTipString(hint_msg)
[0d9dae8]99                    ctl.SetValue(str(format_number(params[item])))
100                    self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter)
[37f487e]101                    ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus)
[0d9dae8]102                    ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter)
103                    self.parameters.append([item, ctl])
[32c0841]104                    self.bck.Add(ctl, (n-1, 1), flag=wx.TOP|wx.BOTTOM, border=0)
[0d9dae8]105            for item in keys:
[d555416]106                if  item.lower() in ["num_points", "avg", "avg_error", "sum",
107                                      "sum_error"]:
[0d9dae8]108                    n += 1
[32c0841]109                    text = wx.StaticText(self, -1, item + ": ", 
110                                         style=wx.ALIGN_LEFT)
111                    self.bck.Add(text, (n-1, 0), 
112                                 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 
113                                 border=15)
114                    ctl = wx.StaticText(self, -1, 
115                                        str(format_number(params[item])),
116                                        style=wx.ALIGN_LEFT)
[0d9dae8]117                    ctl.SetToolTipString("Result %s" % item)
[32c0841]118                    self.bck.Add(ctl, (n-1, 1), flag=wx.TOP|wx.BOTTOM, border=0)       
[aa1b747]119        self.bck.Layout()
[ddd864e]120        #self.bck.Fit(self)
121        self.Layout()
[ae84427]122        psizer = self.parent.GetSizer()
123        if psizer != None:
124            psizer.Layout()
[12aa9b5]125       
[37f487e]126    def onSetFocus(self, evt):
127        """
[27ab091]128        Highlight the txtcrtl
[37f487e]129        """
[27ab091]130        evt.Skip()
[37f487e]131        # Get a handle to the TextCtrl
132        widget = evt.GetEventObject()
133        # Select the whole control, after this event resolves
[32c0841]134        wx.CallAfter(widget.SetSelection, -1, -1)
[37f487e]135        return
136   
[aa1b747]137    def onParamChange(self, evt):
[12aa9b5]138        """
[d955bf19]139        Receive and event and reset the text field contained in self.parameters
[12aa9b5]140           
141        """
[54cc36a]142        evt.Skip()
143        for item in self.parameters:             
144            if item[0] in evt.params:
[0d9dae8]145                item[1].SetValue(format_number(evt.params[item[0]]))
[54cc36a]146                item[1].Refresh()
[0d9dae8]147   
[aa1b747]148    def onTextEnter(self, evt): 
149        """
[d955bf19]150        Parameters have changed
[27ab091]151        """
152        evt.Skip()
[aa1b747]153        params = {}
154        has_error = False
155        for item in self.parameters:
156            try:
157                params[item[0]] = float(item[1].GetValue())
158                item[1].SetBackgroundColour(
159                        wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
160                item[1].Refresh()
161            except:
162                has_error = True
163                item[1].SetBackgroundColour("pink")
164                item[1].Refresh()
[1f3655a]165           
[32c0841]166        if has_error == False:
[aa1b747]167            # Post parameter event
[12aa9b5]168            ## base is guiframe is this case
[aa1b747]169            event = SlicerParameterEvent(type=self.type, params=params)
[0d9dae8]170            wx.PostEvent(self.base, event)
[ae84427]171
172    def on_close(self, event):
173        """
174        On Close Event
175        """
176        ID = self.uid
177        self.parent.delete_panel(ID)           
178        self.frame.Destroy()
Note: See TracBrowser for help on using the repository browser.