Example #1
0
 def OnMenuOptimizePositions(self, event):
     frm = frame_optimizer.get_instance(parent=self)
     frm.Show()
     frm.Raise()
     event.Skip()
 def OnMenuOptimizePositions(self, event):
     frm = frame_optimizer.get_instance(parent=self)
     frm.Show()
     frm.Raise()
     event.Skip()
Example #3
0
def user_guide_script():

    #------- Initial --------------------------------------------
    #Shortcuts to the tested objects
    #@type fm FrameMain
    #@type fv FrameQspaceView
    exp = model.experiment.exp
    inst = model.experiment.exp.inst

    original_size = fm.GetSize()

    ca(screenshot_frame, fm, 'frame_main')
    wait(50)

    #Set the view in the 3D view
    (azimuth, elevation, distance, focalpoint) = fv.controller.scene.mlab.view()
    ca(fv.controller.scene.mlab.view, distance=distance/1.35)
    #Parallel projection off
    ca(fv.controller.scene.__setattr__, 'parallel_projection', False)

#    make_animated_tab_click(fm)
    #warnings.warn("Hey! Turn the animated tab maker back on!")
    
    # --------------------- Q-Space Tab --------------------
    ca(fm.notebook.SetSelection, 0)
    wait(100)
    #Settings for the guide
    #@type params StartupParameters
    params = fm.tab_startup.params
    params.d_min = 1.0
    params.q_resolution = 0.1
    params.wl_min = 0.5
    params.wl_max = 4.0
    wait(100)
    ca(screenshot_of, fm.tab_startup.control, 'startup-traits', minheight=True, margin=10, gradient_edge=0)
    ca(screenshot_of, fm.tab_startup.buttonApply, 'startup-apply', margin=5)
    ca(click, fm.tab_startup.buttonApply)
    wait(1200)

    # ------------------------ Detectors tab ----------------------
    ca(fm.notebook.SetSelection, 1)
    wait(100)
    #@type td PanelDetectors
    td = fm.tab_detectors
    wait(30)
    ca(screenshot_of, td.buttonLoadDetectors, 'detectors-buttonLoadDetectors',  margin=6, gradient_edge=4)
    wait(50)
    ca(screenshot_of, td.button_view_detectors, 'detectors-button_view_detectors', margin=6, gradient_edge=4)
    wait(30)
    ca(td.controller.load_detector_file, "../instruments/TOPAZ_detectors_all.csv")
    waitfor( 'len(model.instrument.inst.detectors) >= 48' )
    assert len(inst.detectors) == 48, "loaded 48 detectors from TOPAZ. We have %d" % len(inst.detectors)

