Changeset cb78690 in sasview for simview/perspectives/simulation
- Timestamp:
- Dec 20, 2009 1:48:39 PM (15 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:
- 66c488b
- Parents:
- eaeb13e
- Location:
- simview/perspectives/simulation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
simview/perspectives/simulation/ShapeParameters.py
reaeb13e rcb78690 50 50 self.shape_sizer = wx.GridBagSizer(5,5) 51 51 52 52 ny = 0 53 53 title = wx.StaticText(self, -1, "[Temporary form]", style=wx.ALIGN_LEFT) 54 self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 55 56 self.bck.Add(self.shape_sizer, (1,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=0) 54 self.bck.Add(title, (ny,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 55 56 # Shape list 57 shape_text = wx.StaticText(self, -1, "Geometric shape", style=wx.ALIGN_LEFT) 58 self.shape_list = SimCanvas.getShapes() 59 value_list = [] 60 for item in self.shape_list: 61 value_list.append(item['name']) 62 63 self.model_combo = wx.ComboBox(self, -1, value=value_list[0], choices=value_list, style=wx.CB_READONLY) 64 self.model_combo.SetToolTip(wx.ToolTip("select a geometric shape from the drop-down list")) 65 66 ny+=1 67 self.bck.Add(shape_text, (ny,0), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 68 self.bck.Add(self.model_combo, (ny,1), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 69 wx.EVT_COMBOBOX(self.model_combo,-1, self._on_select_shape) 70 71 # Placeholder for parameter form 72 ny+=1 73 self.bck.Add(self.shape_sizer, (ny,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=0) 57 74 58 75 # Point density control 59 76 point_density_text = wx.StaticText(self, -1, "Point density", style=wx.ALIGN_LEFT) 60 self.bck.Add(point_density_text, (2,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 77 ny+=1 78 self.bck.Add(point_density_text, (ny,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 61 79 self.point_density_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) 62 self.point_density_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_density_changed) 63 self.point_density_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_density_changed) 64 self.bck.Add(self.point_density_ctrl, (2,1), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 65 66 80 self.point_density_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_parameter_changed) 81 self.point_density_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_parameter_changed) 82 self.bck.Add(self.point_density_ctrl, (ny,1), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 83 84 # Q range 85 q_min_text = wx.StaticText(self, -1, "Q min", style=wx.ALIGN_LEFT) 86 ny+=1 87 self.bck.Add(q_min_text, (ny,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 88 self.q_min_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) 89 self.q_min_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_parameter_changed) 90 self.q_min_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_parameter_changed) 91 self.bck.Add(self.q_min_ctrl, (ny,1), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 92 93 q_max_text = wx.StaticText(self, -1, "Q max", style=wx.ALIGN_LEFT) 94 self.bck.Add(q_max_text, (ny,2), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 95 self.q_max_ctrl = wx.TextCtrl(self, -1, size=(40,20), style=wx.TE_PROCESS_ENTER) 96 self.q_max_ctrl.Bind(wx.EVT_TEXT_ENTER, self._on_parameter_changed) 97 self.q_max_ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_parameter_changed) 98 self.bck.Add(self.q_max_ctrl, (ny,3), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 99 100 # Shape List 101 # Internal counter of shapes in the listbox 102 self.counter = 0 103 # Buffer filled flag 104 self.buffer_filled = False 105 # Save current flag 106 self.current_saved = False 107 108 id = wx.NewId() 109 shape_listbox_text = wx.StaticText(self, -1, "List of shapes on 3D canvas", style=wx.ALIGN_LEFT) 110 self.shape_listbox = wx.ListBox(self, id, wx.DefaultPosition, (295, 200), 111 [], wx.LB_SINGLE | wx.LB_HSCROLL) 112 113 # Listen to history events 114 self.parent.Bind(EVT_ADD_SHAPE, self._on_add_shape_to_listbox) 115 self.shape_listbox.Bind(wx.EVT_LISTBOX, self._on_select_from_listbox, id=id) 116 self.shape_listbox.Bind(wx.EVT_CONTEXT_MENU, self._on_listbox_context_menu, id=id) 117 118 ny+=1 119 self.bck.Add(shape_listbox_text, (ny,0), (1,2), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 120 ny+=1 121 self.bck.Add(self.shape_listbox, (ny,0), (1,5), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 67 122 68 123 self.current_shape = None 69 124 70 # Bind to Edit events 71 self.parent.Bind(EVT_EDIT_SHAPE, self._onEditShape) 72 73 def _on_density_changed(self, event): 125 # Default shape 126 if type(self.shape_list)==list and len(self.shape_list)>0: 127 shape = SimCanvas.getShapeClassByName(self.shape_list[0]['name'])() 128 self.editShape(shape) 129 130 def _on_select_shape(self, event): 131 shape = SimCanvas.getShapeClassByName(self.shape_list[event.GetEventObject().GetSelection()]['name'])() 132 self.editShape(shape) 133 134 def _on_parameter_changed(self, event): 74 135 """ 75 136 Process event that might mean a change of the simulation point density 76 137 """ 77 if self.point_density_ctrl.IsModified(): 78 self.point_density_ctrl.SetModified(False) 138 event_obj = event.GetEventObject() 139 if event_obj.IsModified(): 140 event_obj.SetModified(False) 79 141 self._simulation_update() 80 142 … … 84 146 """ 85 147 #TODO: create an event to pass the parameters to the simulation plug-in for processing 148 print "TODO: Simulation update" 86 149 pass 87 150 … … 226 289 self.shape_sizer.Layout() 227 290 self.shape_sizer.Fit(self) 228 self.parent.GetSizer().Layout() 291 try: 292 self.parent.GetSizer().Layout() 293 except: 294 print "TODO: move the Layout call of editShape up to the caller" 229 295 230 296 def _readCtrlFloat(self, ctrl): … … 308 374 self._readCtrlFloat(item[1]) 309 375 310 311 312 class ShapeListPanel(wx.Panel): 313 """ 314 Panel to show the list of currently displayed shapes 315 """ 316 317 def __init__(self, parent, *args, **kwargs): 318 wx.Panel.__init__(self, parent, *args, **kwargs) 319 self.parent = parent 320 321 self.window_name = "ShapeList" 322 self.window_caption = "Shape list" 323 324 # Listen to history events 325 self.parent.Bind(EVT_ADD_SHAPE, self._onAddShape) 326 327 # Internal counter of history items 328 self.counter = 0 329 330 # Buffer filled flag 331 self.buffer_filled = False 332 333 # Set up the layout 334 self._set_layout() 335 336 # Save current flag 337 self.current_saved = False 338 339 def _set_layout(self): 340 """ 341 Set up the layout of the panel 342 """ 343 self.sizer = wx.GridBagSizer(0,5) 344 self.sizer.SetMinSize((250,50)) 345 346 title = wx.StaticText(self, -1, "List of shapes", style=wx.ALIGN_LEFT) 347 self.sizer.Add(title, (0,0), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 348 349 self.view_box = wx.ListBox(self, 101, wx.DefaultPosition, (295, 200), 350 [], wx.LB_SINGLE | wx.LB_HSCROLL) 351 352 self.sizer.Add(self.view_box, (1,0), flag=wx.TOP, border=0) 353 354 self.SetSizer(self.sizer) 355 356 self.Bind(wx.EVT_CONTEXT_MENU, self.onShowPopup, id=101) 357 self.Bind(wx.EVT_LISTBOX, self.onSelect, id=101) 358 359 def onRemove(self, ev): 360 """ 361 Remove an item 362 """ 363 indices = self.view_box.GetSelections() 364 if len(indices)>0: 365 name = self.view_box.GetClientData(indices[0]).name 366 self.view_box.Delete(indices[0]) 367 wx.PostEvent(self.parent, DelShapeEvent(id = name)) 368 369 def onRename(self, ev): 370 """ 371 Rename an item 372 """ 373 indices = self.view_box.GetSelections() 374 if len(indices)>0: 375 print "NOT YET IMPLMENTED" 376 print "renaming", self.view_box.GetString(indices[0]) 377 378 def onShowPopup(self, event): 379 """ 380 Popup context menu event 381 """ 382 # menu 383 popupmenu = wx.Menu() 384 popupmenu.Append(101, "&Remove Selected") 385 #popupmenu.Append(102, "&Rename Selected") 386 wx.EVT_MENU(self, 101, self.onRemove) 387 #wx.EVT_MENU(self, 102, self.onRename) 388 389 pos = event.GetPosition() 390 pos = self.ScreenToClient(pos) 391 self.PopupMenu(popupmenu, pos) 392 393 def onSelect(self, event): 394 """ 395 Process item selection events 396 """ 397 index = event.GetSelection() 398 view_name = self.view_box.GetString(index) 399 #view = event.GetClientData() 400 401 wx.PostEvent(self.parent, EditShapeEvent(shape=event.GetClientData())) 402 403 def _onAddShape(self, event): 404 """ 405 Process a new shape 406 376 #-- Methods to support list of shapes -- 377 def _on_add_shape_to_listbox(self, event): 378 """ 379 Process a new shape 407 380 @param event: EVT_ADD_SHAPE event 408 381 """ … … 410 383 if event.new: 411 384 self.counter += 1 412 self.view_box.Insert("%d: %s" % (self.counter, event.shape.name), 413 self.view_box.GetCount(), event.shape) 414 385 self.shape_listbox.Insert("%d: %s" % (self.counter, event.shape.name), 386 self.shape_listbox.GetCount(), event.shape) 387 388 def _on_select_from_listbox(self, event): 389 """ 390 Process item selection events 391 """ 392 index = event.GetSelection() 393 view_name = self.shape_listbox.GetString(index) 394 self.editShape(shape=event.GetClientData(), new=False) 395 # The following event is bound to the SimPanel to highlight the shape in blue 396 #TODO: how come it doesn't work? 397 wx.PostEvent(self.parent, EditShapeEvent(shape=event.GetClientData())) 398 #TODO: select the shape from the drop down 399 400 def _on_listbox_context_menu(self, event): 401 """ 402 Popup context menu event 403 """ 404 # Create context menu 405 popupmenu = wx.Menu() 406 407 # Create an item to delete the selected shape from the canvas 408 id = wx.NewId() 409 popupmenu.Append(id, "&Remove Selected") 410 wx.EVT_MENU(self, id, self._on_remove_shape_from_listbox) 411 412 # Create an item to rename a shape to a more user friendly name 413 #id = wx.NewId() 414 #popupmenu.Append(102, "&Rename Selected") 415 #wx.EVT_MENU(self, 102, self.onRename) 416 417 pos = event.GetPosition() 418 pos = self.ScreenToClient(pos) 419 self.PopupMenu(popupmenu, pos) 420 421 def _on_remove_shape_from_listbox(self, ev): 422 """ 423 Remove an item 424 """ 425 indices = self.shape_listbox.GetSelections() 426 if len(indices)>0: 427 name = self.shape_listbox.GetClientData(indices[0]).name 428 self.shape_listbox.Delete(indices[0]) 429 wx.PostEvent(self.parent, DelShapeEvent(id = name)) 430 431 def _on_rename_shape_from_listbox(self, ev): 432 """ 433 Rename an item 434 """ 435 indices = self.shape_listbox.GetSelections() 436 if len(indices)>0: 437 print "NOT YET IMPLMENTED" 438 print "renaming", self.shape_listbox.GetString(indices[0]) 439 -
simview/perspectives/simulation/SimCanvas.py
reaeb13e rcb78690 648 648 return None 649 649 650 def getShapeClassByName(name): 651 """ 652 Returns a child class of BaseShape corresponding 653 to the supplied shape name. 654 @param name: shape name 655 """ 656 def f(s): return s['name']==name 657 if SHAPE_LIST is not None: 658 shape = filter(f, SHAPE_LIST) 659 return shape[0]['cl'] 660 return None -
simview/perspectives/simulation/simulation.py
reaeb13e rcb78690 107 107 self.paramPanel = ShapeParameters.ShapeParameterPanel(self.parent, style=wx.RAISED_BORDER) 108 108 109 # List of shapes110 #TODO: incorporate this into the main simulation panel111 self.shapePanel = ShapeParameters.ShapeListPanel(self.parent, style=wx.RAISED_BORDER)112 113 109 # Simulation 114 110 self.volCanvas = VolumeCanvas.VolumeCanvas() … … 125 121 126 122 # Set the list of panels that are part of the simulation perspective 127 #TODO: modify this so that we have only on parameter panel and on 3D viewer128 123 self.perspective = [] 129 124 self.perspective.append(self.plotPanel.window_name) 130 125 self.perspective.append(self.paramPanel.window_name) 131 self.perspective.append(self.shapePanel.window_name)132 126 133 127 # Bind state events … … 135 129 self.parent.Bind(ShapeParameters.EVT_DEL_SHAPE, self._onDelShape) 136 130 137 return [self.plotPanel, self.paramPanel , self.shapePanel]131 return [self.plotPanel, self.paramPanel] 138 132 139 133 def _onAddShape(self, evt): … … 245 239 246 240 #TODO: remove this method once: 247 1- the shapes are available as a list on the central simulation panel 248 2- P(r) is plotted with the I(q) simulation result 241 1- P(r) is plotted with the I(q) simulation result 249 242 """ 250 243 # Shapes 251 244 shapes = wx.Menu() 252 shape_list = SimCanvas.getShapes()253 254 for item in shape_list:255 shapes.Append(item['id'], item['name'])256 wx.EVT_MENU(self.parent, item['id'], self._onNewShape)257 258 shapes.AppendSeparator()259 245 260 246 #TODO: Save P(r) should be replaced by plotting P(r) for each simulation … … 263 249 wx.EVT_MENU(self.parent, id, self._onSavePr) 264 250 265 return [(id+1, shapes, "Shapes")] 266 267 def _onNewShape(self, evt): 268 """ 269 Process menu event to create a new shape 270 """ 271 evt.Skip() 272 shape = SimCanvas.getShapeClass(evt.GetId())() 273 self.paramPanel.editShape(shape) 251 return [(id+1, shapes, "Save P(r)")] 274 252 275 253 def _change_point_density(self, point_density):
Note: See TracChangeset
for help on using the changeset viewer.