typestar

control_panel.ipf in Igor Pro

A working panel: globals, controls, actions, and a hook that clears up after itself.

#pragma TextEncoding = "UTF-8"
#pragma rtGlobals = 3

Static StrConstant ksFolder = "root:SmoothPanel"

Function InitPanel()
    NewDataFolder/O $ksFolder
    Variable/G $(ksFolder + ":gWindow") = 5
    String/G $(ksFolder + ":gTarget") = ""

    DoWindow/K SmoothPanel
    NewPanel/N=SmoothPanel/K=1/W=(120, 120, 460, 300)
    ModifyPanel cbRGB=(61000, 61000, 61000)

    SetDrawLayer UserBack
    SetDrawEnv fsize=13, fstyle=1
    DrawText 16, 26, "Smooth a wave"

    NVAR window = $(ksFolder + ":gWindow")

    PopupMenu targetPop, pos={16, 44}, size={300, 20}, title="Wave"
    PopupMenu targetPop, value=#"WaveList(\"*\", \";\", \"TEXT:0\")"
    PopupMenu targetPop, mode=1, proc=TargetPicked

    SetVariable widthSet, pos={16, 76}, size={200, 18}, bodyWidth=60
    SetVariable widthSet, title="Window", value=window, limits={1, 99, 2}

    Button applyBtn, pos={16, 108}, size={90, 24}, title="Apply"
    Button applyBtn, proc=ApplyClicked

    Button closeBtn, pos={116, 108}, size={90, 24}, title="Close"
    Button closeBtn, proc=CloseClicked

    SetWindow SmoothPanel, hook(tidy)=PanelHook
    return 0
End

Function TargetPicked(STRUCT WMPopupAction &pa) : PopupMenuControl
    if (pa.eventCode != 2)
        return 0
    endif

    SVAR target = $(ksFolder + ":gTarget")
    target = pa.popStr
    return 0
End

Function ApplyClicked(STRUCT WMButtonAction &ba) : ButtonControl
    if (ba.eventCode != 2)
        return 0
    endif

    SVAR target = $(ksFolder + ":gTarget")
    NVAR window = $(ksFolder + ":gWindow")

    WAVE/Z src = $target
    if (!WaveExists(src))
        DoAlert 0, "Pick a wave first."
        return 0
    endif

    Duplicate/O src, $(target + "_smooth")
    WAVE dest = $(target + "_smooth")
    Smooth/B window, dest

    DoWindow/K SmoothResult
    Display/N=SmoothResult src, dest
    ModifyGraph rgb($NameOfWave(dest))=(65535, 16000, 16000)
    return 0
End

Function CloseClicked(STRUCT WMButtonAction &ba) : ButtonControl
    if (ba.eventCode == 2)
        DoWindow/K SmoothPanel
    endif
    return 0
End

Function PanelHook(STRUCT WMWinHookStruct &s)
    if (CmpStr(s.eventName, "kill") == 0)
        KillDataFolder/Z $ksFolder
    endif
    return 0
End

How it works

  1. The globals are made before any control that binds to one.
  2. Each control names its action; each action checks the event code.
  3. The window hook kills the settings folder when the panel closes.

Keywords and builtins used here

The run, in numbers

Lines
84
Characters to type
1973
Tokens
448
Three-star pace
95 tpm

At the three-star pace of 95 tokens a minute, this run takes about 283 seconds.

Type this snippet

Step 1 of 1 in Encore, step 18 of 18 in Panels & GUI.

← Previous