Changeset fdbea3c in sasview for src/sas/sasgui/perspectives/file_converter
- Timestamp:
- Jul 13, 2016 10:16:49 AM (8 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, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- a8ed421
- Parents:
- 36f4debb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/file_converter/converter_panel.py
r36f4debb rfdbea3c 11 11 from sas.sasgui.guiframe.events import StatusEvent 12 12 from sas.sasgui.guiframe.dataFitting import Data1D 13 from sas.sasgui.guiframe.utils import check_float 13 14 from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader 14 15 from sas.sascalc.dataloader.data_info import Detector 16 from sas.sascalc.dataloader.data_info import Vector 15 17 16 18 # Panel size … … 42 44 self.iq_input = None 43 45 self.output = None 46 self.to_validate = [] 44 47 45 48 self.metadata = { … … 48 51 'run_name': None, 49 52 'instrument': None, 50 'detector': None,53 'detector': [Detector()] 51 54 } 55 self.vectors = ['offset', 'orientation', 'pixel_size'] 56 for vector_name in self.vectors: 57 setattr(self.metadata['detector'][0], vector_name, Vector()) 52 58 53 59 self._do_layout() … … 85 91 86 92 def on_convert(self, event): 93 if not self.validate_inputs(): 94 return 95 87 96 try: 88 97 qdata = self.extract_data(self.q_input.GetPath()) … … 104 113 if run_name is not None: 105 114 self.metadata['run_name'] = { run: run_name } 106 if self.metadata['detector'] is not None: 107 name = self.metadata['detector'] 108 detector = Detector() 109 detector.name = name 110 self.metadata['detector'] = [detector] 115 else: 116 self.metadata['run_name'] = {} 117 else: 118 self.metadata['run'] = [] 119 self.metadata['run_name'] = {} 120 detector = self.metadata['detector'][0] 121 if detector.name is None: 122 self.metadata['detector'][0].name = '' 123 124 # Convert vectors from strings to float 125 for vector_name in self.vectors: 126 # Vector of strings or Nones 127 vector = getattr(self.metadata['detector'][0], vector_name) 128 for direction in ['x', 'y', 'z']: 129 value = getattr(vector, direction) 130 if value is not None: 131 value = float(value) 132 setattr(vector, direction, value) 133 setattr(self.metadata['detector'][0], vector_name, vector) 111 134 112 135 for attr, value in self.metadata.iteritems(): 113 setattr(data, attr, value) 136 if value is not None: 137 setattr(data, attr, value) 114 138 115 139 self.convert_to_cansas(data, output_path) 116 140 wx.PostEvent(self.parent.manager.parent, 117 141 StatusEvent(status="Conversion completed.")) 142 143 def validate_inputs(self): 144 msg = "You must select a" 145 if self.q_input.GetPath() == '': 146 msg += " Q Axis input file." 147 elif self.iq_input.GetPath() == '': 148 msg += "n Intensity input file." 149 elif self.output.GetPath() == '': 150 msg += "destination for the converted file." 151 if msg != "You must select a": 152 wx.PostEvent(self.parent.manager.parent, 153 StatusEvent(status=msg, info='error')) 154 return 155 156 for ctrl in self.to_validate: 157 if ctrl.GetValue() == '': continue 158 ctrl_valid = check_float(ctrl) 159 if not ctrl_valid: 160 msg = "{} must be a valid float".format( 161 ctrl.GetName().replace('_', ' ')) 162 wx.PostEvent(self.parent.manager.parent, 163 StatusEvent(status=msg, info='error')) 164 return False 165 return True 166 118 167 119 168 def metadata_changed(self, event): … … 122 171 attr = textbox.GetName() 123 172 value = textbox.GetValue().strip() 173 174 if attr.startswith('detector_'): 175 attr = attr[9:] # Strip detector_ 176 is_vector = False 177 for vector_name in self.vectors: 178 if attr.startswith(vector_name): is_vector = True 179 if is_vector: 180 if value == '': value = None 181 direction = attr[-1] 182 attr = attr[:-2] 183 vector = getattr(self.metadata['detector'][0], attr) 184 setattr(vector, direction, value) 185 value = vector 186 setattr(self.metadata['detector'][0], attr, value) 187 return 188 124 189 if value == '': 125 190 self.metadata[attr] = None … … 132 197 133 198 instructions = ("Select the 1 column ASCII files containing the Q Axis" 134 "and Intensity data, chose where to save the converted file, then " 135 "click Convert to convert them to CanSAS XML format") 199 " and Intensity data, chose where to save the converted file, then" 200 " click Convert to convert them to CanSAS XML format. If required," 201 " metadata can also be input below.") 136 202 instruction_label = wx.StaticText(self, -1, instructions, 137 203 size=(_STATICBOX_WIDTH+40, -1)) … … 171 237 input_grid.Add(self.output, (2,1), (1,1), wx.ALL, 5) 172 238 173 convert_btn = wx.Button(self, -1, "Convert")239 convert_btn = wx.Button(self, wx.ID_OK, "Convert") 174 240 input_grid.Add(convert_btn, (3,0), (1,1), wx.ALL, 5) 175 241 convert_btn.Bind(wx.EVT_BUTTON, self.on_convert) … … 180 246 181 247 metadata_section = wx.CollapsiblePane(self, -1, "Metadata", 182 size=(_STATICBOX_WIDTH+40, -1) )183 248 size=(_STATICBOX_WIDTH+40, -1), style=wx.WS_EX_VALIDATE_RECURSIVELY) 249 metadata_pane = metadata_section.GetPane() 184 250 metadata_grid = wx.GridBagSizer(5, 5) 185 251 186 252 y = 0 187 253 for item in self.metadata.keys(): 254 if item == 'detector': continue 188 255 label_txt = item.replace('_', ' ').capitalize() 189 label = wx.StaticText(metadata_ section.GetPane(), -1, label_txt,256 label = wx.StaticText(metadata_pane, -1, label_txt, 190 257 style=wx.ALIGN_CENTER_VERTICAL) 191 input_box = wx.TextCtrl(metadata_ section.GetPane(), name=item,258 input_box = wx.TextCtrl(metadata_pane, name=item, 192 259 size=(_STATICBOX_WIDTH-80, -1)) 193 260 input_box.Bind(wx.EVT_TEXT, self.metadata_changed) 194 261 metadata_grid.Add(label, (y,0), (1,1), 195 262 wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) 196 metadata_grid.Add(input_box, (y,1), (1, 1), wx.EXPAND)263 metadata_grid.Add(input_box, (y,1), (1,2), wx.EXPAND) 197 264 y += 1 198 265 199 metadata_section.GetPane().SetSizer(metadata_grid) 266 detector_label = wx.StaticText(metadata_pane, -1, 267 "Detector:") 268 metadata_grid.Add(detector_label, (y, 0), (1,1), wx.ALL | wx.EXPAND, 5) 269 y += 1 270 271 name_label = wx.StaticText(metadata_pane, -1, "Name: ") 272 metadata_grid.Add(name_label, (y, 1), (1,1)) 273 274 name_input = wx.TextCtrl(metadata_pane, 275 name="detector_name", size=(_STATICBOX_WIDTH-80-55, -1)) 276 metadata_grid.Add(name_input, (y, 2), (1,1)) 277 name_input.Bind(wx.EVT_TEXT, self.metadata_changed) 278 y += 1 279 280 distance_label = wx.StaticText(metadata_pane, -1, 281 "Distance (mm):") 282 metadata_grid.Add(distance_label, (y, 1), (1,1)) 283 284 distance_input = wx.TextCtrl(metadata_pane, -1, 285 name="detector_distance", size=(50,-1)) 286 metadata_grid.Add(distance_input, (y,2), (1,1)) 287 self.to_validate.append(distance_input) 288 distance_input.Bind(wx.EVT_TEXT, self.metadata_changed) 289 y += 1 290 291 offset_label = wx.StaticText(metadata_pane, -1, 292 "Offset (m): ") 293 metadata_grid.Add(offset_label, (y,1), (1,1)) 294 295 offset_sizer = wx.BoxSizer(wx.HORIZONTAL) 296 x_label = wx.StaticText(metadata_pane, -1, "x: ", 297 style=wx.ALIGN_CENTER_VERTICAL) 298 offset_sizer.Add(x_label, wx.ALIGN_CENTER_VERTICAL) 299 offset_x_input = wx.TextCtrl(metadata_pane, -1, 300 name="detector_offset_x", size=(50, -1)) 301 offset_sizer.Add(offset_x_input) 302 self.to_validate.append(offset_x_input) 303 offset_x_input.Bind(wx.EVT_TEXT, self.metadata_changed) 304 offset_sizer.AddSpacer((15, -1)) 305 y_label = wx.StaticText(metadata_pane, -1, "y: ", 306 style=wx.ALIGN_CENTER_VERTICAL) 307 offset_sizer.Add(y_label, wx.ALIGN_CENTER_VERTICAL) 308 offset_y_input = wx.TextCtrl(metadata_pane, -1, 309 name="detector_offset_y", size=(50, -1)) 310 offset_sizer.Add(offset_y_input) 311 self.to_validate.append(offset_y_input) 312 offset_y_input.Bind(wx.EVT_TEXT, self.metadata_changed) 313 metadata_grid.Add(offset_sizer, (y,2), (1,1), wx.BOTTOM, 5) 314 y += 1 315 316 orientation_label = wx.StaticText(metadata_pane, -1, 317 u"Orientation (\xb0): ") 318 metadata_grid.Add(orientation_label, (y, 1), (1, 1)) 319 320 orientation_sizer = wx.BoxSizer(wx.HORIZONTAL) 321 roll_label = wx.StaticText(metadata_pane, -1, "Roll: ") 322 orientation_sizer.Add(roll_label) 323 roll_input = wx.TextCtrl(metadata_pane, -1, 324 name="detector_orientation_x", size=(50, -1)) 325 self.to_validate.append(roll_input) 326 roll_input.Bind(wx.EVT_TEXT, self.metadata_changed) 327 orientation_sizer.Add(roll_input) 328 orientation_sizer.AddSpacer((15, -1)) 329 pitch_label = wx.StaticText(metadata_pane, -1, "Pitch: ") 330 orientation_sizer.Add(pitch_label) 331 pitch_input = wx.TextCtrl(metadata_pane, 1, 332 name="detector_orientation_y", size=(50,-1)) 333 self.to_validate.append(pitch_input) 334 pitch_input.Bind(wx.EVT_TEXT, self.metadata_changed) 335 orientation_sizer.Add(pitch_input) 336 orientation_sizer.AddSpacer((15, -1)) 337 yaw_label = wx.StaticText(metadata_pane, -1, "Yaw: ") 338 orientation_sizer.Add(yaw_label) 339 yaw_input = wx.TextCtrl(metadata_pane, 1, 340 name="detector_orientation_z", size=(50,-1)) 341 yaw_input.Bind(wx.EVT_TEXT, self.metadata_changed) 342 self.to_validate.append(yaw_input) 343 orientation_sizer.Add(yaw_input) 344 345 metadata_grid.Add(orientation_sizer, (y,2), (1,1), wx.BOTTOM, 5) 346 y += 1 347 348 pixel_label = wx.StaticText(metadata_pane, -1, "Pixel Size (mm):") 349 metadata_grid.Add(pixel_label, (y,1), (1,1)) 350 351 pixel_sizer = wx.BoxSizer(wx.HORIZONTAL) 352 pixel_x_label = wx.StaticText(metadata_pane, -1, "x: ") 353 pixel_sizer.Add(pixel_x_label) 354 pixel_x_input = wx.TextCtrl(metadata_pane, -1, 355 name="detector_pixel_size_x", size=(50, -1)) 356 self.to_validate.append(pixel_x_input) 357 pixel_x_input.Bind(wx.EVT_TEXT, self.metadata_changed) 358 pixel_sizer.Add(pixel_x_input) 359 pixel_sizer.AddSpacer((15, -1)) 360 pixel_y_label = wx.StaticText(metadata_pane, -1, "y: ") 361 pixel_sizer.Add(pixel_y_label) 362 pixel_y_input = wx.TextCtrl(metadata_pane, 1, 363 name="detector_pixel_size_y", size=(50,-1)) 364 self.to_validate.append(pixel_y_input) 365 pixel_y_input.Bind(wx.EVT_TEXT, self.metadata_changed) 366 pixel_sizer.Add(pixel_y_input) 367 368 metadata_grid.Add(pixel_sizer, (y,2), (1,1), wx.BOTTOM, 5) 369 370 metadata_pane.SetSizer(metadata_grid) 200 371 201 372 vbox.Add(metadata_section, proportion=0, flag=wx.ALL, border=5)
Note: See TracChangeset
for help on using the changeset viewer.