#    #3d shot of detectors
#    ca(click, td.button_view_detectors)
#    wait(2000)
#    ca(screenshot_frame, td.frame3d, 'detectors-3d_view')
#    #Bring back the main window
#    ca(fm.Raise)
#    wait(100)


    # ------------------------ goniometer tab ----------------------
    ca(fm.notebook.SetSelection, 2)
    wait(250)
    #@type tg PanelGoniometer
    tg = fm.tab_goniometer
    ca(screenshot_of, tg.currentControl, 'goniometer-selected', minheight=True, margin=[10, 10, 40, 10], gradient_edge=4)
    ca(screenshot_of, tg.buttonEditAngles, 'goniometer-buttonEditAngles', margin=6, gradient_edge=0)
    ca(screenshot_of, tg.buttonApplyChanges, 'goniometer-buttonApplyChanges', margin=6, gradient_edge=0)
    ca(screenshot_of, tg.buttonSwitchGoniometer, 'goniometer-buttonSwitchGoniometer', margin=6, gradient_edge=0)
    #Select the TopazInHouseGoniometer and switch to it
    ca(select_name, tg.choiceGonio, model.goniometer.TopazInHouseGoniometer().name)
    wait(50)
    ca(screenshot_of, tg.choiceGonio, 'goniometer-choice', margin=6, gradient_edge=0)
    ca(screenshot_of, [tg.staticTextDesc, tg.staticTextDescLabel], 'goniometer-desc', margin=6, gradient_edge=0)
    ca(click, tg.buttonSwitchGoniometer)
    wait(100)
    assert isinstance(inst.goniometer, model.goniometer.TopazInHouseGoniometer), "we picked a TopazInHouseGoniometer"

    # ------------------------- Sample tab -----------------------
    ca(fm.notebook.SetSelection, 3)
    wait(250)
    #@type ts PanelSample
    ts = fm.tab_sample
    ca(screenshot_of, ts.crystal_control, 'sample-info', margin=10, gradient_edge=0)
    ca(screenshot_of, ts.buttonEditCrystal, 'sample-buttonEditCrystal', margin=5)
    ca(click, ts.buttonEditCrystal)
    wait(500)
    #@type dlg DialogEditCrystal
    dlg = dialog_edit_crystal.last_dialog
    dlg.crystal.name = "Quartz Crystal"
    dlg.crystal.description = "Tutorial sample of quartz."
    wait(50)
    ca(screenshot_frame, dlg, 'dialog_edit_crystal', top_only=80)
    ca(dlg.notebook.SetSelection, 1)
    wait(50)
    ca(screenshot_of, dlg.notebook, 'dialog_edit_crystal-notebook1', margin=10)
    ca(screenshot_of, dlg.buttonGenerateUB, 'dialog_edit_crystal-buttonGenerateUB', margin=6)
    ca(dlg.notebook.SetSelection, 0)
    wait(50)
    ca(screenshot_of, dlg.boxSizerIsaw, 'dialog_edit_crystal-notebook0', margin=[16, 16, 46, 16], gradient_edge=6, minheight=True)
    ca(screenshot_of, dlg.buttonReadUB, 'dialog_edit_crystal-buttonReadUB', margin=6)
    ca(screenshot_of, dlg.buttonOK, 'dialog_edit_crystal-buttonOK', margin=6)
    ca(screenshot_of, dlg.buttonCancel, 'dialog_edit_crystal-buttonCancel', margin=6)
    angles = np.array([30, 15, 60])
    (phi, chi, omega) = angles
    dlg.ub_orientation.phi_degrees = phi
    dlg.ub_orientation.chi_degrees = chi
    dlg.ub_orientation.omega_degrees = omega
    wait(50)
    ca(screenshot_of, dlg.control_load_angles, 'dialog_edit_crystal-control_load_angles', margin=6)
    ca(dlg.crystal.read_ISAW_ubmatrix_file, "../model/data/quartzub.txt", np.deg2rad(angles))
    wait(200)
    ca(screenshot_of, dlg.control_top, 'dialog_edit_crystal-control_top', margin=6)
    ca(click, dlg.buttonOK)
    wait(500)

    ca(screenshot_of, ts.range_control, 'sample-range_control', margin=10, gradient_edge=0)
    ca(screenshot_of, ts.buttonApplyRange, 'sample-buttonApplyRange', margin=10, gradient_edge=0)

    # ------------------------- Trial Positions tab -----------------------
    ca(fm.notebook.SetSelection, 4)
    wait(40)
    #Make the main window narrower
    ca(fm.SetSize, wx.Size(500, original_size[1]))
    wait(150)
    #@type tt PanelTryPosition
    tt = fm.tab_try
    ca(screenshot_of, tt.boxSizerAll, 'try', minheight=True, margin=[10, 10, 40, 10], gradient_edge=5)
    #Check the box
    ca(check, tt.checkAdd, True)
    wait(100)
    ca(screenshot_of, tt.checkAdd, 'try-checkAdd', margin=6, gradient_edge=2)
    wait(40)

    #@type slid ValueSlider
    slid = tt.sliders[0]
    ca(slid.SetValue, -30)
    wait(50)
    ca(slid.SendScrollEndEvent)
    wait(500)
    ca(screenshot_of, slid, 'try-phi-30', margin=6, gradient_edge=2)

    # ------------------------ 3D Viewer! ----------------------
    #The whole frame
    ca(fv.Raise) #Bring it to front first!
    wait(300)

    ca(screenshot_frame, fv, 'frame_qspace')

    #Animate a phi rotation
    wait(100)
    #make_animated_phi_rotation(slid, fv, "3d-phi_rotation_anim.png")
    #make_animated_phi_rotation(tt.sliders[1], fv, "3d-chi_rotation_anim.png")

    # ------------------------ Try Positions, bad goniometer ----------------------
    ca(fm.Raise)

    #Set a chi of +45 deg
    slid = tt.sliders[1]
    ca(slid.SetValue, +45)
    ca(slid.SendScrollEvent) #Trigger the showing the warning
    wait(150)
    ca(screenshot_of, slid, 'try-chi-45', margin=6, gradient_edge=2)
    ca(screenshot_of, [tt.staticTextWarning, tt.staticTextWarningReason], 'try-staticTextWarning', margin=6)
    ca(screenshot_of, tt.buttonSave, 'try-buttonSave', margin=6)
    #un-check the box
    ca(check, tt.checkAdd, False)


    # ------------------------ Add Orientations tab ----------------------
    ca(fm.notebook.SetSelection, 5)

    #@type ta PanelAddPositions
    ta = fm.tab_add

    waitfor_set(ta.textWarnings.GetValue)
    ca(ta.controller.textAngles[0].SetValue, "0, 10, 35.5")
    ca(ta.controller.textAngles[1].SetValue, "arange(0, 50, 12.5)")
    ca(ta.controller.textAngles[2].SetValue, "linspace(0, 360, 6)")
    waitfor_change()
    ca(screenshot_of, [ta.boxSizerAngles] , 'add-lists', margin=12)
    ca(ta.controller.textAngles[0].SetValue, "0")
    ca(ta.controller.textAngles[1].SetValue, "arange(-20, 20, 5)")
    ca(ta.controller.textAngles[2].SetValue, "0")
    waitfor_change()
    ca(screenshot_of, [ta.staticTextWarnings, ta.textWarnings], 'add-textWarnings', margin=12)
    ca(screenshot_of, ta.boxSizerAngles , 'add-lists2', margin=12)
    ca(ta.controller.textAngles[0].SetValue, "0, 30, 60, 90")
    ca(ta.controller.textAngles[1].SetValue, "0")
    ca(ta.controller.textAngles[2].SetValue, "0")
    waitfor_change()
    ca(screenshot_of, ta.boxSizerAngles , 'add-lists3', margin=12)
    wait(50)
    ca(screenshot_of, [ta.buttonCalculate, ta.buttonCancel] , 'add-start_button', margin=20)
    ca(click, ta.buttonCalculate)
    #Delay util the progress bar has something
    waitfor('len(model.experiment.exp.inst.positions) > 1')
    ca(screenshot_of, [ta.gaugeProgress, ta.staticTextProgress] , 'add-progress_bar', margin=10)
    wait(30)
    ca(screenshot_of, [ta.buttonCalculate, ta.buttonCancel] , 'add-cancel_button', margin=20)
    #Wait till done
    waitfor('len(model.experiment.exp.inst.positions) >= 4')
    wait(50)
    #assert len(model.experiment.exp.inst.positions)==2, "Length of positions calculated was to be 19, it was %d." % len(model.experiment.exp.inst.positions)

    # ------------------------ Experiment Plan tab ----------------------
    ca(fm.notebook.SetSelection, 6)

    #Restore the window width
    ca(fm.SetSize, original_size)
    wait(150)

    #@type te PanelExperiment
    te = fm.tab_experiment

    ca(te.gridExp.SelectBlock, 1,0,1,100)
    wait(50)
    ca(screenshot_of, te.gridExp, 'exp-grid', margin=12)
    ca(screenshot_of, te.boxSizerDelete, 'exp-delete_buttons', margin=8)
    ca(screenshot_of, [te.checkUseAll, te.buttonDontUseHighlighted], 'exp-select_buttons', margin=8)
    ca(screenshot_of, te.buttonSaveToCSV, 'exp-buttonSaveToCSV', margin=6)
    ca(screenshot_of, te.buttonOptimizer, 'exp-buttonOptimizer', margin=6)
    ca(screenshot_of, te.staticTextEstimatedTime, 'exp-estimated_time', margin=6)
    wait(50)

    # ------------------------ Back to 3D view----------------------
    #The q-space options panel
    #@type tv PanelQspaceOptions
    tv = fv.tabVolume

    ca(fv.Raise)
    wait(50)

    control_margins = [-180, -180, -30, -10]
    control_gradient_edge = 100
    check_margin = 4

    ca(screenshot_frame, fv, '3d-4orientations')
    ca(screenshot_of, fv.panelStats, '3d-panelStats', margin=10)
    ca(screenshot_of, tv.sliceControl, '3d-sliceControl', margin=10)


    ca(screenshot_of, tv.checkSymmetry, 'volume_options-checkSymmetry', margin=check_margin)
    ca(check, tv.checkSymmetry, True)
    wait(600)
    ca(screenshot_of, fv.control, '3d-symmetry', margin=control_margins, gradient_edge=control_gradient_edge)
    ca(screenshot_of, fv.panelStats, '3d-panelStats-symmetry', margin=10)

    ca(screenshot_of, tv.checkInvert, 'volume_options-checkInvert', margin=check_margin)
    ca(check, tv.checkInvert, True)
    wait(600)
    ca(screenshot_of, fv.control, '3d-inverted', margin=control_margins, gradient_edge=control_gradient_edge)
    ca(check, tv.checkInvert, False)
    ca(check, tv.checkSymmetry, False)
    ca(check, tv.checkShowRedundancy, True)
    wait(1200)

    ca(screenshot_of, tv.checkShowRedundancy, 'volume_options-checkShowRedundancy', margin=check_margin)
    ca(screenshot_of, fv.control, '3d-redundancy', margin=control_margins, gradient_edge=control_gradient_edge)

    ca(screenshot_of, tv.checkShowSlice, 'volume_options-checkShowSlice', margin=check_margin)
    tv.sliceControl.slice_min = 3
    tv.sliceControl.slice_max = 3.5
    wait(30)
    ca(check, tv.checkShowRedundancy, False)
    ca(check, tv.checkShowSlice, True)
    wait(600)
    ca(screenshot_of, tv.sliceControl, '3d-sliceControl-on', margin=10)
    ca(screenshot_of, fv.control, '3d-slice', margin=control_margins, gradient_edge=control_gradient_edge)
    ca(check, tv.checkShowRedundancy, True)
    wait(900)
    ca(screenshot_of, fv.control, '3d-slice-redundancy', margin=control_margins, gradient_edge=control_gradient_edge)


    # ------------------------ Reflections View ---------------------
    #@type tr PanelReflectionsViewOptions
    tr = fv.tabReflections

    #Select it
    ca(fv.notebookView.SetSelection, 1)
    wait(800)
    ca(screenshot_frame, fv, '3d-reflections')
    ca(screenshot_of, fv.panelStats, '3drefs-panelStats-normal', margin=10)

    #Only the measured peaks
    ca(tr.choiceView.SetSelection, 1)
    ca(call_event, tr.choiceView, wx.EVT_CHOICE)
    wait(400)
    ca(screenshot_of, fv.control, '3drefs-measured', margin=control_margins, gradient_edge=control_gradient_edge)
    ca(screenshot_of, tr.boxSizerDisplay, '3drefs-display', margin=10, gradient_edge=4)
    ca(screenshot_of, [tr.staticTextViewOption, tr.choiceView], '3drefs-view_option', margin=check_margin, gradient_edge=2)
    ca(screenshot_of, tr.checkUseSymmetry, '3drefs-checkUseSymmetry', margin=check_margin)

    #Use symmetry
    ca(check, tr.checkUseSymmetry, True)
    ca(tr.choiceView.SetSelection, 0)
    ca(call_event, tr.choiceView, wx.EVT_CHOICE)
    wait(400)
    ca(screenshot_of, fv.control, '3drefs-measured-symmetry', margin=control_margins, gradient_edge=control_gradient_edge)
    ca(screenshot_of, fv.panelStats, '3drefs-panelStats-symmetry', margin=10)

    ca(fv.controller.scene.__setattr__, 'parallel_projection', True)
    wait(400)
    ca(screenshot_of, fv.control, '3drefs-parallel', margin=control_margins, gradient_edge=control_gradient_edge)
    ca(fv.controller.scene.__setattr__, 'parallel_projection', False)
    wait(400)
    
    #--- Find a reflection to display ---
    #Simulate a left-click
    ca(fv.controller.on_button_press, FakeClickObject(50,50), None)
