Re: v1 -> v2 Script Converter
Posted: 16 Apr 2023, 12:15
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=83&t=25100
Code: Select all
_Menu(p) {
global Orig_Line_NoComment
global MenuList
global Indentation
MenuLine := Orig_Line_NoComment
LineResult := ""
menuNameLine := RegExReplace(MenuLine, "i)^\s*Menu\s*[,\s]\s*([^,]*).*$", "$1", &RegExCount1)
; e.g.: Menu, Tray, Add, % func_arg3(nested_arg3a, nested_arg3b), % func_arg4(nested_arg4a, nested_arg4b), % func_arg5(nested_arg5a, nested_arg5b)
Var2 := RegExReplace(MenuLine, "
(
ix) # case insensitive, extended mode to ignore space and comments
^\s*Menu\s*[,\s]\s* #
([^,]*) \s* , \s* # arg1 Tray {group $1}
([^,]*) # arg2 Add {group $2}
.* #
)"
, "$2", &RegExCount2) ; =Add
Var3 := RegExReplace(MenuLine, "
(
ix) #
^\s*Menu \s*[,\s]\s* #
([^,] *) , \s* # arg1 Tray {group $1}
([^,] *) \s* , \s* # arg2 Add {group $2}
([^,(]* \(? # % func_arg3(nested_arg3a, nested_arg3b) {group $3 start
(?(?<=\()[^)]*\)) # nested function conditional, if matched ( then match everything up to and including the )
[^,]*) # group $3 end}
.*$ #
)"
, "$3", &RegExCount3) ; =% func_arg3(nested_arg3a, nested_arg3b)
; and so on..... with more clauses
Code: Select all
add_menuhandler(FNOut) ;outscript_path
{
menuhandle := 0 ; => these denote true[1]/false[0]
GuiEsc:= 0 ; => for various bad output code, such as
FindMenu := 0 ; => once MenuBar := Menubar() is found FindMenu:= 1;
FindMenuBar := 0 ; =>
; this will all get removed with methods
; && for loops
newoutscript := ""
intxt := FileRead(FNOut)
Loop Parse, intxt, "`n", "`r" {
if menuhandle == 0 && InStr(A_LoopField, "MenuHandler"){
menuhandle := 1
newoutscript .= A_LoopField . "`n"
}
else if (menuhandle == 1) && (GuiEsc== 0) && InStr(A_LoopField, "GuiEscape(*)") {
newoutscript .= "MenuHandler(*) {`n`tToolTip `"Click!`", 100, 150`n}`n" A_LoopField
GuiEsc:= 1
}
else if InStr(A_LoopField, "myGui.OnEvent(`"Close`", GuiEscape)") || InStr(A_LoopField, "myGui.OnEvent(`"Escape`", GuiEscape)") || InStr(A_LoopField, "Bind(`"Normal`")") || (A_LoopField == "") {
continue
}
; else if InStr(LTrim(A_LoopField), "MenuBar.Add(") && a == 1 {
; if StrSplit(LTrim(A_LoopField), "(")[1] == "MenuBar.Add" {
; newoutscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenBar.Add(")
; newoutscript .= "`n"
; }
; ; }
else if (LTrim(A_LoopField) == "Menu := Menu()") {
newoutscript .= StrReplace(A_LoopField, "Menu := Menu()", "Men := Menu()")
newoutscript .= "`n"
FindMenu := 1
}
else if (FindMenu == 1 && InStr(LTrim(A_LoopField), "Menu.Add(")) {
if (StrSplit(LTrim(A_LoopField), "(")[1] == "Menu.Add") {
newoutscript .= StrReplace(A_LoopField, "Menu.Add(", "Men.Add(")
newoutscript .= "`n"
}
}
else if (LTrim(A_LoopField) == "MenuBar := Menu()") {
newoutscript .= StrReplace(A_LoopField, "MenuBar := Menu()", "MenBars := MenuBar()")
newoutscript .= "`n"
FindMenuBar := 1
}
else if (FindMenuBar == 1) && InStr(LTrim(A_LoopField), "MenuBar.Add(") {
if (StrSplit(LTrim(A_LoopField), "(")[1] == "MenuBar.Add") {
newoutscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenBars.Add(")
newoutscript .= "`n"
}
}
else if (A_Index == 2) {
newoutscript := "`;AutoGUI 2.5.8 `n`;Auto-GUI-v2 credit to autohotkey.com/boards/viewtopic.php?f=64&t=89901`n`;AHKv2converter credit to github.com/mmikeww/AHK-v2-script-converter`n"
}
else if InStr(A_LoopField, ".MenuToolbar := MenuBar") {
newoutscript .= StrReplace(A_LoopField, "MenuToolbar := MenuBar", "MenuBar := MenBars")
newoutscript .= "`n"
}
else {
newoutscript .= A_LoopField . "`n"
}
}
FileDelete(FNOut)
FileAppend(newoutscript, FNOut)
}
@sashaatxsashaatx wrote: ↑19 Apr 2023, 16:34@guest3456
hello there,
I would love really quick pointers, huge fan and user of the converter. I am looking to add to some functions I've run in to while developing these projects:
https://github.com/samfisherirl/Auto-GUI-for-AHK-v2
I'm processing hundreds of massive GUI clone requests in AutoGUI and seeing the bounds of the converter. Its very powerful and want to propose some solutions.
I know very basic amounts of regex. If you wouldnt mind providing details on (one or more question):
- In the example of adding to improvements to the `Menu := Menu()` conversion
- It appears to happen from line ~2130-2170
- I dont understand beyond a replacement is happening, maybe this is a perfect function and I need to focus on other areas
- What are the recommended ways to translate this regex to something a newbie would understand
- Is there a key elsewhere or are embedded instructions past what Im seeing
thank you
I ended up taking a hatchet to the output gui naming scheme as a ham-fisted solution for the mean time.Code: Select all
_Menu(p) { global Orig_Line_NoComment global MenuList global Indentation MenuLine := Orig_Line_NoComment LineResult := "" menuNameLine := RegExReplace(MenuLine, "i)^\s*Menu\s*[,\s]\s*([^,]*).*$", "$1", &RegExCount1) ; e.g.: Menu, Tray, Add, % func_arg3(nested_arg3a, nested_arg3b), % func_arg4(nested_arg4a, nested_arg4b), % func_arg5(nested_arg5a, nested_arg5b) Var2 := RegExReplace(MenuLine, " ( ix) # case insensitive, extended mode to ignore space and comments ^\s*Menu\s*[,\s]\s* # ([^,]*) \s* , \s* # arg1 Tray {group $1} ([^,]*) # arg2 Add {group $2} .* # )" , "$2", &RegExCount2) ; =Add Var3 := RegExReplace(MenuLine, " ( ix) # ^\s*Menu \s*[,\s]\s* # ([^,] *) , \s* # arg1 Tray {group $1} ([^,] *) \s* , \s* # arg2 Add {group $2} ([^,(]* \(? # % func_arg3(nested_arg3a, nested_arg3b) {group $3 start (?(?<=\()[^)]*\)) # nested function conditional, if matched ( then match everything up to and including the ) [^,]*) # group $3 end} .*$ # )" , "$3", &RegExCount3) ; =% func_arg3(nested_arg3a, nested_arg3b) ; and so on..... with more clauses
Code: Select all
add_menuhandler(FNOut) ;outscript_path { menuhandle := 0 ; => these denote true[1]/false[0] GuiEsc:= 0 ; => for various bad output code, such as FindMenu := 0 ; => once MenuBar := Menubar() is found FindMenu:= 1; FindMenuBar := 0 ; => ; this will all get removed with methods ; && for loops newoutscript := "" intxt := FileRead(FNOut) Loop Parse, intxt, "`n", "`r" { if menuhandle == 0 && InStr(A_LoopField, "MenuHandler"){ menuhandle := 1 newoutscript .= A_LoopField . "`n" } else if (menuhandle == 1) && (GuiEsc== 0) && InStr(A_LoopField, "GuiEscape(*)") { newoutscript .= "MenuHandler(*) {`n`tToolTip `"Click!`", 100, 150`n}`n" A_LoopField GuiEsc:= 1 } else if InStr(A_LoopField, "myGui.OnEvent(`"Close`", GuiEscape)") || InStr(A_LoopField, "myGui.OnEvent(`"Escape`", GuiEscape)") || InStr(A_LoopField, "Bind(`"Normal`")") || (A_LoopField == "") { continue } ; else if InStr(LTrim(A_LoopField), "MenuBar.Add(") && a == 1 { ; if StrSplit(LTrim(A_LoopField), "(")[1] == "MenuBar.Add" { ; newoutscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenBar.Add(") ; newoutscript .= "`n" ; } ; ; } else if (LTrim(A_LoopField) == "Menu := Menu()") { newoutscript .= StrReplace(A_LoopField, "Menu := Menu()", "Men := Menu()") newoutscript .= "`n" FindMenu := 1 } else if (FindMenu == 1 && InStr(LTrim(A_LoopField), "Menu.Add(")) { if (StrSplit(LTrim(A_LoopField), "(")[1] == "Menu.Add") { newoutscript .= StrReplace(A_LoopField, "Menu.Add(", "Men.Add(") newoutscript .= "`n" } } else if (LTrim(A_LoopField) == "MenuBar := Menu()") { newoutscript .= StrReplace(A_LoopField, "MenuBar := Menu()", "MenBars := MenuBar()") newoutscript .= "`n" FindMenuBar := 1 } else if (FindMenuBar == 1) && InStr(LTrim(A_LoopField), "MenuBar.Add(") { if (StrSplit(LTrim(A_LoopField), "(")[1] == "MenuBar.Add") { newoutscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenBars.Add(") newoutscript .= "`n" } } else if (A_Index == 2) { newoutscript := "`;AutoGUI 2.5.8 `n`;Auto-GUI-v2 credit to autohotkey.com/boards/viewtopic.php?f=64&t=89901`n`;AHKv2converter credit to github.com/mmikeww/AHK-v2-script-converter`n" } else if InStr(A_LoopField, ".MenuToolbar := MenuBar") { newoutscript .= StrReplace(A_LoopField, "MenuToolbar := MenuBar", "MenuBar := MenBars") newoutscript .= "`n" } else { newoutscript .= A_LoopField . "`n" } } FileDelete(FNOut) FileAppend(newoutscript, FNOut) }
Hey user,AHK_user wrote: ↑20 Apr 2023, 08:03@sashaatxsashaatx wrote: ↑19 Apr 2023, 16:34@guest3456
hello there,
I would love really quick pointers, huge fan and user of the converter. I am looking to add to some functions I've run in to while developing these projects:
https://github.com/samfisherirl/Auto-GUI-for-AHK-v2
I'm processing hundreds of massive GUI clone requests in AutoGUI and seeing the bounds of the converter. Its very powerful and want to propose some solutions.
I know very basic amounts of regex. If you wouldnt mind providing details on (one or more question):
- In the example of adding to improvements to the `Menu := Menu()` conversion
- It appears to happen from line ~2130-2170
- I dont understand beyond a replacement is happening, maybe this is a perfect function and I need to focus on other areas
- What are the recommended ways to translate this regex to something a newbie would understand
- Is there a key elsewhere or are embedded instructions past what Im seeing
thank you
I ended up taking a hatchet to the output gui naming scheme as a ham-fisted solution for the mean time.Code: Select all
_Menu(p) { global Orig_Line_NoComment global MenuList global Indentation MenuLine := Orig_Line_NoComment LineResult := "" menuNameLine := RegExReplace(MenuLine, "i)^\s*Menu\s*[,\s]\s*([^,]*).*$", "$1", &RegExCount1) ; e.g.: Menu, Tray, Add, % func_arg3(nested_arg3a, nested_arg3b), % func_arg4(nested_arg4a, nested_arg4b), % func_arg5(nested_arg5a, nested_arg5b) Var2 := RegExReplace(MenuLine, " ( ix) # case insensitive, extended mode to ignore space and comments ^\s*Menu\s*[,\s]\s* # ([^,]*) \s* , \s* # arg1 Tray {group $1} ([^,]*) # arg2 Add {group $2} .* # )" , "$2", &RegExCount2) ; =Add Var3 := RegExReplace(MenuLine, " ( ix) # ^\s*Menu \s*[,\s]\s* # ([^,] *) , \s* # arg1 Tray {group $1} ([^,] *) \s* , \s* # arg2 Add {group $2} ([^,(]* \(? # % func_arg3(nested_arg3a, nested_arg3b) {group $3 start (?(?<=\()[^)]*\)) # nested function conditional, if matched ( then match everything up to and including the ) [^,]*) # group $3 end} .*$ # )" , "$3", &RegExCount3) ; =% func_arg3(nested_arg3a, nested_arg3b) ; and so on..... with more clauses
Code: Select all
add_menuhandler(FNOut) ;outscript_path { menuhandle := 0 ; => these denote true[1]/false[0] GuiEsc:= 0 ; => for various bad output code, such as FindMenu := 0 ; => once MenuBar := Menubar() is found FindMenu:= 1; FindMenuBar := 0 ; => ; this will all get removed with methods ; && for loops newoutscript := "" intxt := FileRead(FNOut) Loop Parse, intxt, "`n", "`r" { if menuhandle == 0 && InStr(A_LoopField, "MenuHandler"){ menuhandle := 1 newoutscript .= A_LoopField . "`n" } else if (menuhandle == 1) && (GuiEsc== 0) && InStr(A_LoopField, "GuiEscape(*)") { newoutscript .= "MenuHandler(*) {`n`tToolTip `"Click!`", 100, 150`n}`n" A_LoopField GuiEsc:= 1 } else if InStr(A_LoopField, "myGui.OnEvent(`"Close`", GuiEscape)") || InStr(A_LoopField, "myGui.OnEvent(`"Escape`", GuiEscape)") || InStr(A_LoopField, "Bind(`"Normal`")") || (A_LoopField == "") { continue } ; else if InStr(LTrim(A_LoopField), "MenuBar.Add(") && a == 1 { ; if StrSplit(LTrim(A_LoopField), "(")[1] == "MenuBar.Add" { ; newoutscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenBar.Add(") ; newoutscript .= "`n" ; } ; ; } else if (LTrim(A_LoopField) == "Menu := Menu()") { newoutscript .= StrReplace(A_LoopField, "Menu := Menu()", "Men := Menu()") newoutscript .= "`n" FindMenu := 1 } else if (FindMenu == 1 && InStr(LTrim(A_LoopField), "Menu.Add(")) { if (StrSplit(LTrim(A_LoopField), "(")[1] == "Menu.Add") { newoutscript .= StrReplace(A_LoopField, "Menu.Add(", "Men.Add(") newoutscript .= "`n" } } else if (LTrim(A_LoopField) == "MenuBar := Menu()") { newoutscript .= StrReplace(A_LoopField, "MenuBar := Menu()", "MenBars := MenuBar()") newoutscript .= "`n" FindMenuBar := 1 } else if (FindMenuBar == 1) && InStr(LTrim(A_LoopField), "MenuBar.Add(") { if (StrSplit(LTrim(A_LoopField), "(")[1] == "MenuBar.Add") { newoutscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenBars.Add(") newoutscript .= "`n" } } else if (A_Index == 2) { newoutscript := "`;AutoGUI 2.5.8 `n`;Auto-GUI-v2 credit to autohotkey.com/boards/viewtopic.php?f=64&t=89901`n`;AHKv2converter credit to github.com/mmikeww/AHK-v2-script-converter`n" } else if InStr(A_LoopField, ".MenuToolbar := MenuBar") { newoutscript .= StrReplace(A_LoopField, "MenuToolbar := MenuBar", "MenuBar := MenBars") newoutscript .= "`n" } else { newoutscript .= A_LoopField . "`n" } } FileDelete(FNOut) FileAppend(newoutscript, FNOut) }
I do not think this is the correct approach. Guis from v1 and v2 are completely different, so I would not advice to add this to a v1 Gui creator.
You must accept that converting Gui`s from v1 to v2 will never be optimal, because they are quite different.
I actually started with a auto-Gui for V2, written in V2, but have not done a lot of work at it recently.
Of course it is not as good and tested as the v1 original, because I started almost from scratch, but a lot of functions already work quite well.
Extracting Gui data from existing windows already works very well, also the placing and positioning controls.
Feel free to improve it, and in the same time learn more about v2.
https://github.com/dmtr99/V2GuiCreator
Thanks @joedf, I'm definitely on there already!joedf wrote: ↑19 Apr 2023, 08:39@submeg I think this is in the AHK discord.
https://www.autohotkey.com/discord
Hi Guest,
Code: Select all
add_menuHandler(FNOut := "path", script := "code") ;outscript_path
{
menuHandle := 0 ; => these denote true[1]/false[0]
GuiEsc := 0 ; => for various bad output code, such as
FindMenu := 0 ; => once MenuBar := Menubar() is found FindMenu:= 1;
FindMenuBar := 0 ; =>
MenuHandleCount := 0
brackets := 0
RemoveFunction := 0 ; RemoveFunction==1 loops to find `}` while `{` not found in line
new_outscript := ""
buttonFound := 0
editFound := 0
editCount := 0
Edit_Storage := []
if FileExist(FNOut) {
FileMove(FNOut, A_ScriptDir "\complete_application\convert\temp.txt", 1)
}
Loop Parse, script, "`n", "`r" {
if (A_Index == 1) {
new_outscript := "`n" ";AutoGUI 2.5.8 " "`n" ";Auto-GUI-v2 credit to Alguimist autohotkey.com/boards/viewtopic.php?f=64&t=89901`n;AHKv2converter credit to github.com/mmikeww/AHK-v2-script-converter`n`n"
}
if (RemoveFunction == 1) {
if InStr(Trim(A_LoopField), "{") && not InStr(Trim(A_LoopField), "{") {
brackets += 1 ; for every opening bracket, remove until equal number of closed brackets found
continue
}
else if InStr(A_LoopField, "}") && not InStr(Trim(A_LoopField), "{") {
if (brackets <= 1) {
RemoveFunction := 0
brackets := 0
continue
}
else if (brackets > 1) {
brackets := brackets - 1
continue
}
}
else {
continue
}
}
if (menuHandle == 0) && (MenuHandleCount < 1) && InStr(A_LoopField, "MenuHandler") {
menuHandle := 1
new_outscript .= A_LoopField . "`n"
}
if InStr(A_LoopField, "MenuHandler(") {
MenuHandleCount += 1
RemoveFunction := 1
}
else if InStr(A_LoopField, ".Add(`"Edit`"") {
editFound := 1
editCount += 1
Edit_Storage.Push("Edit_Storage" . editCount)
new_outscript .= "Edit_Storage" editCount " := " A_LoopField "`n"
;ogcButtonOK.OnEvent("Click", GuiClose)
}
else if InStr(A_LoopField, ".Add(`"Button`"") {
buttonFound := 1
new_outscript .= A_LoopField "`n"
variableName := Trim(StrSplit(A_LoopField, ":=")[1])
;ogcButtonOK.OnEvent("Click", GuiClose)
val := variableName ".OnEvent(`"Click`", ButtonHandler)`n"
new_outscript .= val
}
else if InStr(A_LoopField, "GuiEscape(*)") {
;if END OF SCRIPT found, attempt to append functions
if (menuHandle == 1) && (MenuHandleCount < 2) {
new_outscript .= "`nMenuHandler(*)`n" tooltip_()
GuiEsc := 1
}
if (buttonFound == 1) && (editFound == 0) {
new_outscript .= "`nButtonHandler(*)`n" tooltip_()
}
else if (editFound == 1) {
if (buttonFound == 0) && (editFound == 1) {
func := "`nEditHandler(*)`n"
string := ""
; for i in Edit_Storage {
; string .= Format(" `"``n // {1}.Value ==> `" {1}.Value", i)
; ;string .= " `"``n //%i% " A_Index "// `" " i ".Value"
; }
}
else if (buttonFound == 1) && (editFound == 1) {
func .= "`nButtonHandler(*)`n"
}
string := ""
for i in Edit_Storage {
string .= Format(" `"``n // {1}.Value ==> `" {1}.Value", i)
}
new_outscript .= func . tooltip_(string)
}
new_outscript .= A_LoopField "`n"
;if () GuiEsc := 1
}
else if (menuHandle == 1) && (MenuHandleCount >= 1) && InStr(A_LoopField, "MenuHandler(") {
RemoveFunction := 1
continue
}
else if InStr(A_LoopField, "myGui.OnEvent(`"Close`", GuiEscape)") || InStr(A_LoopField, "myGui.OnEvent(`"Escape`", GuiEscape)") || InStr(A_LoopField, "Bind(`"Normal`")") || (A_LoopField == "") {
continue
}
; else if InStr(LTrim(A_LoopField), "MenuBar.Add(") && a == 1 {
; if StrSplit(LTrim(A_LoopField), "(")[1] == "MenuBar.Add" {
; new_outscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenBar.Add(")
; new_outscript .= "`n"
; }
; ; }
else if (Trim(A_LoopField) == "Menu := Menu()") {
new_outscript .= StrReplace(A_LoopField, "Menu := Menu()", "Menu_Storage := Menu()")
new_outscript .= "`n"
FindMenu := 1
}
else if (FindMenu == 1) && (InStr(Trim(A_LoopField), "Menu.Add(")) {
if (StrSplit(Trim(A_LoopField), "(")[1] == "Menu.Add") {
new_outscript .= StrReplace(A_LoopField, "Menu.Add(", "Menu_Storage.Add(")
new_outscript .= "`n"
}
}
else if (Trim(A_LoopField) == "MenuBar := Menu()") {
new_outscript .= StrReplace(A_LoopField, "MenuBar := Menu()", "MenuBar_Storage := MenuBar()")
new_outscript .= "`n"
FindMenuBar := 1
}
else if (FindMenuBar == 1) && InStr(Trim(A_LoopField), "MenuBar.Add(") {
if (StrSplit(Trim(A_LoopField), "(")[1] == "MenuBar.Add") {
new_outscript .= StrReplace(A_LoopField, "MenuBar.Add(", "MenuBar_Storage.Add(")
new_outscript .= "`n"
}
}
else if InStr(A_LoopField, ".MenuToolbar := MenuBar") {
new_outscript .= StrReplace(A_LoopField, "MenuToolbar := MenuBar", "MenuBar := MenuBar_Storage")
new_outscript .= "`n"
}
else if InStr(A_LoopField, ".Show(`"") && (buttonFound == 0) && (editFound == 1) {
for i in Edit_Storage {
new_outscript .= i ".OnEvent(`"Change`", EditHandler)`n"
}
new_outscript .= A_LoopField . "`n"
}
else {
new_outscript .= A_LoopField . "`n"
}
}
return new_outscript
}
tooltip_(string := "") {
if (string != "") {
string := "The edit values include:`" " . string
}
return "{`n`tToolTip `"Click! This is a sample action. ``n" string ", 20, 20`n`tSetTimer () => ToolTip(), -3000 `; timer expires in 2 seconds and tooltip disappears`n}`n"
}
replied on githubsashaatx wrote: ↑04 May 2023, 05:00Hi Guest,
I reached out a week ago, I'd love to connect. I'm making a bunch of additions as I work with my EasyAutoGUI modded for v2 script.
I would just need your help with how to navigate the regex vs my instr mods. A brief chat would help me navigate the github.
yea sorry the confusion of usernames. probably best to post bugs on github i think. i dont work on it too much anymore and sometimes other contributors see the issues on therekunkel321 wrote: ↑05 Aug 2023, 13:44Hi there Guest3456. Thanks for making this excellent tool and sharing it. I had assumed that mmikeww was the same person as the forum user mikeyww, but I guess not. Anyway, should possible bugs by discussed here on this forum thread, or should we just post here: https://github.com/mmikeww/AHK-v2-script-converter/issues ?
i have no problem with you doing thisgeek wrote: ↑03 Feb 2024, 11:26Would there be interest in a hosted version of this conversion tool? I should be able to pull all the code into the wiki sandbox (https://autohotkey.wiki/cloudahk) and write some front-end code to provide a diffing interface like shown in the original post. This should allow people to use the tool without needing to download anything, they'd just have to visit in the browser.