source: sasview/guiframe/local_perspectives/plotting/SlicerParameters.py @ 4e9583c

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 4e9583c was d955bf19, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on documentation

  • Property mode set to 100644
File size: 5.0 KB
Line 
1
2
3import wx
4import wx.lib.newevent
5from copy import deepcopy
6
7from sans.guiframe.utils import format_number
8from sans.guicomm.events import EVT_SLICER,EVT_SLICER_PARS,SlicerParameterEvent
9
10class SlicerParameterPanel(wx.Dialog):
11    """
12    Panel class to show the slicer parameters
13    """
14    #TODO: show units
15    #TODO: order parameters properly
16   
17    def __init__(self, parent, *args, **kwargs):
18        wx.Dialog.__init__(self, parent, *args, **kwargs)
19        """
20        Dialog window that allow to edit parameters slicer
21        by entering new values
22        """
23        self.params = {}
24        self.parent = parent
25        self.type = None
26        self.listeners = []
27        self.parameters = []
28        self.bck = wx.GridBagSizer(5,5)
29        self.SetSizer(self.bck)
30               
31        title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)
32        self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
33       
34        # Bindings
35        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER)
36        self.parent.Bind(EVT_SLICER_PARS, self.onParamChange)
37
38    def onEVT_SLICER(self, event):
39        """
40        Process EVT_SLICER events
41        When the slicer changes, update the panel
42       
43        :param event: EVT_SLICER event
44        """
45        event.Skip()
46        if event.obj_class==None:
47            self.set_slicer(None, None)
48        else:
49            self.set_slicer(event.type, event.params)
50       
51    def set_slicer(self, type, params):
52        """
53        Rebuild the panel
54        """
55        self.bck.Clear(True) 
56        self.type = type 
57       
58        if type==None:
59            title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)
60            self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
61
62        else:
63            title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT)
64            self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
65            ix = 0
66            iy = 0
67            self.parameters = []
68            keys = params.keys()
69            keys.sort()
70           
71            for item in keys:
72                iy += 1
73                ix = 0
74                if not item in ["count","errors"]:
75                   
76                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
77                    self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
78                    ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER)
79                   
80                    ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item)
81                   
82                    ix = 1
83                    ctl.SetValue(format_number(str(params[item])))
84                    self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter)
85                    ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter)
86                    self.parameters.append([item, ctl])
87                    self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
88                   
89                    ix =3
90                    self.bck.Add((20,20), (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
91                else:
92                    text = wx.StaticText(self, -1, item+ " : ", style=wx.ALIGN_LEFT)
93                    self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
94                    ctl =wx.StaticText(self, -1, format_number(str(params[item])), style=wx.ALIGN_LEFT)
95                    ix =1
96                    self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
97            iy +=1
98            ix = 1
99            self.bck.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
100        self.bck.Layout()
101        self.bck.Fit(self)
102        self.parent.GetSizer().Layout()
103
104    def onParamChange(self, evt):
105        """
106        receive an event end reset value text fields
107        inside self.parameters
108        """
109        evt.Skip()
110        if evt.type == "UPDATE":
111            for item in self.parameters:             
112                if item[0] in evt.params:
113                    item[1].SetValue("%-5.3g" %evt.params[item[0]])
114                    item[1].Refresh()
115       
116    def onTextEnter(self, evt): 
117        """
118        Parameters have changed
119        """ 
120        params = {}
121        has_error = False
122        for item in self.parameters:
123            try:
124                params[item[0]] = float(item[1].GetValue())
125                item[1].SetBackgroundColour(
126                        wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
127                item[1].Refresh()
128            except:
129                has_error = True
130                item[1].SetBackgroundColour("pink")
131                item[1].Refresh()
132
133        if has_error==False:
134            # Post parameter event
135            ##parent hier is plotter2D
136            event = SlicerParameterEvent(type=self.type, params=params)
137            wx.PostEvent(self.parent, event)
138       
Note: See TracBrowser for help on using the repository browser.