Changeset 9ff861b in sasview for prview/perspectives/pr


Ignore:
Timestamp:
Aug 1, 2009 8:29:38 AM (15 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
e082e2c
Parents:
6dc9ad8
Message:

prview: improved text control look&feel, added scrolled panel, got rid of old code.

Location:
prview/perspectives/pr
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • prview/perspectives/pr/explore_dialog.py

    r96c430d r9ff861b  
    2727from danse.common.plottools.plottables import Graph 
    2828 
     29from pr_widgets import PrTextCtrl 
     30 
    2931# Default number of points on the output plot 
    3032DEFAULT_NPTS = 10 
     
    148150         
    149151        # Control for number of points 
    150         self.npts_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     152        self.npts_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    151153        # Control for the minimum value of D_max 
    152         self.dmin_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     154        self.dmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    153155        # Control for the maximum value of D_max 
    154         self.dmax_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     156        self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    155157 
    156158        # Output selection box for the y axis 
  • prview/perspectives/pr/inversion_panel.py

    r0ccd214 r9ff861b  
    99import sys 
    1010import logging 
     11from wx.lib.scrolledpanel import ScrolledPanel 
    1112from sans.guicomm.events import StatusEvent     
    1213from inversion_state import InversionState 
    13  
    14 class InversionDlg(wx.Dialog): 
    15     def __init__(self, parent, id, title, plots, file=False, pars=True): 
    16          
    17         # Estimate size 
    18         nplots = len(plots) 
    19         # y size for data set only 
    20         ysize  = 110 + nplots*20 
    21         # y size including parameters 
    22         if pars: 
    23             ysize  += 90 
    24          
    25         wx.Dialog.__init__(self, parent, id, title, size=(250, ysize)) 
    26         self.SetTitle(title) 
    27  
    28         # Data set 
    29         self.datasets = InversionPanel(self, -1, plots) 
    30         vbox = wx.BoxSizer(wx.VERTICAL) 
    31  
    32         vbox.Add(self.datasets) 
    33  
    34         # Parameters 
    35         self.pars_flag = False 
    36         if pars==True: 
    37             self.pars_flag = True 
    38             self.pars = ParsDialog(self, -1, file=file) 
    39             vbox.Add(self.pars) 
    40  
    41         static_line = wx.StaticLine(self, -1) 
    42         vbox.Add(static_line, 0, wx.EXPAND, 0) 
    43          
    44         button_OK = wx.Button(self, wx.ID_OK, "OK") 
    45         button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
    46          
    47         sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    48         sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    49         sizer_button.Add(button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
    50         sizer_button.Add(button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)         
    51         vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
    52  
    53         self.SetSizer(vbox) 
    54         self.SetAutoLayout(True) 
    55          
    56         self.Layout() 
    57         self.Centre() 
    58  
    59     def get_content(self): 
    60         dataset = self.datasets.get_selected() 
    61         if self.pars_flag: 
    62             nfunc, alpha, dmax, file = self.pars.getContent() 
    63             return dataset, nfunc, alpha, dmax 
    64         else: 
    65             return dataset 
    66      
    67     def set_content(self, dataset, nfunc, alpha, dmax): 
    68         if not dataset==None and dataset in self.datasets.radio_buttons.keys(): 
    69             self.datasets.radio_buttons[dataset].SetValue(True) 
    70         if self.pars_flag: 
    71             self.pars.setContent(nfunc, alpha, dmax, None) 
    72  
    73 class InversionPanel(wx.Panel): 
    74      
    75     def __init__(self, parent, id = -1, plots = None, **kwargs): 
    76         wx.Panel.__init__(self, parent, id = id, **kwargs) 
    77          
    78         self.plots = plots 
    79         self.radio_buttons = {} 
    80          
    81         self._do_layout() 
    82          
    83     def _do_layout(self): 
    84         panel = wx.Panel(self, -1) 
    85         vbox = wx.BoxSizer(wx.VERTICAL) 
    86  
    87         ysize = 30+20*len(self.plots) 
    88         wx.StaticBox(panel, -1, 'Choose a data set', (5, 5), (230, ysize)) 
    89         ypos = 30 
    90         self.radio_buttons = {} 
    91         for item in self.plots.keys(): 
    92             self.radio_buttons[self.plots[item].name] = wx.RadioButton(panel, -1, self.plots[item].name, (15, ypos)) 
    93             ypos += 20 
    94          
    95         vbox.Add(panel) 
    96  
    97         self.SetSizer(vbox) 
    98          
    99     def get_selected(self): 
    100         for item in self.radio_buttons: 
    101             if self.radio_buttons[item].GetValue(): 
    102                 return item 
    103         return None 
    104  
    105 class InversionControl(wx.Panel): 
     14from pr_widgets import PrTextCtrl, DataFileTextCtrl, OutputTextCtrl 
     15 
     16 
     17 
     18class InversionControl(ScrolledPanel): 
    10619    window_name = 'pr_control' 
    10720    window_caption = "P(r) control panel" 
     
    11427     
    11528    def __init__(self, parent, id = -1, plots = None, standalone=False, **kwargs): 
    116         wx.Panel.__init__(self, parent, id = id, **kwargs) 
     29        ScrolledPanel.__init__(self, parent, id = id, **kwargs) 
     30        self.SetupScrolling() 
    11731         
    11832        self.plots = plots 
     
    451365        pars_sizer.Add(self.file_radio, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    452366         
    453         self.plot_data = wx.TextCtrl(self, -1, size=(220,20)) 
    454         self.plot_data.SetEditable(False) 
    455         pars_sizer.Add(self.plot_data, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     367        self.plot_data = DataFileTextCtrl(self, -1, size=(260,20)) 
     368         
     369        pars_sizer.Add(self.plot_data, (iy,1), (1,1), wx.EXPAND|wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 15) 
    456370         
    457371        self.bck_chk = wx.CheckBox(self, -1, "Estimate background level") 
     
    475389            #label_sunits1 = wx.StaticText(self, -1, "[A^(-1)]") 
    476390            label_sunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55,20)) 
    477             self.sheight_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    478             self.swidth_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     391            self.sheight_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     392            self.swidth_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    479393            self.sheight_ctl.SetToolTipString("Enter slit height in units of Q or leave blank.") 
    480394            self.swidth_ctl.SetToolTipString("Enter slit width in units of Q or leave blank.") 
     
    506420        #label_qunits1 = wx.StaticText(self, -1, "[A^(-1)]") 
    507421        label_qunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55,20)) 
    508         self.qmin_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    509         self.qmax_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     422        self.qmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     423        self.qmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    510424        self.qmin_ctl.SetToolTipString("Select a lower bound for Q or leave blank.") 
    511425        self.qmax_ctl.SetToolTipString("Select an upper bound for Q or leave blank.") 
     
    550464        #self.label_sugg.Hide() 
    551465         
    552         self.nfunc_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     466        self.nfunc_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    553467        self.nfunc_ctl.SetToolTipString("Number of terms in the expansion.") 
    554         self.alpha_ctl = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     468        self.alpha_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    555469        self.alpha_ctl.SetToolTipString("Control parameter for the size of the regularization term.") 
    556         self.dmax_ctl  = wx.TextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
     470        self.dmax_ctl  = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 
    557471        self.dmax_ctl.SetToolTipString("Maximum distance between any two points in the system.") 
    558472        id = wx.NewId() 
     
    618532        label_bck      = wx.StaticText(self, -1, "Background") 
    619533        label_bck_unit = wx.StaticText(self, -1, "[A^(-1)]") 
    620         self.rg_ctl    = wx.TextCtrl(self, -1, size=(60,20)) 
    621         self.rg_ctl.SetEditable(False) 
     534        self.rg_ctl    = OutputTextCtrl(self, -1, size=(60,20)) 
    622535        self.rg_ctl.SetToolTipString("Radius of gyration for the computed P(r).") 
    623         self.iq0_ctl   = wx.TextCtrl(self, -1, size=(60,20)) 
    624         self.iq0_ctl.SetEditable(False) 
     536        self.iq0_ctl   = OutputTextCtrl(self, -1, size=(60,20)) 
    625537        self.iq0_ctl.SetToolTipString("Scattering intensity at Q=0 for the computed P(r).") 
    626         self.bck_ctl   = wx.TextCtrl(self, -1, size=(60,20)) 
    627         self.bck_ctl.SetEditable(False) 
     538        self.bck_ctl   = OutputTextCtrl(self, -1, size=(60,20)) 
    628539        self.bck_ctl.SetToolTipString("Value of estimated constant background.") 
    629540         
     
    636547        label_pos_err = wx.StaticText(self, -1, "1-sigma positive fraction") 
    637548         
    638         self.time_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    639         self.time_ctl.SetEditable(False) 
     549        self.time_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
    640550        self.time_ctl.SetToolTipString("Computation time for the last inversion, in seconds.") 
    641551         
    642         self.chi2_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    643         self.chi2_ctl.SetEditable(False) 
     552        self.chi2_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
    644553        self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") 
    645554         
    646555        # Oscillation parameter 
    647         self.osc_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    648         self.osc_ctl.SetEditable(False) 
     556        self.osc_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
    649557        self.osc_ctl.SetToolTipString("Oscillation parameter. P(r) for a sphere has an oscillation parameter of 1.1.") 
    650558         
    651559        # Positive fraction figure of merit 
    652         self.pos_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    653         self.pos_ctl.SetEditable(False) 
     560        self.pos_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
    654561        self.pos_ctl.SetToolTipString("Fraction of P(r) that is positive. Theoretically, P(r) is defined positive.") 
    655562         
    656563        # 1-simga positive fraction figure of merit 
    657         self.pos_err_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    658         self.pos_err_ctl.SetEditable(False) 
     564        self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60,20)) 
    659565        message  = "Fraction of P(r) that is at least 1 standard deviation greater than zero.\n" 
    660566        message += "This figure of merit tells you about the size of the P(r) errors.\n" 
     
    1019925         
    1020926        label_npts = wx.StaticText(self, -1, "Number of points") 
    1021         self.npts_ctl = wx.TextCtrl(self, -1, size=(100,20)) 
     927        self.npts_ctl = PrTextCtrl(self, -1, size=(100,20)) 
    1022928                  
    1023929        pars_sizer = wx.GridBagSizer(5,5) 
     
    1079985        self.npts_ctl.SetValue("%i" % npts) 
    1080986 
    1081  
    1082 class ParsDialog(wx.Panel): 
    1083     """ 
    1084         Dialog box to let the user edit detector settings 
    1085     """ 
    1086      
    1087     def __init__(self, parent, id = id, file=True, **kwargs): 
    1088  
    1089         wx.Panel.__init__(self, parent, id = id, **kwargs) 
    1090         self.file = file 
    1091          
    1092         self.label_nfunc = wx.StaticText(self, -1, "Number of terms") 
    1093         self.label_alpha = wx.StaticText(self, -1, "Regularization constant") 
    1094         self.label_dmax  = wx.StaticText(self, -1, "Max distance [A]") 
    1095          
    1096         # Npts, q max 
    1097         self.nfunc_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    1098         self.alpha_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    1099         self.dmax_ctl  = wx.TextCtrl(self, -1, size=(60,20)) 
    1100  
    1101         self.label_file = None 
    1102         self.file_ctl   = None 
    1103  
    1104         self.static_line_3 = wx.StaticLine(self, -1) 
    1105          
    1106          
    1107  
    1108         self.__do_layout() 
    1109  
    1110         self.Fit() 
    1111          
    1112     def _load_file(self, evt): 
    1113         import os 
    1114         path = None 
    1115         dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.txt", wx.OPEN) 
    1116         if dlg.ShowModal() == wx.ID_OK: 
    1117             path = dlg.GetPath() 
    1118             mypath = os.path.basename(path) 
    1119         dlg.Destroy() 
    1120          
    1121         if path and os.path.isfile(path): 
    1122             self.file_ctl.SetValue(str(path)) 
    1123  
    1124          
    1125     def checkValues(self, event): 
    1126         flag = True 
    1127         try: 
    1128             float(self.alpha_ctl.GetValue()) 
    1129             self.alpha_ctl.SetBackgroundColour(wx.WHITE) 
    1130             self.alpha_ctl.Refresh() 
    1131         except: 
    1132             flag = False 
    1133             self.alpha_ctl.SetBackgroundColour("pink") 
    1134             self.alpha_ctl.Refresh() 
    1135              
    1136         try: 
    1137             float(self.dmax_ctl.GetValue()) 
    1138             self.dmax_ctl.SetBackgroundColour(wx.WHITE) 
    1139             self.dmax_ctl.Refresh() 
    1140         except: 
    1141             flag = False 
    1142             self.dmax_ctl.SetBackgroundColour("pink") 
    1143             self.dmax_ctl.Refresh() 
    1144              
    1145         try: 
    1146             int(self.nfunc_ctl.GetValue()) 
    1147             self.nfunc_ctl.SetBackgroundColour(wx.WHITE) 
    1148             self.nfunc_ctl.Refresh() 
    1149         except: 
    1150             flag = False 
    1151             self.nfunc_ctl.SetBackgroundColour("pink") 
    1152             self.nfunc_ctl.Refresh() 
    1153          
    1154         if flag: 
    1155             event.Skip(True) 
    1156      
    1157     def setContent(self, nfunc, alpha, dmax, file): 
    1158         self.nfunc_ctl.SetValue(str(nfunc)) 
    1159         self.alpha_ctl.SetValue(str(alpha)) 
    1160         self.dmax_ctl.SetValue(str(dmax)) 
    1161         if self.file: 
    1162             self.file_ctl.SetValue(str(file)) 
    1163  
    1164     def getContent(self): 
    1165         nfunc = int(self.nfunc_ctl.GetValue()) 
    1166         alpha = float(self.alpha_ctl.GetValue()) 
    1167         dmax = float(self.dmax_ctl.GetValue()) 
    1168         file = None 
    1169         if self.file: 
    1170             file = self.file_ctl.GetValue() 
    1171         return nfunc, alpha, dmax, file 
    1172  
    1173  
    1174     def __do_layout(self): 
    1175         sizer_main = wx.BoxSizer(wx.VERTICAL) 
    1176         sizer_params = wx.GridBagSizer(5,5) 
    1177  
    1178         iy = 0 
    1179         sizer_params.Add(self.label_nfunc, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    1180         sizer_params.Add(self.nfunc_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    1181         iy += 1 
    1182         sizer_params.Add(self.label_alpha, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    1183         sizer_params.Add(self.alpha_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    1184         iy += 1 
    1185         sizer_params.Add(self.label_dmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    1186         sizer_params.Add(self.dmax_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    1187         iy += 1 
    1188         if self.file: 
    1189             self.label_file  = wx.StaticText(self, -1, "Input file") 
    1190             self.file_ctl  = wx.TextCtrl(self, -1, size=(120,20)) 
    1191             sizer_params.Add(self.label_file, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    1192             sizer_params.Add(self.file_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    1193  
    1194         sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) 
    1195          
    1196          
    1197         if self.file: 
    1198             sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    1199             self.button_load = wx.Button(self, 1, "Choose file") 
    1200             self.Bind(wx.EVT_BUTTON, self._load_file, id = 1)         
    1201             sizer_button.Add(self.button_load, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
    1202          
    1203          
    1204             sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
    1205         self.SetAutoLayout(True) 
    1206         self.SetSizer(sizer_main) 
    1207         self.Layout() 
    1208         self.Centre() 
    1209         # end wxGlade 
    1210  
    1211  
    1212 # end of class DialogAbout 
    1213  
    1214987##### testing code ############################################################ 
    1215988class TestPlot: 
  • prview/perspectives/pr/pr.py

    rceaf16e r9ff861b  
     1""" 
     2This software was developed by the University of Tennessee as part of the 
     3Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     4project funded by the US National Science Foundation.  
     5 
     6See the license text in license.txt 
     7 
     8copyright 2009, University of Tennessee 
     9""" 
     10 
    111# Make sure the option of saving each curve is available  
    212# Use the I(q) curve as input and compare the output to P(r) 
     
    11621172        panel = event.GetEventObject() 
    11631173 
    1164         from inversion_panel import InversionDlg 
    1165          
    11661174        # If we have more than one displayed plot, make the user choose 
    11671175        if len(panel.plots)>1 and panel.graph.selected_plottable in panel.plots: 
    11681176            dataset = panel.graph.selected_plottable 
    1169             if False: 
    1170                 dialog = InversionDlg(None, -1, "P(r) Inversion", panel.plots, pars=False) 
    1171                 dialog.set_content(self.last_data, self.nfunc, self.alpha, self.max_length) 
    1172                 if dialog.ShowModal() == wx.ID_OK: 
    1173                     dataset = dialog.get_content() 
    1174                     dialog.Destroy() 
    1175                 else: 
    1176                     dialog.Destroy() 
    1177                     return 
    11781177        elif len(panel.plots)==1: 
    11791178            dataset = panel.plots.keys()[0] 
Note: See TracChangeset for help on using the changeset viewer.