control_panel.ipf en Igor Pro
Un panel funcional: globales, controles, acciones y un hook que limpia al final.
#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
Cómo funciona
- Las globales se crean antes que cualquier control que se ligue a una.
- Cada control nombra su acción; cada acción revisa el código de evento.
- El hook de ventana mata la carpeta de ajustes cuando el panel se cierra.
Palabras clave y builtins usados aquí
EndFunctionNVARSTRUCTSVARStaticStrConstantStringVariableWAVEendififprocreturnwindow
El intento, en números
- Líneas
- 84
- Caracteres a escribir
- 1973
- Tokens
- 448
- Ritmo de tres estrellas
- 95 tpm
Al ritmo de tres estrellas de 95 tokens por minuto, este intento toma unos 283 segundos.
Paso 1 de 1 en Bis; paso 18 de 18 en Paneles y GUI.