Changeset 318b5bbb in sasview for calculatorview


Ignore:
Timestamp:
Dec 18, 2012 10:55:24 AM (12 years ago)
Author:
Jae Cho <jhjcho@…>
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:
6550b64
Parents:
0203ade
Message:

Added polarization and magnetic stuffs

Location:
calculatorview/src/sans/perspectives/calculator
Files:
15 added
4 edited

Legend:

Unmodified
Added
Removed
  • calculatorview/src/sans/perspectives/calculator/calculator.py

    rce3feca r318b5bbb  
    6464        mass_volume_help = "Based on the chemical formular, " 
    6565        mass_volume_help += "compute the mass density or the molar volume." 
     66        gensans_help = "Genneric SANS" 
    6667        pyconsole_help = "Python Console." 
    6768        #data_editor_help = "Meta Data Editor" 
     
    7778                          ("SANS Resolution Estimator",  
    7879                        resolution_help, self.on_calculate_resoltuion), 
     80                ("Generic Scattering Calculator",  
     81                        gensans_help, self.on_gen_model), 
    7982                ("Python Shell/Editor", pyconsole_help, self.on_python_console)] 
    8083               
     
    162165        #if event != None: 
    163166        #    event.Skip() 
     167         
     168    def on_gen_model(self, event): 
     169        from sans.perspectives.calculator.gen_scatter_panel \ 
     170        import SasGenWindow 
     171        frame = SasGenWindow(parent=self.parent) 
     172        self.put_icon(frame) 
     173        frame.Show(True)  
     174         
    164175    def on_python_console(self, event): 
    165176        """ 
  • calculatorview/src/sans/perspectives/calculator/help_panel.py

    rce3feca r318b5bbb  
    1313    """ 
    1414    """ 
    15     def __init__(self, parent, title="Tool Help", pageToOpen=None): 
    16         wx.Frame.__init__(self, parent, title, size=(700, 450)) 
     15    def __init__(self, parent, id=-1, title="Tool Help", pageToOpen=None,  
     16                                                    size=(700, 450)): 
     17        wx.Frame.__init__(self, parent, id, title, size=size) 
    1718        """ 
    1819             contains help info 
    1920        """ 
    20         self.SetTitle("Tool Help",)  
     21        self.SetTitle(title)  
    2122        splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) 
    2223        rpanel = wx.Panel(splitter, -1) 
    23         lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) 
     24        self.lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) 
    2425         
    2526        vbox = wx.BoxSizer(wx.VERTICAL) 
     
    3738        
    3839        vboxl = wx.BoxSizer(wx.VERTICAL) 
    39         headerl = wx.Panel(lpanel, -1, size=(-1, 20)) 
     40        headerl = wx.Panel(self.lpanel, -1, size=(-1, 20)) 
    4041        
    4142        headerl.SetBackgroundColour('#6666FF') 
     
    4950        headerl.SetSizer(hboxl) 
    5051        vboxl.Add(headerl, 0, wx.EXPAND) 
    51         self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) 
     52        self.lhelp = html.HtmlWindow(self.lpanel, -1, style=wx.NO_BORDER) 
    5253        self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER,  
    5354                                     size=(500,-1)) 
    54          
    55         self.path = calculator.get_data_path(media='media') 
     55        if pageToOpen != None: 
     56            path = os.path.dirname(pageToOpen) 
     57            self.path = os.path.join(path, "gen_sans_help.html") 
     58        else: 
     59            self.path = calculator.get_data_path(media='media') 
    5660        
    5761        page1 = """<html> 
     
    7680            <li><a href ="resolution_calculator_help.html"  
    7781            target ="showframe">Resolution Estimator</a><br></li> 
     82            <li><a href ="gen_sans_help.html"  
     83            target ="showframe">Generic Scattering Calculator</a><br></li> 
    7884            <li><a href ="pycrust_help.html"  
    7985            target ="showframe">Python Shell</a><br></li> 
     
    8490        self.lhelp.SetPage(page) 
    8591        self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked) 
    86          
     92        if  pageToOpen != None: 
     93            self.rhelp.LoadPage(str(pageToOpen)) 
    8794        vbox.Add(self.rhelp, 1, wx.EXPAND) 
    8895        vboxl.Add(self.lhelp, 1, wx.EXPAND) 
    8996        rpanel.SetSizer(vbox) 
    90         lpanel.SetSizer(vboxl) 
    91         lpanel.SetFocus() 
     97        self.lpanel.SetSizer(vboxl) 
     98        self.lpanel.SetFocus() 
    9299         
    93100        vbox1 = wx.BoxSizer(wx.HORIZONTAL) 
    94101        vbox1.Add(splitter, 1, wx.EXPAND) 
    95         splitter.AppendWindow(lpanel, 200) 
     102        splitter.AppendWindow(self.lpanel, 200) 
    96103        splitter.AppendWindow(rpanel) 
    97104        self.SetSizer(vbox1) 
    98         
     105         
     106        self.splitter = splitter 
    99107        self.Centre() 
    100108        self.Show(True) 
  • calculatorview/src/sans/perspectives/calculator/load_thread.py

    r7343319 r318b5bbb  
    4646            # Real code should not print, but this is an example... 
    4747            raise 
    48        
     48         
     49class GenReader(CalcThread): 
     50    """ 
     51        Load a sld data given a filename 
     52    """ 
     53    def __init__(self, path, loader,  
     54                 completefn=None, 
     55                 updatefn   = None, 
     56                 yieldtime  = 0.01, 
     57                 worktime   = 0.01 
     58                 ): 
     59        CalcThread.__init__(self, completefn, 
     60                 updatefn, 
     61                 yieldtime, 
     62                 worktime) 
     63        self.path = path 
     64        #Instantiate a loader  
     65        self.loader = loader 
     66        self.starttime = 0   
     67         
     68    def isquit(self): 
     69        """ 
     70             @raise KeyboardInterrupt: when the thread is interrupted 
     71        """ 
     72        try: 
     73            CalcThread.isquit(self) 
     74        except KeyboardInterrupt: 
     75            raise KeyboardInterrupt    
     76         
     77         
     78    def compute(self): 
     79        """ 
     80            read some data 
     81        """ 
     82        self.starttime = time.time() 
     83        try: 
     84            data =  self.loader.read(self.path) 
     85            self.complete(data=data) 
     86        except: 
     87            # Thread was interrupted, just proceed and re-raise. 
     88            # Real code should not print, but this is an example... 
     89            raise 
     90             
  • calculatorview/src/sans/perspectives/calculator/model_editor.py

    r657e52c r318b5bbb  
    1111import sys 
    1212import os 
     13import math 
    1314from wx.py.editwindow import EditWindow 
    14 import subprocess 
    1515 
    1616if sys.platform.count("win32") > 0: 
     
    2424M_NAME = 'Model' 
    2525EDITOR_WIDTH = 800 
    26 EDITOR_HEIGTH = 720 
     26EDITOR_HEIGTH = 735 
    2727PANEL_WIDTH = 500 
    2828_BOX_WIDTH = 55 
     
    530530        self.warning = "" 
    531531        self._description = "New Custom Model" 
     532        self.function_tcl = None 
    532533        #self._default_save_location = os.getcwd() 
    533534        self._do_layout() 
     
    546547        self.param_sizer = wx.BoxSizer(wx.VERTICAL) 
    547548        self.function_sizer = wx.BoxSizer(wx.VERTICAL) 
     549        self.func_horizon_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    548550        self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    549551        self.msg_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     
    592594        """ 
    593595        param_txt = wx.StaticText(self, -1, 'Fit Parameters (if any): ')  
     596         
    594597        param_tip = "#Set the parameters and initial values.\n" 
    595598        param_tip += "#Example:\n" 
     
    601604        self.param_tcl.setDisplayLineNumbers(True) 
    602605        self.param_tcl.SetToolTipString(param_tip) 
     606 
    603607        self.param_sizer.AddMany([(param_txt, 0, wx.LEFT, 10), 
    604608                        (self.param_tcl, 1, wx.EXPAND|wx.ALL, 10)]) 
    605  
    606     
     609                 
    607610    def _layout_function(self): 
    608611        """ 
     
    616619        hint_function += "    y = A + B * cos(2 * pi * x)\n" 
    617620        hint_function += "return y\n" 
     621        math_txt = wx.StaticText(self, -1, '*Useful math functions: ') 
     622        math_combo = self._fill_math_combo() 
     623         
    618624        id  = wx.NewId()  
    619625        self.function_tcl = EditWindow(self, id, wx.DefaultPosition,  
     
    621627        self.function_tcl.setDisplayLineNumbers(True) 
    622628        self.function_tcl.SetToolTipString(hint_function) 
    623         self.function_sizer.Add(function_txt, 0, wx.LEFT, 10) 
     629         
     630        self.func_horizon_sizer.Add(function_txt) 
     631        self.func_horizon_sizer.Add(math_txt, 0, wx.LEFT, 250) 
     632        self.func_horizon_sizer.Add(math_combo, 0, wx.LEFT, 10) 
     633 
     634        self.function_sizer.Add(self.func_horizon_sizer, 0, wx.LEFT, 10) 
    624635        self.function_sizer.Add( self.function_tcl, 1, wx.EXPAND|wx.ALL, 10) 
    625636         
     
    682693        self.SetSizer(self.main_sizer) 
    683694        self.SetAutoLayout(True) 
    684      
     695 
     696    def _fill_math_combo(self): 
     697        """ 
     698        Fill up the math combo box 
     699        """ 
     700        self.math_combo = wx.ComboBox(self, -1, size=(100, -1),  
     701                                      style=wx.CB_READONLY)  
     702        for item in dir(math): 
     703            if item.count("_") < 1: 
     704                try: 
     705                    exec "float(math.%s)"% item 
     706                    self.math_combo.Append(str(item)) 
     707                except: 
     708                    self.math_combo.Append(str(item) + "()" ) 
     709        self.math_combo.Bind(wx.EVT_COMBOBOX, self._on_math_select) 
     710        self.math_combo.SetSelection(0) 
     711        return self.math_combo 
     712         
     713    def _on_math_select(self, event): 
     714        """ 
     715        On math selection on ComboBox 
     716        """ 
     717        event.Skip() 
     718        label = self.math_combo.GetLabel()  
     719        self.function_tcl.SetFocus() 
     720        # Put the text at the cursor position 
     721        pos = self.function_tcl.GetCurrentPos() 
     722        self.function_tcl.InsertText(pos, label)   
     723        # Put the cursor at appropriate postion 
     724        length = len(label) 
     725        if label[-1] == ')': 
     726            length -= 1 
     727        f_pos = pos + length 
     728        self.function_tcl.GotoPos(f_pos)    
     729 
    685730    def get_notes(self): 
    686731        """ 
     
    10711116        ## Parameter details [units, min, max] 
    10721117        self.details = {} 
    1073          
     1118        ## Magnetic Panrameters 
     1119        self.magnetic_params = [] 
    10741120        # non-fittable parameters 
    10751121        self.non_fittable = p_model1.non_fittable   
     
    11051151            if not new_item in self.orientation_params: 
    11061152                self.orientation_params.append(new_item) 
     1153        ## magnetic params 
     1154        for item in self.p_model1.magnetic_params: 
     1155            new_item = "p1_" + item 
     1156            if not new_item in self.magnetic_params: 
     1157                self.magnetic_params.append(new_item) 
     1158             
     1159        for item in self.p_model2.magnetic_params: 
     1160            new_item = "p2_" + item 
     1161            if not new_item in self.magnetic_params: 
     1162                self.magnetic_params.append(new_item) 
    11071163        # get multiplicity if model provide it, else 1. 
    11081164        try: 
Note: See TracChangeset for help on using the changeset viewer.