[77d92cd] | 1 | """ |
---|
| 2 | This module provides a GUI for the file converter |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | import wx |
---|
| 6 | import sys |
---|
[a58706d] | 7 | import numpy as np |
---|
[77d92cd] | 8 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
| 9 | from sas.sasgui.guiframe.panel_base import PanelBase |
---|
| 10 | from sas.sasgui.perspectives.calculator import calculator_widgets as widget |
---|
[c9a519f] | 11 | from sas.sasgui.perspectives.file_converter.converter_widgets import VectorInput |
---|
[de0df2c] | 12 | from sas.sasgui.perspectives.file_converter.meta_panels import MetadataWindow |
---|
| 13 | from sas.sasgui.perspectives.file_converter.meta_panels import DetectorPanel |
---|
[2a7722b] | 14 | from sas.sasgui.perspectives.file_converter.meta_panels import SamplePanel |
---|
[55bc56bc] | 15 | from sas.sasgui.perspectives.file_converter.meta_panels import SourcePanel |
---|
[eb8da5f] | 16 | from sas.sasgui.perspectives.file_converter.frame_select_dialog import FrameSelectDialog |
---|
[a58706d] | 17 | from sas.sasgui.guiframe.events import StatusEvent |
---|
[11794f2] | 18 | from sas.sasgui.guiframe.documentation_window import DocumentationWindow |
---|
[a58706d] | 19 | from sas.sasgui.guiframe.dataFitting import Data1D |
---|
[fdbea3c] | 20 | from sas.sasgui.guiframe.utils import check_float |
---|
[8976865] | 21 | from sas.sasgui.perspectives.file_converter.cansas_writer import CansasWriter |
---|
[4b862c4] | 22 | from sas.sasgui.perspectives.file_converter.bsl_loader import BSLLoader |
---|
[f2b3f28] | 23 | from sas.sascalc.dataloader.data_info import Detector |
---|
[2a7722b] | 24 | from sas.sascalc.dataloader.data_info import Sample |
---|
[55bc56bc] | 25 | from sas.sascalc.dataloader.data_info import Source |
---|
[fdbea3c] | 26 | from sas.sascalc.dataloader.data_info import Vector |
---|
[77d92cd] | 27 | |
---|
| 28 | # Panel size |
---|
| 29 | if sys.platform.count("win32") > 0: |
---|
| 30 | PANEL_TOP = 0 |
---|
| 31 | _STATICBOX_WIDTH = 410 |
---|
| 32 | _BOX_WIDTH = 200 |
---|
[36f4debb] | 33 | PANEL_SIZE = 480 |
---|
[77d92cd] | 34 | FONT_VARIANT = 0 |
---|
| 35 | else: |
---|
| 36 | PANEL_TOP = 60 |
---|
| 37 | _STATICBOX_WIDTH = 430 |
---|
| 38 | _BOX_WIDTH = 200 |
---|
[36f4debb] | 39 | PANEL_SIZE = 500 |
---|
[77d92cd] | 40 | FONT_VARIANT = 1 |
---|
| 41 | |
---|
| 42 | class ConverterPanel(ScrolledPanel, PanelBase): |
---|
| 43 | |
---|
| 44 | def __init__(self, parent, base=None, *args, **kwargs): |
---|
| 45 | ScrolledPanel.__init__(self, parent, *args, **kwargs) |
---|
| 46 | PanelBase.__init__(self) |
---|
[a58706d] | 47 | self.SetupScrolling() |
---|
[77d92cd] | 48 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 49 | |
---|
| 50 | self.base = base |
---|
| 51 | self.parent = parent |
---|
[de0df2c] | 52 | self.meta_frames = [] |
---|
[77d92cd] | 53 | |
---|
[a58706d] | 54 | self.q_input = None |
---|
| 55 | self.iq_input = None |
---|
| 56 | self.output = None |
---|
[4b862c4] | 57 | self.data_type = "ascii" |
---|
[a58706d] | 58 | |
---|
[503cc34] | 59 | self.title = None |
---|
| 60 | self.run = None |
---|
| 61 | self.run_name = None |
---|
| 62 | self.instrument = None |
---|
| 63 | self.detector = Detector() |
---|
| 64 | self.sample = Sample() |
---|
| 65 | self.source = Source() |
---|
| 66 | self.properties = ['title', 'run', 'run_name', 'instrument'] |
---|
| 67 | |
---|
| 68 | self.detector.name = '' |
---|
| 69 | self.source.radiation = 'neutron' |
---|
[4b862c4] | 70 | |
---|
[a58706d] | 71 | self._do_layout() |
---|
[77d92cd] | 72 | self.SetAutoLayout(True) |
---|
| 73 | self.Layout() |
---|
| 74 | |
---|
[94f4518] | 75 | def convert_to_cansas(self, frame_data, filename, single_file): |
---|
[8976865] | 76 | reader = CansasWriter() |
---|
[ea2a7348] | 77 | entry_attrs = None |
---|
| 78 | if self.run_name is not None: |
---|
| 79 | entry_attrs = { 'name': self.run_name } |
---|
[94f4518] | 80 | if single_file: |
---|
| 81 | reader.write(filename, frame_data, |
---|
| 82 | sasentry_attrs=entry_attrs) |
---|
| 83 | else: |
---|
| 84 | # strip extension from filename |
---|
| 85 | ext = "." + filename.split('.')[-1] |
---|
| 86 | name = filename.replace(ext, '') |
---|
| 87 | for i in range(len(frame_data)): |
---|
| 88 | f_name = "{}{}{}".format(name, i+1, ext) |
---|
| 89 | reader.write(f_name, [frame_data[i]], |
---|
| 90 | sasentry_attrs=entry_attrs) |
---|
[a58706d] | 91 | |
---|
| 92 | def extract_data(self, filename): |
---|
| 93 | data = np.loadtxt(filename, dtype=str) |
---|
| 94 | |
---|
[ff790b3] | 95 | if len(data.shape) != 1: |
---|
| 96 | msg = "Error reading {}: Only one column of data is allowed" |
---|
| 97 | raise Exception(msg.format(filename.split('\\')[-1])) |
---|
| 98 | |
---|
[a58706d] | 99 | is_float = True |
---|
| 100 | try: |
---|
| 101 | float(data[0]) |
---|
| 102 | except: |
---|
| 103 | is_float = False |
---|
| 104 | |
---|
| 105 | if not is_float: |
---|
| 106 | end_char = data[0][-1] |
---|
| 107 | # If lines end with comma or semi-colon, trim the last character |
---|
| 108 | if end_char == ',' or end_char == ';': |
---|
| 109 | data = map(lambda s: s[0:-1], data) |
---|
| 110 | else: |
---|
| 111 | msg = ("Error reading {}: Lines must end with a digit, comma " |
---|
| 112 | "or semi-colon").format(filename.split('\\')[-1]) |
---|
| 113 | raise Exception(msg) |
---|
| 114 | |
---|
| 115 | return np.array(data, dtype=np.float32) |
---|
| 116 | |
---|
[eb8da5f] | 117 | def ask_frame_range(self, n_frames): |
---|
| 118 | valid_input = False |
---|
| 119 | dlg = FrameSelectDialog(n_frames) |
---|
| 120 | frames = None |
---|
| 121 | increment = None |
---|
[94f4518] | 122 | single_file = True |
---|
[eb8da5f] | 123 | while not valid_input: |
---|
| 124 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 125 | msg = "" |
---|
| 126 | try: |
---|
| 127 | first_frame = int(dlg.first_input.GetValue()) |
---|
| 128 | last_frame = int(dlg.last_input.GetValue()) |
---|
| 129 | increment = int(dlg.increment_input.GetValue()) |
---|
[94f4518] | 130 | single_file = dlg.single_btn.GetValue() |
---|
[eb8da5f] | 131 | if last_frame < 0 or first_frame < 0: |
---|
| 132 | msg = "Frame values must be positive" |
---|
| 133 | elif increment < 1: |
---|
| 134 | msg = "Increment must be greater than or equal to 1" |
---|
| 135 | elif first_frame > last_frame: |
---|
| 136 | msg = "First frame must be less than last frame" |
---|
| 137 | elif last_frame > n_frames: |
---|
| 138 | msg = "Last frame must be less than {}".format(n_frames) |
---|
| 139 | else: |
---|
| 140 | valid_input = True |
---|
| 141 | except: |
---|
| 142 | valid_input = False |
---|
| 143 | msg = "Please enter valid integer values" |
---|
| 144 | |
---|
| 145 | if not valid_input: |
---|
| 146 | wx.PostEvent(self.parent.manager.parent, |
---|
| 147 | StatusEvent(status=msg)) |
---|
| 148 | else: |
---|
[94f4518] | 149 | return { 'frames': [], 'inc': None, 'file': single_file } |
---|
[eb8da5f] | 150 | frames = range(first_frame, last_frame + increment, |
---|
| 151 | increment) |
---|
[94f4518] | 152 | return { 'frames': frames, 'inc': increment, 'file': single_file } |
---|
[eb8da5f] | 153 | |
---|
[a58706d] | 154 | def on_convert(self, event): |
---|
[fdbea3c] | 155 | if not self.validate_inputs(): |
---|
| 156 | return |
---|
| 157 | |
---|
[503cc34] | 158 | self.sample.ID = self.title |
---|
[3ea9371] | 159 | |
---|
[a58706d] | 160 | try: |
---|
[4b862c4] | 161 | if self.data_type == 'ascii': |
---|
| 162 | qdata = self.extract_data(self.q_input.GetPath()) |
---|
| 163 | iqdata = self.extract_data(self.iq_input.GetPath()) |
---|
| 164 | else: # self.data_type == 'bsl' |
---|
| 165 | loader = BSLLoader(self.q_input.GetPath(), |
---|
| 166 | self.iq_input.GetPath()) |
---|
| 167 | bsl_data = loader.load_bsl_data() |
---|
| 168 | qdata = bsl_data.q_axis.data[0] |
---|
[eb8da5f] | 169 | iqdata = bsl_data.data_axis.data |
---|
| 170 | frames = [iqdata.shape[0]] |
---|
| 171 | increment = 1 |
---|
[94f4518] | 172 | single_file = True |
---|
[eb8da5f] | 173 | if frames[0] > 3: |
---|
[94f4518] | 174 | params = self.ask_frame_range(frames[0]) |
---|
| 175 | frames = params['frames'] |
---|
| 176 | increment = params['inc'] |
---|
| 177 | single_file = params['file'] |
---|
[eb8da5f] | 178 | if frames == []: return |
---|
[a58706d] | 179 | except Exception as ex: |
---|
| 180 | msg = str(ex) |
---|
| 181 | wx.PostEvent(self.parent.manager.parent, |
---|
| 182 | StatusEvent(status=msg, info='error')) |
---|
| 183 | return |
---|
| 184 | |
---|
[f2b3f28] | 185 | output_path = self.output.GetPath() |
---|
| 186 | |
---|
[d112c30] | 187 | if self.run is None: |
---|
[503cc34] | 188 | self.run = [] |
---|
[d112c30] | 189 | elif not isinstance(self.run, list): |
---|
| 190 | self.run = [self.run] |
---|
[503cc34] | 191 | |
---|
[ea2a7348] | 192 | if self.title is None: |
---|
| 193 | self.title = '' |
---|
| 194 | |
---|
[503cc34] | 195 | metadata = { |
---|
| 196 | 'title': self.title, |
---|
| 197 | 'run': self.run, |
---|
| 198 | 'intrument': self.instrument, |
---|
| 199 | 'detector': [self.detector], |
---|
| 200 | 'sample': self.sample, |
---|
| 201 | 'source': self.source |
---|
| 202 | } |
---|
[f2b3f28] | 203 | |
---|
[eb8da5f] | 204 | frame_data = [] |
---|
| 205 | for i in frames: |
---|
| 206 | data = Data1D(x=qdata, y=iqdata[i]) |
---|
| 207 | frame_data.append(data) |
---|
[94f4518] | 208 | if single_file: |
---|
| 209 | # Only need to set metadata on first Data1D object |
---|
| 210 | frame_data[0].filename = output_path.split('\\')[-1] |
---|
| 211 | for key, value in metadata.iteritems(): |
---|
| 212 | setattr(frame_data[0], key, value) |
---|
| 213 | else: |
---|
| 214 | # Need to set metadata for all Data1D objects |
---|
| 215 | for datainfo in frame_data: |
---|
| 216 | datainfo.filename = output_path.split('\\')[-1] |
---|
| 217 | for key, value in metadata.iteritems(): |
---|
| 218 | setattr(datainfo, key, value) |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | self.convert_to_cansas(frame_data, output_path, single_file) |
---|
[a58706d] | 222 | wx.PostEvent(self.parent.manager.parent, |
---|
| 223 | StatusEvent(status="Conversion completed.")) |
---|
| 224 | |
---|
[11794f2] | 225 | def on_help(self, event): |
---|
| 226 | tree_location = ("user/sasgui/perspectives/file_converter/" |
---|
| 227 | "file_converter_help.html") |
---|
| 228 | doc_viewer = DocumentationWindow(self, -1, tree_location, |
---|
| 229 | "", "File Converter Help") |
---|
| 230 | |
---|
[fdbea3c] | 231 | def validate_inputs(self): |
---|
| 232 | msg = "You must select a" |
---|
| 233 | if self.q_input.GetPath() == '': |
---|
| 234 | msg += " Q Axis input file." |
---|
| 235 | elif self.iq_input.GetPath() == '': |
---|
| 236 | msg += "n Intensity input file." |
---|
| 237 | elif self.output.GetPath() == '': |
---|
| 238 | msg += "destination for the converted file." |
---|
| 239 | if msg != "You must select a": |
---|
| 240 | wx.PostEvent(self.parent.manager.parent, |
---|
| 241 | StatusEvent(status=msg, info='error')) |
---|
| 242 | return |
---|
| 243 | |
---|
| 244 | return True |
---|
| 245 | |
---|
[af84162] | 246 | def show_detector_window(self, event): |
---|
[de0df2c] | 247 | if self.meta_frames != []: |
---|
| 248 | for frame in self.meta_frames: |
---|
| 249 | frame.panel.on_close() |
---|
| 250 | detector_frame = MetadataWindow(DetectorPanel, |
---|
| 251 | parent=self.parent.manager.parent, manager=self, |
---|
[503cc34] | 252 | metadata=self.detector, title='Detector Metadata') |
---|
[de0df2c] | 253 | self.meta_frames.append(detector_frame) |
---|
| 254 | self.parent.manager.put_icon(detector_frame) |
---|
| 255 | detector_frame.Show(True) |
---|
[fdbea3c] | 256 | |
---|
[2a7722b] | 257 | def show_sample_window(self, event): |
---|
| 258 | if self.meta_frames != []: |
---|
| 259 | for frame in self.meta_frames: |
---|
| 260 | frame.panel.on_close() |
---|
| 261 | sample_frame = MetadataWindow(SamplePanel, |
---|
| 262 | parent=self.parent.manager.parent, manager=self, |
---|
[503cc34] | 263 | metadata=self.sample, title='Sample Metadata') |
---|
[2a7722b] | 264 | self.meta_frames.append(sample_frame) |
---|
| 265 | self.parent.manager.put_icon(sample_frame) |
---|
| 266 | sample_frame.Show(True) |
---|
| 267 | |
---|
[55bc56bc] | 268 | def show_source_window(self, event): |
---|
| 269 | if self.meta_frames != []: |
---|
| 270 | for frame in self.meta_frames: |
---|
| 271 | frame.panel.on_close() |
---|
| 272 | source_frame = MetadataWindow(SourcePanel, |
---|
| 273 | parent=self.parent.manager.parent, manager=self, |
---|
[503cc34] | 274 | metadata=self.source, title="Source Metadata") |
---|
[55bc56bc] | 275 | self.meta_frames.append(source_frame) |
---|
| 276 | self.parent.manager.put_icon(source_frame) |
---|
| 277 | source_frame.Show(True) |
---|
| 278 | |
---|
[a027549] | 279 | def on_collapsible_pane(self, event): |
---|
| 280 | self.Freeze() |
---|
| 281 | self.SetupScrolling() |
---|
| 282 | self.parent.Layout() |
---|
| 283 | self.Thaw() |
---|
| 284 | |
---|
[4b862c4] | 285 | def datatype_changed(self, event): |
---|
| 286 | event.Skip() |
---|
| 287 | dtype = event.GetEventObject().GetName() |
---|
| 288 | self.data_type = dtype |
---|
| 289 | |
---|
[55775e8] | 290 | def radiationtype_changed(self, event): |
---|
| 291 | event.Skip() |
---|
| 292 | rtype = event.GetEventObject().GetValue().lower() |
---|
[503cc34] | 293 | self.source.radiation = rtype |
---|
[55775e8] | 294 | |
---|
[f2b3f28] | 295 | def metadata_changed(self, event): |
---|
| 296 | event.Skip() |
---|
| 297 | textbox = event.GetEventObject() |
---|
| 298 | attr = textbox.GetName() |
---|
| 299 | value = textbox.GetValue().strip() |
---|
[fdbea3c] | 300 | |
---|
[503cc34] | 301 | if value == '': value = None |
---|
| 302 | |
---|
| 303 | setattr(self, attr, value) |
---|
[f2b3f28] | 304 | |
---|
| 305 | |
---|
[77d92cd] | 306 | def _do_layout(self): |
---|
[f2b3f28] | 307 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[a58706d] | 308 | |
---|
[13b9a63] | 309 | instructions = ("Select either single column ASCII files or BSL/OTOKO" |
---|
| 310 | " files containing the Q-Axis and Intensity-axis data, chose where" |
---|
| 311 | " to save the converted file, then click Convert to convert them " |
---|
| 312 | "to CanSAS XML format. If required, metadata can also be input " |
---|
| 313 | "below.") |
---|
[5afe77f] | 314 | instruction_label = wx.StaticText(self, -1, instructions, |
---|
| 315 | size=(_STATICBOX_WIDTH+40, -1)) |
---|
| 316 | instruction_label.Wrap(_STATICBOX_WIDTH+40) |
---|
[f2b3f28] | 317 | vbox.Add(instruction_label, flag=wx.TOP | wx.LEFT | wx.RIGHT, border=5) |
---|
[77d92cd] | 318 | |
---|
[a58706d] | 319 | section = wx.StaticBox(self, -1) |
---|
| 320 | section_sizer = wx.StaticBoxSizer(section, wx.VERTICAL) |
---|
| 321 | section_sizer.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
[77d92cd] | 322 | |
---|
| 323 | input_grid = wx.GridBagSizer(5, 5) |
---|
| 324 | |
---|
[4b862c4] | 325 | y = 0 |
---|
| 326 | |
---|
[13b9a63] | 327 | q_label = wx.StaticText(self, -1, "Q-Axis Data: ") |
---|
[4b862c4] | 328 | input_grid.Add(q_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) |
---|
[a58706d] | 329 | |
---|
| 330 | self.q_input = wx.FilePickerCtrl(self, -1, |
---|
| 331 | size=(_STATICBOX_WIDTH-80, -1), |
---|
[13b9a63] | 332 | message="Chose the Q-Axis data file.") |
---|
[4b862c4] | 333 | input_grid.Add(self.q_input, (y,1), (1,1), wx.ALL, 5) |
---|
| 334 | y += 1 |
---|
[a58706d] | 335 | |
---|
[13b9a63] | 336 | iq_label = wx.StaticText(self, -1, "Intensity-Axis Data: ") |
---|
[4b862c4] | 337 | input_grid.Add(iq_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) |
---|
[a58706d] | 338 | |
---|
| 339 | self.iq_input = wx.FilePickerCtrl(self, -1, |
---|
| 340 | size=(_STATICBOX_WIDTH-80, -1), |
---|
[13b9a63] | 341 | message="Chose the Intensity-Axis data file.") |
---|
[4b862c4] | 342 | input_grid.Add(self.iq_input, (y,1), (1,1), wx.ALL, 5) |
---|
| 343 | y += 1 |
---|
| 344 | |
---|
| 345 | data_type_label = wx.StaticText(self, -1, "Input Format: ") |
---|
| 346 | input_grid.Add(data_type_label, (y,0), (1,1), |
---|
| 347 | wx.ALIGN_CENTER_VERTICAL, 5) |
---|
| 348 | radio_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 349 | ascii_btn = wx.RadioButton(self, -1, "ASCII", name="ascii", |
---|
| 350 | style=wx.RB_GROUP) |
---|
| 351 | ascii_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) |
---|
| 352 | radio_sizer.Add(ascii_btn) |
---|
[13b9a63] | 353 | bsl_btn = wx.RadioButton(self, -1, "BSL/OTOKO", name="bsl") |
---|
[4b862c4] | 354 | bsl_btn.Bind(wx.EVT_RADIOBUTTON, self.datatype_changed) |
---|
| 355 | radio_sizer.Add(bsl_btn) |
---|
| 356 | input_grid.Add(radio_sizer, (y,1), (1,1), wx.ALL, 5) |
---|
| 357 | y += 1 |
---|
[a58706d] | 358 | |
---|
[55775e8] | 359 | radiation_label = wx.StaticText(self, -1, "Radiation Type: ") |
---|
| 360 | input_grid.Add(radiation_label, (y,0), (1,1), wx.ALL, 5) |
---|
| 361 | radiation_input = wx.ComboBox(self, -1, |
---|
| 362 | choices=["Neutron", "X-Ray", "Muon", "Electron"], |
---|
| 363 | name="radiation", style=wx.CB_READONLY, value="Neutron") |
---|
| 364 | radiation_input.Bind(wx.EVT_COMBOBOX, self.radiationtype_changed) |
---|
| 365 | input_grid.Add(radiation_input, (y,1), (1,1)) |
---|
| 366 | y += 1 |
---|
| 367 | |
---|
[a58706d] | 368 | output_label = wx.StaticText(self, -1, "Output File: ") |
---|
[4b862c4] | 369 | input_grid.Add(output_label, (y,0), (1,1), wx.ALIGN_CENTER_VERTICAL, 5) |
---|
[a58706d] | 370 | |
---|
| 371 | self.output = wx.FilePickerCtrl(self, -1, |
---|
| 372 | size=(_STATICBOX_WIDTH-80, -1), |
---|
[55775e8] | 373 | message="Chose where to save the output file.", |
---|
[a58706d] | 374 | style=wx.FLP_SAVE | wx.FLP_OVERWRITE_PROMPT | wx.FLP_USE_TEXTCTRL, |
---|
| 375 | wildcard="*.xml") |
---|
[4b862c4] | 376 | input_grid.Add(self.output, (y,1), (1,1), wx.ALL, 5) |
---|
| 377 | y += 1 |
---|
[a58706d] | 378 | |
---|
[fdbea3c] | 379 | convert_btn = wx.Button(self, wx.ID_OK, "Convert") |
---|
[4b862c4] | 380 | input_grid.Add(convert_btn, (y,0), (1,1), wx.ALL, 5) |
---|
[a58706d] | 381 | convert_btn.Bind(wx.EVT_BUTTON, self.on_convert) |
---|
[77d92cd] | 382 | |
---|
[11794f2] | 383 | help_btn = wx.Button(self, -1, "HELP") |
---|
| 384 | input_grid.Add(help_btn, (y,1), (1,1), wx.ALL, 5) |
---|
| 385 | help_btn.Bind(wx.EVT_BUTTON, self.on_help) |
---|
| 386 | |
---|
[a58706d] | 387 | section_sizer.Add(input_grid) |
---|
[77d92cd] | 388 | |
---|
[f2b3f28] | 389 | vbox.Add(section_sizer, flag=wx.ALL, border=5) |
---|
| 390 | |
---|
| 391 | metadata_section = wx.CollapsiblePane(self, -1, "Metadata", |
---|
[fdbea3c] | 392 | size=(_STATICBOX_WIDTH+40, -1), style=wx.WS_EX_VALIDATE_RECURSIVELY) |
---|
| 393 | metadata_pane = metadata_section.GetPane() |
---|
[f2b3f28] | 394 | metadata_grid = wx.GridBagSizer(5, 5) |
---|
| 395 | |
---|
[a027549] | 396 | metadata_section.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, |
---|
| 397 | self.on_collapsible_pane) |
---|
| 398 | |
---|
[f2b3f28] | 399 | y = 0 |
---|
[503cc34] | 400 | for item in self.properties: |
---|
[7c8ddb83] | 401 | # Capitalise each word |
---|
| 402 | label_txt = " ".join( |
---|
| 403 | [s.capitalize() for s in item.replace('_', ' ').split(' ')]) |
---|
| 404 | if item == 'run': |
---|
| 405 | label_txt = "Run Number" |
---|
[fdbea3c] | 406 | label = wx.StaticText(metadata_pane, -1, label_txt, |
---|
[f2b3f28] | 407 | style=wx.ALIGN_CENTER_VERTICAL) |
---|
[fdbea3c] | 408 | input_box = wx.TextCtrl(metadata_pane, name=item, |
---|
[f2b3f28] | 409 | size=(_STATICBOX_WIDTH-80, -1)) |
---|
| 410 | input_box.Bind(wx.EVT_TEXT, self.metadata_changed) |
---|
| 411 | metadata_grid.Add(label, (y,0), (1,1), |
---|
| 412 | wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) |
---|
[fdbea3c] | 413 | metadata_grid.Add(input_box, (y,1), (1,2), wx.EXPAND) |
---|
[f2b3f28] | 414 | y += 1 |
---|
| 415 | |
---|
[fdbea3c] | 416 | detector_label = wx.StaticText(metadata_pane, -1, |
---|
| 417 | "Detector:") |
---|
| 418 | metadata_grid.Add(detector_label, (y, 0), (1,1), wx.ALL | wx.EXPAND, 5) |
---|
[af84162] | 419 | detector_btn = wx.Button(metadata_pane, -1, "Enter Detector Metadata") |
---|
| 420 | metadata_grid.Add(detector_btn, (y, 1), (1,1), wx.ALL | wx.EXPAND, 5) |
---|
| 421 | detector_btn.Bind(wx.EVT_BUTTON, self.show_detector_window) |
---|
[fdbea3c] | 422 | y += 1 |
---|
| 423 | |
---|
[2a7722b] | 424 | sample_label = wx.StaticText(metadata_pane, -1, "Sample: ") |
---|
| 425 | metadata_grid.Add(sample_label, (y,0), (1,1), wx.ALL | wx.EXPAND, 5) |
---|
| 426 | sample_btn = wx.Button(metadata_pane, -1, "Enter Sample Metadata") |
---|
| 427 | metadata_grid.Add(sample_btn, (y,1), (1,1), wx.ALL | wx.EXPAND, 5) |
---|
| 428 | sample_btn.Bind(wx.EVT_BUTTON, self.show_sample_window) |
---|
| 429 | y += 1 |
---|
| 430 | |
---|
[55bc56bc] | 431 | source_label = wx.StaticText(metadata_pane, -1, "Source: ") |
---|
| 432 | metadata_grid.Add(source_label, (y,0), (1,1), wx.ALL | wx.EXPAND, 5) |
---|
| 433 | source_btn = wx.Button(metadata_pane, -1, "Enter Source Metadata") |
---|
| 434 | source_btn.Bind(wx.EVT_BUTTON, self.show_source_window) |
---|
| 435 | metadata_grid.Add(source_btn, (y,1), (1,1), wx.ALL | wx.EXPAND, 5) |
---|
| 436 | y += 1 |
---|
| 437 | |
---|
[fdbea3c] | 438 | metadata_pane.SetSizer(metadata_grid) |
---|
[f2b3f28] | 439 | |
---|
| 440 | vbox.Add(metadata_section, proportion=0, flag=wx.ALL, border=5) |
---|
[77d92cd] | 441 | |
---|
| 442 | vbox.Fit(self) |
---|
| 443 | self.SetSizer(vbox) |
---|
| 444 | |
---|
| 445 | class ConverterWindow(widget.CHILD_FRAME): |
---|
| 446 | |
---|
| 447 | def __init__(self, parent=None, title='File Converter', base=None, |
---|
[a027549] | 448 | manager=None, size=(PANEL_SIZE * 1.05, PANEL_SIZE / 1.25), |
---|
[77d92cd] | 449 | *args, **kwargs): |
---|
| 450 | kwargs['title'] = title |
---|
| 451 | kwargs['size'] = size |
---|
| 452 | widget.CHILD_FRAME.__init__(self, parent, *args, **kwargs) |
---|
| 453 | |
---|
| 454 | self.manager = manager |
---|
| 455 | self.panel = ConverterPanel(self, base=None) |
---|
| 456 | self.Bind(wx.EVT_CLOSE, self.on_close) |
---|
| 457 | self.SetPosition((wx.LEFT, PANEL_TOP)) |
---|
| 458 | self.Show(True) |
---|
| 459 | |
---|
| 460 | def on_close(self, event): |
---|
| 461 | if self.manager is not None: |
---|
| 462 | self.manager.converter_frame = None |
---|
| 463 | self.Destroy() |
---|