#    refl = pick_a_reflection()
#    #Select it
#    ca(fv.controller.select_reflection, refl)

    wait(250)
    ca(screenshot_of, fv.control, '3drefs-reflection_selected', margin=control_margins, gradient_edge=control_gradient_edge)
    #@type fri FrameReflectionInfo
    fri = fv.controller.open_frame_reflection_info()
    ca(screenshot_frame, fri, 'ref_info')
    #@type pri PanelReflectionInfo
    pri = fri.panel

    #Put in bad values for hkl
    ca(pri.textCtrlH.SetValue, "20")
    wait(40)
    ca(screenshot_of, [pri.staticTextHKLLabel, pri.gridSizerHKL], 'ref_info-bad_hkl', margin=10, gradient_edge=5)
    ca(pri.textCtrlH.SetValue, "3")
    ca(pri.textCtrlK.SetValue, "2")
    ca(pri.textCtrlL.SetValue, "-4")
    wait(300)
    size = fri.GetSize()
    ca(fri.SetSize, wx.Size(size[0], 600))
    ca(screenshot_of, pri, 'ref_info2', margin=5, gradient_edge=0)
    #Check it
    ca(check, pri.checkUseEquivalent, True)
    ca(screenshot_of, pri.checkUseEquivalent, 'ref_info-checkUseEquivalent', margin=4, gradient_edge=2)
    ca(screenshot_of, pri.boxSizerDivergence, 'ref_info-textCtrlDivergence', margin=4, gradient_edge=2)
    wait(150)
    ca(screenshot_of, pri, 'ref_info2-equivalent', margin=5, gradient_edge=0)


    #--------------- Measured Reflections -------------
    #@type tr PanelReflectionsViewOptions
    tr = fv.tabReflections
    #Load some peaks file
    ca(model.experiment.exp.load_peaks_file, "../model/data/TOPAZ_1241.integrate", append=False)
    wait(1000)
    ca(display_thread.handle_change_of_qspace)
    wait(1000)
    ca(screenshot_of, tr.boxSizerColor, 'refl-measurements',  margin=6, gradient_edge=2)

