source: sasview/guiframe/local_perspectives/plotting/slicerpanel.py @ ffd23b5

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 ffd23b5 was aa1b747, checked in by Gervaise Alina <gervyh@…>, 15 years ago

worling on slicer panel

  • Property mode set to 100644
File size: 4.2 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, *args, **kwargs):
23        wx.Panel.__init__(self, parent, *args, **kwargs)
24        self.params = {}
25        self.parent = parent
26        self.type = None
27        self.listeners = []
28        self.parameters = []
29        self.bck = wx.GridBagSizer(5,5)
30        self.SetSizer(self.bck)
31               
32        title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)
33        self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
34       
35        # Bindings
36        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER)
37        self.parent.Bind(EVT_SLICER_PARS, self.onParamChange)
38
39    def onEVT_SLICER(self, event):
40        """
41            Process EVT_SLICER events
42            When the slicer changes, update the panel
43           
44            @param event: EVT_SLICER event
45        """
46        event.Skip()
47        if event.obj_class==None:
48            self.set_slicer(None, None)
49           
50        else:
51            print "when here not empty event",event.type, event.params
52            self.set_slicer(event.type, event.params)
53       
54    def set_slicer(self, type, params):
55        """
56            Rebuild the panel
57        """
58        self.bck.Clear(True) 
59        self.type = type 
60       
61        if type==None:
62            #title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)
63            #self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
64
65        #else:
66            title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT)
67            self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)
68           
69            n = 1
70            self.parameters = []
71            #params = slicer.get_params()
72            keys = params.keys()
73            keys.sort()
74           
75            for item in keys:
76                n += 1
77                text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT)
78                self.bck.Add(text, (n-1,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15)
79                ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER)
80               
81                ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item)
82               
83               
84                ctl.SetValue(str(params[item]))
85                self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter)
86                ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter)
87                self.parameters.append([item, ctl])
88                self.bck.Add(ctl, (n-1,1), flag=wx.TOP|wx.BOTTOM, border = 0)
89
90        self.bck.Layout()
91        self.bck.Fit(self)
92        self.parent.GetSizer().Layout()
93
94    def onParamChange(self, evt):
95        evt.Skip()
96        if evt.type == "UPDATE":
97            for item in self.parameters:             
98                if item[0] in evt.params:
99                    item[1].SetValue("%-5.3g" %evt.params[item[0]])
100                    item[1].Refresh()
101       
102    def onTextEnter(self, evt): 
103        """
104            Parameters have changed
105        """ 
106        params = {}
107        has_error = False
108        for item in self.parameters:
109            try:
110                params[item[0]] = float(item[1].GetValue())
111                item[1].SetBackgroundColour(
112                        wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
113                item[1].Refresh()
114            except:
115                has_error = True
116                item[1].SetBackgroundColour("pink")
117                item[1].Refresh()
118
119        if has_error==False:
120            # Post parameter event
121            event = SlicerParameterEvent(type=self.type, params=params)
122            wx.PostEvent(self.parent, event)
123       
Note: See TracBrowser for help on using the repository browser.