source: sasview/guiframe/local_perspectives/plotting/slicerpanel.py @ 1f3655a

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 1f3655a was 1f3655a, checked in by Gervaise Alina <gervyh@…>, 16 years ago

disable controlbox for slicerpanel and boxsum limits changed

  • Property mode set to 100644
File size: 4.9 KB
Line 
1"""
2    Panel class to show the slicer parameters
3"""
4
5import wx
6import wx.lib.newevent
7from copy import deepcopy
8
9(SlicerEvent, EVT_SLICER)   = wx.lib.newevent.NewEvent()
10(SlicerParameterEvent, EVT_SLICER_PARS)   = wx.lib.newevent.NewEvent()
11
12class SlicerPanel(wx.Panel):
13    #TODO: show units
14    #TODO: order parameters properly
15     ## Internal name for the AUI manager
16    window_name = "Slicer panel"
17    ## Title to appear on top of the window
18    window_caption = "Slicer Panel"
19   
20    CENTER_PANE = False
21   
22    def __init__(self, parent,id=-1,type=None, params={}, *args, **kwargs):
23        wx.Panel.__init__(self, parent,id, *args, **kwargs)
24        print "panel created"
25        self.params = params
26        self.parent = parent
27        self.type = type
28        self.listeners = []
29        self.parameters = []
30        self.bck = wx.GridBagSizer(5,5)
31        self.SetSizer(self.bck)
32        if type==None and params==None:     
33            title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)
34            self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
35        else:
36            self.set_slicer( type, params)
37        # Bindings
38        #self.parent.Bind(EVT_SLICER, self.onEVT_SLICER)
39        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER)
40        self.parent.Bind(EVT_SLICER_PARS, self.onParamChange)
41
42    def onEVT_SLICER(self, event):
43        """
44            Process EVT_SLICER events
45            When the slicer changes, update the panel
46           
47            @param event: EVT_SLICER event
48        """
49        print "went here panel"
50        event.Skip()
51        if event.obj_class==None:
52            self.set_slicer(None, None)
53           
54        else:
55            print "when here not empty event",event.type, event.params
56            self.set_slicer(event.type, event.params)
57       
58    def set_slicer(self, type, params):
59        """
60            Rebuild the panel
61        """
62        self.bck.Clear(True) 
63        self.type = type 
64        print "in set slicer", type, params
65        if type==None:
66            title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)
67            self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
68
69        else:
70            title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT)
71            self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
72           
73            n = 1
74            self.parameters = []
75            #params = slicer.get_params()
76            keys = params.keys()
77            keys.sort()
78           
79            for item in keys:
80                n += 1
81                text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
82                self.bck.Add(text, (n-1,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15)
83                ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER)
84               
85                ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item)
86               
87               
88                ctl.SetValue(str(params[item]))
89                ctl.Disable()
90                self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter)
91                ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter)
92                self.parameters.append([item, ctl])
93                self.bck.Add(ctl, (n-1,1), flag=wx.TOP|wx.BOTTOM, border = 0)
94
95        self.bck.Layout()
96        self.bck.Fit(self)
97        self.parent.GetSizer().Layout()
98    def onParamChange(self, evt):
99        print "parameters changed"
100        evt.Skip()
101        #if evt.type == "UPDATE":
102        for item in self.parameters:             
103            if item[0] in evt.params:
104                item[1].SetValue("%-5.3g" %evt.params[item[0]])
105                item[1].Refresh()
106       
107
108    def old_onParamChange(self, evt):
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            print "post new param"
136            event = SlicerParameterEvent(type=self.type, params=params)
137            wx.PostEvent(self.parent, event)
138            print "self parent ", self.parent
139       
Note: See TracBrowser for help on using the repository browser.