#---END---


    #--------------- The Reflection Placer -------------

    #@type prm PanelReflectionMeasurement
    prm = pri.measure_panels[0][0]
    ca(screenshot_of, prm, 'prm', margin=5, gradient_edge=0)
    ca(screenshot_of, prm.buttonPlace, 'prm-buttonPlace', margin=5, gradient_edge=0)
    ca(click, prm.buttonPlace)
    wait(800)

    #@type frp FrameReflectionPlacer
    global frp
    frp = prm.last_placer_frame
    #Wait for calculation to be done
    wait(3800)
    frp.placer.xy[0] = -5
    wait(100)
    ca(screenshot_frame, frp, 'ref_placer')
    ca(screenshot_of, frp.buttonAddOrientation, 'ref_placer-buttonAddOrientation', margin=4, gradient_edge=2)

#---END---
    

    #--- Automatic coverage optimizer ---
    #@type te PanelExperiment
    te = fm.tab_experiment
    ca(click, te.buttonOptimizer)
    wait(500)
    #@type fo FrameOptimizer
    fo = frame_optimizer.get_instance(fm)
    wait(500)
    fo.Raise()
    ca(screenshot_of, fo.buttonStart, 'optim-buttonStart',  margin=6, gradient_edge=2)
    ca(click, fo.buttonStart)
    wait(500)
    ca(screenshot_of, fo.buttonStop, 'optim-buttonStop',  margin=6, gradient_edge=2)
    ca(screenshot_of, fo.buttonApply, 'optim-buttonApply',  margin=6, gradient_edge=2)
    wait(2500)
    ca(screenshot_frame, fo, 'frame_optimizer')
    #Stop
    ca(click, fo.buttonStop)
    wait(500)
    ca(screenshot_of, fo.buttonKeepGoing, 'optim-buttonKeepGoing',  margin=6, gradient_edge=2)
Example #4
0
 def OnButtonOptimizer(self, event):
     frm = frame_optimizer.get_instance(parent=self)
     frm.Show()
     frm.Raise()
     event.Skip()
