Changeset fdef956 in sasview for calculatorview/src/sans
- Timestamp:
- Jun 14, 2012 8:05:22 PM (12 years ago)
- 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:
- d7b49576
- Parents:
- 0008f54
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/src/sans/perspectives/calculator/model_editor.py
r0008f54 rfdef956 18 18 if sys.platform.count("win32") > 0: 19 19 FONT_VARIANT = 0 20 PNL_WIDTH = 4 6020 PNL_WIDTH = 450 21 21 PNL_HITE = 320 22 22 else: 23 23 FONT_VARIANT = 1 24 PNL_WIDTH = 5 0024 PNL_WIDTH = 590 25 25 PNL_HITE = 400 26 M_NAME = ' SumModel'26 M_NAME = 'Model' 27 27 EDITOR_WIDTH = 800 28 28 EDITOR_HEIGTH = 720 29 29 PANEL_WIDTH = 500 30 _BOX_WIDTH = 5 130 _BOX_WIDTH = 55 31 31 32 32 … … 74 74 self.model1_string = "SphereModel" 75 75 self.model2_string = "CylinderModel" 76 self.name = 'Sum' + M_NAME 76 77 self._notes = '' 77 78 self.operator = '+' 79 self.operator_cbox = None 80 self.explanation = '' 81 self.explanationctr = None 82 self.sizer = None 78 83 self._msg_box = None 79 84 self.msg_sizer = None … … 82 87 self.model2_name = str(self.model2.GetValue()) 83 88 self.good_name = True 89 self.fill_oprator_combox() 84 90 85 91 def _layout_name(self): … … 98 104 self.name_tcl.SetToolTipString(hint_name) 99 105 self.name_hsizer.AddMany([(name_txt, 0, wx.LEFT|wx.TOP, 10), 100 (self.name_tcl, 0, wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 101 self.name_sizer.AddMany([(self.name_hsizer, 0, 106 (self.name_tcl, -1, 107 wx.EXPAND|wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 108 self.name_sizer.AddMany([(self.name_hsizer, -1, 102 109 wx.LEFT|wx.TOP, 10)]) 103 110 … … 113 120 self.desc_tcl.SetValue('') 114 121 #self.name_tcl.SetFont(self.font) 115 hint_desc = "Write a short description of th e summodel function."122 hint_desc = "Write a short description of this model function." 116 123 self.desc_tcl.SetToolTipString(hint_desc) 117 124 self.desc_sizer.AddMany([(desc_txt, 0, wx.LEFT|wx.TOP, 10), 118 (self.desc_tcl, 0,119 125 (self.desc_tcl, -1, 126 wx.EXPAND|wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) 120 127 121 128 def _build_sizer(self): … … 123 130 Build gui 124 131 """ 125 _BOX_WIDTH= 195 # combobox width132 box_width = 195 # combobox width 126 133 vbox = wx.BoxSizer(wx.VERTICAL) 127 s izer = wx.GridBagSizer(1, 3)134 self.sizer = wx.GridBagSizer(1, 3) 128 135 self._layout_name() 129 136 self._layout_description() … … 138 145 self.model1 = wx.ComboBox(self, -1, style=wx.CB_READONLY) 139 146 wx.EVT_COMBOBOX(self.model1, -1, self.on_model1) 140 self.model1.SetMinSize(( _BOX_WIDTH, -1))147 self.model1.SetMinSize((box_width*5/6, -1)) 141 148 self.model1.SetToolTipString("model1") 149 150 self.operator_cbox = wx.ComboBox(self, -1, size=(50, -1), 151 style=wx.CB_READONLY) 152 wx.EVT_COMBOBOX(self.operator_cbox, -1, self.on_select_operator) 153 operation_tip = "Add: +, Multiply: * " 154 self.operator_cbox.SetToolTipString(operation_tip) 155 142 156 self.model2 = wx.ComboBox(self, -1, style=wx.CB_READONLY) 143 157 wx.EVT_COMBOBOX(self.model2, -1, self.on_model2) 144 self.model2.SetMinSize(( _BOX_WIDTH, -1))158 self.model2.SetMinSize((box_width*5/6, -1)) 145 159 self.model2.SetToolTipString("model2") 146 160 self._set_model_list() … … 148 162 # Buttons on the bottom 149 163 self.static_line_1 = wx.StaticLine(self, -1) 150 self.okButton = wx.Button(self,wx.ID_OK, 'Apply', size=( _BOX_WIDTH/2, 25))164 self.okButton = wx.Button(self,wx.ID_OK, 'Apply', size=(box_width/2, 25)) 151 165 self.okButton.Bind(wx.EVT_BUTTON, self.check_name) 152 166 self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Close', 153 size=( _BOX_WIDTH/2, 25))167 size=(box_width/2, 25)) 154 168 # Intro 155 explanation = " custom model = scale_factor * (model1 %s model2)\n"\169 self.explanation = " custom model = scale_factor * (model1 %s model2)\n"\ 156 170 % self.operator 157 171 #explanation += " Note: This will overwrite the previous sum model.\n" … … 163 177 vbox.Add(self.name_hsizer) 164 178 vbox.Add(self.desc_sizer) 165 vbox.Add(s izer)179 vbox.Add(self.sizer) 166 180 ix = 0 167 181 iy = 1 168 sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 182 self.explanationctr = wx.StaticText(self, -1, self.explanation) 183 self.sizer.Add(self.explanationctr , (iy, ix), 169 184 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 170 185 model1_box.Add(wx.StaticText(self,-1, model_string% (1, 1)), -1, 0) 171 model1_box.Add(( _BOX_WIDTH-35,10))186 model1_box.Add((box_width-15,10)) 172 187 model1_box.Add(wx.StaticText(self, -1, model_string% (2, 2)), -1, 0) 173 188 model2_box.Add(self.model1, -1, 0) 174 model2_box.Add((20,10)) 189 model2_box.Add((15,10)) 190 model2_box.Add(self.operator_cbox, 0, 0) 191 model2_box.Add((15,10)) 175 192 model2_box.Add(self.model2, -1, 0) 176 193 model_vbox.Add(model1_box, -1, 0) … … 179 196 iy += 1 180 197 ix = 0 181 s izer.Add(sum_box, (iy, ix),198 self.sizer.Add(sum_box, (iy, ix), 182 199 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 183 200 vbox.Add((10,10)) … … 190 207 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 0) 191 208 sizer_button.Add(self.closeButton, 0, 192 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 1 5)209 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 193 210 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 211 194 212 self.SetSizer(vbox) 195 213 self.Centre() … … 214 232 title = self.name_tcl.GetValue().lstrip().rstrip() 215 233 if title == '': 216 title = M_NAME 234 text = self.operator_cbox.GetLabel().strip() 235 if text == '+': 236 name = 'Sum' 237 else: 238 name = 'Multi' 239 self.name = name + M_NAME 240 title = self.name 217 241 self.name = title 218 242 t_fname = title + '.py' 219 243 if not self.overwrite_name: 220 if t_fname in list_fnames and title != M_NAME:244 if t_fname in list_fnames and title != self.name: 221 245 self.name_tcl.SetBackgroundColour('pink') 222 246 self.good_name = False … … 254 278 color = 'blue' 255 279 except: 256 msg= "Easy Custom Sum : Error occurred..."280 msg= "Easy Custom Sum/Multipy: Error occurred..." 257 281 info = 'Error' 258 282 color = 'red' … … 295 319 self.model2_name = str(self.model2.GetValue()) 296 320 self.model2_string = self.model2_name 297 321 322 def on_select_operator(self, event=None): 323 """ 324 On Select an Operator 325 """ 326 item = event.GetEventObject() 327 text = item.GetLabel().strip() 328 if text == '+': 329 name = 'Sum' 330 else: 331 name = 'Multi' 332 self.operator = str(text) 333 self.explanation = " custom model = scale_factor * " 334 self.explanation += "(model1 %s model2)\n"% self.operator 335 self.explanationctr.SetLabel(self.explanation) 336 self.name = name + M_NAME 337 self.sizer.Layout() 338 339 def fill_oprator_combox(self): 340 """ 341 fill the current combobox with the operator 342 """ 343 operator_list = [' +', ' *'] 344 for oper in operator_list: 345 pos = self.operator_cbox.Append(str(oper)) 346 self.operator_cbox.SetClientData(pos, str(oper.strip())) 347 self.operator_cbox.SetSelection(0) 348 298 349 def getText(self): 299 350 """ … … 312 363 name = self.name_tcl.GetValue().lstrip().rstrip() 313 364 if name == '': 314 name = M_NAME 365 text = self.operator_cbox.GetLabel().strip() 366 if text == '+': 367 name = 'Sum' 368 else: 369 name = 'Multi' 370 self.name = name + M_NAME 315 371 path = self.fname 316 372 try: … … 1154 1210 #m2.p_model2.setParam("rg", 100) 1155 1211 out2 = m2.p_model1.runXY(0.01) %s m2.p_model2.runXY(0.01)\n 1212 print "My name is %s."% m1.name 1156 1213 print out1, " = ", out2 1157 1214 if out1 == out2:
Note: See TracChangeset
for help on using the changeset viewer.