From 92c978f270e618e8203e75e00ef3ef71fc3abf2c Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Thu, 26 Oct 2017 17:57:38 -0400 Subject: [PATCH] Add GUI tester and update Readme --- Example_JSON_Gui.ahk | 95 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 3 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 Example_JSON_Gui.ahk diff --git a/Example_JSON_Gui.ahk b/Example_JSON_Gui.ahk new file mode 100644 index 0000000..2cdefe7 --- /dev/null +++ b/Example_JSON_Gui.ahk @@ -0,0 +1,95 @@ +#Include %A_LineFile%\..\JSON.ahk +#SingleInstance,Force + SetTitleMatchMode,Regex + SetKeyDelay,-1 +json_str = +( +{ + "str": "Hello World", + "num": 12345, + "float": 123.5, + "true": true, + "false": false, + "null": null, + "array": [ + "Auto", + "Hot", + "key" + ], + "object": { + "A": "Auto", + "H": "Hot", + "K": "key" + } +} +) + ;-------------------------------------------------- + ; * gui defined + ;-------------------------------------------------- + Gui, Destroy + Gui, +AlwaysOnTop + Gui,Font,s9,Open Sans + ;-------------------------------------------------- + ; ** define basic layout + ;-------------------------------------------------- + marginTop = 10 + marginLeft = 10 + xCol1 = 90 + xCol2 = 460 + ew = 400 + bH = 26 ; button height + Gui, Add, Text, section x10 w80 ,Input JSON: + Gui, Add, Edit, xs ys+20 h500 w400 Wrap Multi vInput hwndInput,%json_str% + Gui, Add, Button, ym ys+20 w75 gcmd_Parsed, &Parsed + Gui, Add, Button, w75 gcmd_Stringified, &Stringified + Gui, Add, Text, ym w80 x+10 section ,Output: + Gui, Add, Edit, xs ys+20 w400 h500 Wrap Multi vOutput hwndOutput +;/* ===BUTTON=== */ + Gui, Add, Button, w60 section default h%bH% gOK, &OK + Gui, Add, Button, w60 ys h%bH% gClose, &Cancel + Gui, Show,, PowerShell CSV Output Script + GuiControl, Focus, filename + return ; End of auto-execute section. The script is idle until the user does something. + ControlSetText,, %filename_code%, ahk_id %filename% + Return +;/* ===SUBMIT OK BUTTON=== */ +GuiSubmit: +OK: + ControlGetText,sInput ,,ahk_id %Input% + ControlSetText,, %sInput%, ahk_id %Output% +Return + GuiEscape: + Gui, Destroy + Return +Close: + Gui, Destroy +Return +cmd_Parsed: + ControlGetText,sInput ,,ahk_id %Input% + parsed := JSON.Load(sInput) + parsed_out := Format(" + (Join`r`n + String: {} + Number: {} + Float: {} + true: {} + false: {} + null: {} + array: [{}, {}, {}] + object: {{}A:""{}"", H:""{}"", K:""{}""{}} + )" + , parsed.str, parsed.num, parsed.float, parsed.true, parsed.false, parsed.null + , parsed.array[1], parsed.array[2], parsed.array[3] + , parsed.object.A, parsed.object.H, parsed.object.K) + + + ControlSetText,, %parsed_out%, ahk_id %Output% +Return +cmd_Stringified: + ControlGetText,sInput ,,ahk_id %Input% + parsed := JSON.Load(sInput) + stringified := JSON.Dump(parsed,, 4) + stringified := StrReplace(stringified, "`n", "`r`n") ; for display purposes only + + ControlSetText,, %stringified%, ahk_id %Output% +Return diff --git a/README.md b/README.md index fd3d535..eee99f5 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ Requirements: Latest version of AutoHotkey _(v1.1+ or v2.0-a+)_ Version: v2.1.1 _(updated 01/30/2016)_ - +Example: Updated 2017-10-26 License: [WTFPL](http://wtfpl.net/) +The example gui, `Example_JSON_Gui.ahk`, has a **Parsed** and a **Stringified** button. Parsed is custom code uses the input string given as an example. Stringified, however, will take any JSON pasted into the **Input** box and stringify (prettify) it. - - -