Example #5
0
def user_guide_script():

    #------- Initial --------------------------------------------
    #Shortcuts to the tested objects
    #@type fm FrameMain
    #@type fv FrameQspaceView
    exp = model.experiment.exp
    inst = model.experiment.exp.inst

    original_size = fm.GetSize()

    ca(screenshot_frame, fm, 'frame_main')
    wait(50)

    #Set the view in the 3D view
    (azimuth, elevation, distance,
     focalpoint) = fv.controller.scene.mlab.view()
    ca(fv.controller.scene.mlab.view, distance=distance / 1.35)
    #Parallel projection off
    ca(fv.controller.scene.__setattr__, 'parallel_projection', False)

    #    make_animated_tab_click(fm)
    #warnings.warn("Hey! Turn the animated tab maker back on!")

    # --------------------- Q-Space Tab --------------------
    ca(fm.notebook.SetSelection, 0)
    wait(100)
    #Settings for the guide
    #@type params StartupParameters
    params = fm.tab_startup.params
    params.d_min = 1.0
    params.q_resolution = 0.1
    params.wl_min = 0.5
    params.wl_max = 4.0
    wait(100)
    ca(screenshot_of,
       fm.tab_startup.control,
       'startup-traits',
       minheight=True,
       margin=10,
       gradient_edge=0)
    ca(screenshot_of, fm.tab_startup.buttonApply, 'startup-apply', margin=5)
    ca(click, fm.tab_startup.buttonApply)
    wait(1200)

    # ------------------------ Detectors tab ----------------------
    ca(fm.notebook.SetSelection, 1)
    wait(100)
    #@type td PanelDetectors
    td = fm.tab_detectors
    wait(30)
    ca(screenshot_of,
       td.buttonLoadDetectors,
       'detectors-buttonLoadDetectors',
       margin=6,
       gradient_edge=4)
    wait(50)
    ca(screenshot_of,
       td.button_view_detectors,
       'detectors-button_view_detectors',
       margin=6,
       gradient_edge=4)
    wait(30)
    ca(td.controller.load_detector_file,
       "../instruments/TOPAZ_detectors_all.csv")
    waitfor('len(model.instrument.inst.detectors) >= 48')
    assert len(
        inst.detectors
    ) == 48, "loaded 48 detectors from TOPAZ. We have %d" % len(inst.detectors)

    #    #3d shot of detectors
    #    ca(click, td.button_view_detectors)
    #    wait(2000)
    #    ca(screenshot_frame, td.frame3d, 'detectors-3d_view')
    #    #Bring back the main window
    #    ca(fm.Raise)
    #    wait(100)

    # ------------------------ goniometer tab ----------------------
    ca(fm.notebook.SetSelection, 2)
    wait(250)
    #@type tg PanelGoniometer
    tg = fm.tab_goniometer
    ca(screenshot_of,
       tg.currentControl,
       'goniometer-selected',
       minheight=True,
       margin=[10, 10, 40, 10],
       gradient_edge=4)
    ca(screenshot_of,
       tg.buttonEditAngles,
       'goniometer-buttonEditAngles',
       margin=6,
       gradient_edge=0)
    ca(screenshot_of,
       tg.buttonApplyChanges,
       'goniometer-buttonApplyChanges',
       margin=6,
       gradient_edge=0)
    ca(screenshot_of,
       tg.buttonSwitchGoniometer,
       'goniometer-buttonSwitchGoniometer',
       margin=6,
       gradient_edge=0)
    #Select the TopazInHouseGoniometer and switch to it
    ca(select_name, tg.choiceGonio,
       model.goniometer.TopazInHouseGoniometer().name)
    wait(50)
    ca(screenshot_of,
       tg.choiceGonio,
       'goniometer-choice',
       margin=6,
       gradient_edge=0)
    ca(screenshot_of, [tg.staticTextDesc, tg.staticTextDescLabel],
       'goniometer-desc',
       margin=6,
       gradient_edge=0)
    ca(click, tg.buttonSwitchGoniometer)
    wait(100)
    assert isinstance(inst.goniometer, model.goniometer.TopazInHouseGoniometer
                      ), "we picked a TopazInHouseGoniometer"

    # ------------------------- Sample tab -----------------------
    ca(fm.notebook.SetSelection, 3)
    wait(250)
    #@type ts PanelSample
    ts = fm.tab_sample
    ca(screenshot_of,
       ts.crystal_control,
       'sample-info',
       margin=10,
       gradient_edge=0)
    ca(screenshot_of,
       ts.buttonEditCrystal,
       'sample-buttonEditCrystal',
       margin=5)
    ca(click, ts.buttonEditCrystal)
    wait(500)
    #@type dlg DialogEditCrystal
    dlg = dialog_edit_crystal.last_dialog
    dlg.crystal.name = "Quartz Crystal"
    dlg.crystal.description = "Tutorial sample of quartz."
    wait(50)
    ca(screenshot_frame, dlg, 'dialog_edit_crystal', top_only=80)
    ca(dlg.notebook.SetSelection, 1)
    wait(50)
    ca(screenshot_of, dlg.notebook, 'dialog_edit_crystal-notebook1', margin=10)
    ca(screenshot_of,
       dlg.buttonGenerateUB,
       'dialog_edit_crystal-buttonGenerateUB',
       margin=6)
    ca(dlg.notebook.SetSelection, 0)
    wait(50)
    ca(screenshot_of,
       dlg.boxSizerIsaw,
       'dialog_edit_crystal-notebook0',
       margin=[16, 16, 46, 16],
       gradient_edge=6,
       minheight=True)
    ca(screenshot_of,
       dlg.buttonReadUB,
       'dialog_edit_crystal-buttonReadUB',
       margin=6)
    ca(screenshot_of, dlg.buttonOK, 'dialog_edit_crystal-buttonOK', margin=6)
    ca(screenshot_of,
       dlg.buttonCancel,
       'dialog_edit_crystal-buttonCancel',
       margin=6)
    angles = np.array([30, 15, 60])
    (phi, chi, omega) = angles
    dlg.ub_orientation.phi_degrees = phi
    dlg.ub_orientation.chi_degrees = chi
    dlg.ub_orientation.omega_degrees = omega
    wait(50)
    ca(screenshot_of,
       dlg.control_load_angles,
       'dialog_edit_crystal-control_load_angles',
       margin=6)
    ca(dlg.crystal.read_ISAW_ubmatrix_file, "../model/data/quartzub.txt",
       np.deg2rad(angles))
    wait(200)
    ca(screenshot_of,
       dlg.control_top,
       'dialog_edit_crystal-control_top',
       margin=6)
    ca(click, dlg.buttonOK)
    wait(500)

    ca(screenshot_of,
       ts.range_control,
       'sample-range_control',
       margin=10,
       gradient_edge=0)
    ca(screenshot_of,
       ts.buttonApplyRange,
       'sample-buttonApplyRange',
       margin=10,
       gradient_edge=0)

    # ------------------------- Trial Positions tab -----------------------
    ca(fm.notebook.SetSelection, 4)
    wait(40)
    #Make the main window narrower
    ca(fm.SetSize, wx.Size(500, original_size[1]))
    wait(150)
    #@type tt PanelTryPosition
    tt = fm.tab_try
    ca(screenshot_of,
       tt.boxSizerAll,
       'try',
       minheight=True,
       margin=[10, 10, 40, 10],
       gradient_edge=5)
    #Check the box
    ca(check, tt.checkAdd, True)
    wait(100)
    ca(screenshot_of, tt.checkAdd, 'try-checkAdd', margin=6, gradient_edge=2)
    wait(40)

    #@type slid ValueSlider
    slid = tt.sliders[0]
    ca(slid.SetValue, -30)
    wait(50)
    ca(slid.SendScrollEndEvent)
    wait(500)
    ca(screenshot_of, slid, 'try-phi-30', margin=6, gradient_edge=2)

    # ------------------------ 3D Viewer! ----------------------
    #The whole frame
    ca(fv.Raise)  #Bring it to front first!
    wait(300)

    ca(screenshot_frame, fv, 'frame_qspace')

    #Animate a phi rotation
    wait(100)
    #make_animated_phi_rotation(slid, fv, "3d-phi_rotation_anim.png")
    #make_animated_phi_rotation(tt.sliders[1], fv, "3d-chi_rotation_anim.png")

    # ------------------------ Try Positions, bad goniometer ----------------------
    ca(fm.Raise)

    #Set a chi of +45 deg
    slid = tt.sliders[1]
    ca(slid.SetValue, +45)
    ca(slid.SendScrollEvent)  #Trigger the showing the warning
    wait(150)
    ca(screenshot_of, slid, 'try-chi-45', margin=6, gradient_edge=2)
    ca(screenshot_of, [tt.staticTextWarning, tt.staticTextWarningReason],
       'try-staticTextWarning',
       margin=6)
    ca(screenshot_of, tt.buttonSave, 'try-buttonSave', margin=6)
    #un-check the box
    ca(check, tt.checkAdd, False)

    # ------------------------ Add Orientations tab ----------------------
    ca(fm.notebook.SetSelection, 5)

    #@type ta PanelAddPositions
    ta = fm.tab_add

    waitfor_set(ta.textWarnings.GetValue)
    ca(ta.controller.textAngles[0].SetValue, "0, 10, 35.5")
    ca(ta.controller.textAngles[1].SetValue, "arange(0, 50, 12.5)")
    ca(ta.controller.textAngles[2].SetValue, "linspace(0, 360, 6)")
    waitfor_change()
    ca(screenshot_of, [ta.boxSizerAngles], 'add-lists', margin=12)
    ca(ta.controller.textAngles[0].SetValue, "0")
    ca(ta.controller.textAngles[1].SetValue, "arange(-20, 20, 5)")
    ca(ta.controller.textAngles[2].SetValue, "0")
    waitfor_change()
    ca(screenshot_of, [ta.staticTextWarnings, ta.textWarnings],
       'add-textWarnings',
       margin=12)
    ca(screenshot_of, ta.boxSizerAngles, 'add-lists2', margin=12)
    ca(ta.controller.textAngles[0].SetValue, "0, 30, 60, 90")
    ca(ta.controller.textAngles[1].SetValue, "0")
    ca(ta.controller.textAngles[2].SetValue, "0")
    waitfor_change()
    ca(screenshot_of, ta.boxSizerAngles, 'add-lists3', margin=12)
    wait(50)
    ca(screenshot_of, [ta.buttonCalculate, ta.buttonCancel],
       'add-start_button',
       margin=20)
    ca(click, ta.buttonCalculate)
    #Delay util the progress bar has something
    waitfor('len(model.experiment.exp.inst.positions) > 1')
    ca(screenshot_of, [ta.gaugeProgress, ta.staticTextProgress],
       'add-progress_bar',
       margin=10)
    wait(30)
    ca(screenshot_of, [ta.buttonCalculate, ta.buttonCancel],
       'add-cancel_button',
       margin=20)
    #Wait till done
    waitfor('len(model.experiment.exp.inst.positions) >= 4')
    wait(50)
    #assert len(model.experiment.exp.inst.positions)==2, "Length of positions calculated was to be 19, it was %d." % len(model.experiment.exp.inst.positions)

    # ------------------------ Experiment Plan tab ----------------------
    ca(fm.notebook.SetSelection, 6)

    #Restore the window width
    ca(fm.SetSize, original_size)
    wait(150)

    #@type te PanelExperiment
    te = fm.tab_experiment

    ca(te.gridExp.SelectBlock, 1, 0, 1, 100)
    wait(50)
    ca(screenshot_of, te.gridExp, 'exp-grid', margin=12)
    ca(screenshot_of, te.boxSizerDelete, 'exp-delete_buttons', margin=8)
    ca(screenshot_of, [te.checkUseAll, te.buttonDontUseHighlighted],
       'exp-select_buttons',
       margin=8)
    ca(screenshot_of, te.buttonSaveToCSV, 'exp-buttonSaveToCSV', margin=6)
    ca(screenshot_of, te.buttonOptimizer, 'exp-buttonOptimizer', margin=6)
    ca(screenshot_of,
       te.staticTextEstimatedTime,
       'exp-estimated_time',
       margin=6)
    wait(50)

    # ------------------------ Back to 3D view----------------------
    #The q-space options panel
    #@type tv PanelQspaceOptions
    tv = fv.tabVolume

    ca(fv.Raise)
    wait(50)

    control_margins = [-180, -180, -30, -10]
    control_gradient_edge = 100
    check_margin = 4

    ca(screenshot_frame, fv, '3d-4orientations')
    ca(screenshot_of, fv.panelStats, '3d-panelStats', margin=10)
    ca(screenshot_of, tv.sliceControl, '3d-sliceControl', margin=10)

    ca(screenshot_of,
       tv.checkSymmetry,
       'volume_options-checkSymmetry',
       margin=check_margin)
    ca(check, tv.checkSymmetry, True)
    wait(600)
    ca(screenshot_of,
       fv.control,
       '3d-symmetry',
       margin=control_margins,
       gradient_edge=control_gradient_edge)
    ca(screenshot_of, fv.panelStats, '3d-panelStats-symmetry', margin=10)

    ca(screenshot_of,
       tv.checkInvert,
       'volume_options-checkInvert',
       margin=check_margin)
    ca(check, tv.checkInvert, True)
    wait(600)
    ca(screenshot_of,
       fv.control,
       '3d-inverted',
       margin=control_margins,
       gradient_edge=control_gradient_edge)
    ca(check, tv.checkInvert, False)
    ca(check, tv.checkSymmetry, False)
    ca(check, tv.checkShowRedundancy, True)
    wait(1200)

    ca(screenshot_of,
       tv.checkShowRedundancy,
       'volume_options-checkShowRedundancy',
       margin=check_margin)
    ca(screenshot_of,
       fv.control,
       '3d-redundancy',
       margin=control_margins,
       gradient_edge=control_gradient_edge)

    ca(screenshot_of,
       tv.checkShowSlice,
       'volume_options-checkShowSlice',
       margin=check_margin)
    tv.sliceControl.slice_min = 3
    tv.sliceControl.slice_max = 3.5
    wait(30)
    ca(check, tv.checkShowRedundancy, False)
    ca(check, tv.checkShowSlice, True)
    wait(600)
    ca(screenshot_of, tv.sliceControl, '3d-sliceControl-on', margin=10)
    ca(screenshot_of,
       fv.control,
       '3d-slice',
       margin=control_margins,
       gradient_edge=control_gradient_edge)
    ca(check, tv.checkShowRedundancy, True)
    wait(900)
    ca(screenshot_of,
       fv.control,
       '3d-slice-redundancy',
       margin=control_margins,
       gradient_edge=control_gradient_edge)

    # ------------------------ Reflections View ---------------------
    #@type tr PanelReflectionsViewOptions
    tr = fv.tabReflections

    #Select it
    ca(fv.notebookView.SetSelection, 1)
    wait(800)
    ca(screenshot_frame, fv, '3d-reflections')
    ca(screenshot_of, fv.panelStats, '3drefs-panelStats-normal', margin=10)

    #Only the measured peaks
    ca(tr.choiceView.SetSelection, 1)
    ca(call_event, tr.choiceView, wx.EVT_CHOICE)
    wait(400)
    ca(screenshot_of,
       fv.control,
       '3drefs-measured',
       margin=control_margins,
       gradient_edge=control_gradient_edge)
    ca(screenshot_of,
       tr.boxSizerDisplay,
       '3drefs-display',
       margin=10,
       gradient_edge=4)
    ca(screenshot_of, [tr.staticTextViewOption, tr.choiceView],
       '3drefs-view_option',
       margin=check_margin,
       gradient_edge=2)
    ca(screenshot_of,
       tr.checkUseSymmetry,
       '3drefs-checkUseSymmetry',
       margin=check_margin)

    #Use symmetry
    ca(check, tr.checkUseSymmetry, True)
    ca(tr.choiceView.SetSelection, 0)
    ca(call_event, tr.choiceView, wx.EVT_CHOICE)
    wait(400)
    ca(screenshot_of,
       fv.control,
       '3drefs-measured-symmetry',
       margin=control_margins,
       gradient_edge=control_gradient_edge)
    ca(screenshot_of, fv.panelStats, '3drefs-panelStats-symmetry', margin=10)

    ca(fv.controller.scene.__setattr__, 'parallel_projection', True)
    wait(400)
    ca(screenshot_of,
       fv.control,
       '3drefs-parallel',
       margin=control_margins,
       gradient_edge=control_gradient_edge)
    ca(fv.controller.scene.__setattr__, 'parallel_projection', False)
    wait(400)

    #--- Find a reflection to display ---
    #Simulate a left-click
    ca(fv.controller.on_button_press, FakeClickObject(50, 50), None)
    #    refl = pick_a_reflection()
    #    #Select it
    #    ca(fv.controller.select_reflection, refl)

    wait(250)
    ca(screenshot_of,
       fv.control,
       '3drefs-reflection_selected',
       margin=control_margins,
       gradient_edge=control_gradient_edge)
    #@type fri FrameReflectionInfo
    fri = fv.controller.open_frame_reflection_info()
    ca(screenshot_frame, fri, 'ref_info')
    #@type pri PanelReflectionInfo
    pri = fri.panel

    #Put in bad values for hkl
    ca(pri.textCtrlH.SetValue, "20")
    wait(40)
    ca(screenshot_of, [pri.staticTextHKLLabel, pri.gridSizerHKL],
       'ref_info-bad_hkl',
       margin=10,
       gradient_edge=5)
    ca(pri.textCtrlH.SetValue, "3")
    ca(pri.textCtrlK.SetValue, "2")
    ca(pri.textCtrlL.SetValue, "-4")
    wait(300)
    size = fri.GetSize()
    ca(fri.SetSize, wx.Size(size[0], 600))
    ca(screenshot_of, pri, 'ref_info2', margin=5, gradient_edge=0)
    #Check it
    ca(check, pri.checkUseEquivalent, True)
    ca(screenshot_of,
       pri.checkUseEquivalent,
       'ref_info-checkUseEquivalent',
       margin=4,
       gradient_edge=2)
    ca(screenshot_of,
       pri.boxSizerDivergence,
       'ref_info-textCtrlDivergence',
       margin=4,
       gradient_edge=2)
    wait(150)
    ca(screenshot_of, pri, 'ref_info2-equivalent', margin=5, gradient_edge=0)

    #--------------- Measured Reflections -------------
    #@type tr PanelReflectionsViewOptions
    tr = fv.tabReflections
    #Load some peaks file
    ca(model.experiment.exp.load_peaks_file,
       "../model/data/TOPAZ_1241.integrate",
       append=False)
    wait(1000)
    ca(display_thread.handle_change_of_qspace)
    wait(1000)
    ca(screenshot_of,
       tr.boxSizerColor,
       'refl-measurements',
       margin=6,
       gradient_edge=2)

    #---END---

    #--------------- The Reflection Placer -------------

    #@type prm PanelReflectionMeasurement
    prm = pri.measure_panels[0][0]
    ca(screenshot_of, prm, 'prm', margin=5, gradient_edge=0)
    ca(screenshot_of,
       prm.buttonPlace,
       'prm-buttonPlace',
       margin=5,
       gradient_edge=0)
    ca(click, prm.buttonPlace)
    wait(800)

    #@type frp FrameReflectionPlacer
    global frp
    frp = prm.last_placer_frame
    #Wait for calculation to be done
    wait(3800)
    frp.placer.xy[0] = -5
    wait(100)
    ca(screenshot_frame, frp, 'ref_placer')
    ca(screenshot_of,
       frp.buttonAddOrientation,
       'ref_placer-buttonAddOrientation',
       margin=4,
       gradient_edge=2)

    #---END---

    #--- Automatic coverage optimizer ---
    #@type te PanelExperiment
    te = fm.tab_experiment
    ca(click, te.buttonOptimizer)
    wait(500)
    #@type fo FrameOptimizer
    fo = frame_optimizer.get_instance(fm)
    wait(500)
    fo.Raise()
    ca(screenshot_of,
       fo.buttonStart,
       'optim-buttonStart',
       margin=6,
       gradient_edge=2)
    ca(click, fo.buttonStart)
    wait(500)
    ca(screenshot_of,
       fo.buttonStop,
       'optim-buttonStop',
       margin=6,
       gradient_edge=2)
    ca(screenshot_of,
       fo.buttonApply,
       'optim-buttonApply',
       margin=6,
       gradient_edge=2)
    wait(2500)
    ca(screenshot_frame, fo, 'frame_optimizer')
    #Stop
    ca(click, fo.buttonStop)
    wait(500)
    ca(screenshot_of,
       fo.buttonKeepGoing,
       'optim-buttonKeepGoing',
       margin=6,
       gradient_edge=2)
 def OnButtonOptimizer(self, event):
     frm = frame_optimizer.get_instance(parent=self)
     frm.Show()
     frm.Raise()
     event.Skip()