Ignore:
Timestamp:
Dec 18, 2012 8:55:24 AM (11 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.