Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GUI tester and update Readme #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Example_JSON_Gui.ahk
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

- - -

Expand Down