Debug Window, A AHK gui based console window

Post your working scripts, libraries and tools
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Debug Window, A AHK gui based console window

16 Sep 2017, 00:26

Tired of using MsgBox to debug your stuff? tried the console ideas that acted weird? Here's a Pure AHK solution for a debug output!

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Debug.MsgBox() is a wrapper arroung MsgBox with the proper flag so you SEE the darn thing even if a topmost window is about.
Debug.Write() Creates the Output Window, if it's not created, then pops it up adding content to the text box.
Debug.WriteNL() , Adds a New Line after the text
Debug.WriteSP() , Adds a space after the text
Debug.MsgBox("Var is: " . var)
Debug.WriteNL("Var is: " . var)

V3.0 Major Additions
Added Debug Level to turn on and off various levels of debug information
Added appropriate commands to the console, see the code
Added Text Limit to cause a Clear when the limit is reached
Added WriteStack set of functions which basically adds leading spaces so you can push a text at the beginning of a function and pop at the end
Added Functions to play with and reset the stack value if you need to, like if you break out of multiple loops... and you are tracing the loop
See example In Post Below

V2 Adds
Debug.WriteClear() To replace the entire content
GUIClose And GUIEscape Events, which close the window. It will pop again when Write() is called, but with new content
Write() will show (and activate) only the first time, since it's on top, subsequent write call only change the text (v2.2 removes the AlwaysOnTop)
Cleaned up some superfluous GUI default calls.
Removed the Edit Box gLabel
Added some console commands
Clear - to reset the text to nothing
Close - to close the window
Exit - to exit the app
Enter:: is used for this window, if it's active, to handle the enter event, since the output box is editable, that was the work around short of adding low level message handling

V2,1
Added
last:=a_defaultgui
Gui, last:Default

V2.2
Removed the Always On Top option
Fixed the send {enter} being performed at the wrong spot in the code
Added >Prompt on enter.
Made comparison for commands case insensitive
Added suggested find last line code and replaced the less efficient loop

V2.3
Bug Fix, Changed
Gui, last:Default
to
Gui, %last%:Default
Last edited by icuurd12b42 on 22 Sep 2017, 02:55, edited 8 times in total.
User avatar
RUNIE
Posts: 246
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 00:33

I don't get why you made the control variables global (or even bothered using control variables in the first place). Also resetting the default gui to Gui 1 after a method has been run is not a good idea.
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 01:41

RUNIE wrote:I don't get why you made the control variables global (or even bothered using control variables in the first place).


I'm hoping to catch edit box events later on to do thing in my project like a console window

Also resetting the default gui to Gui 1 after a method has been run is not a good idea.


Isn't 1 the default gui window id? Why is this not a good idea? Most gui code I've seen don't use multiple GUIs ids. without this The GUI context would switch to the debug window and people's UI stuff would stop working
User avatar
RUNIE
Posts: 246
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 02:36

You can change the default gui. It would be reset to 1 after running any methods from your class.
just me
Posts: 4685
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 03:25

RUNIE wrote:You can change the default gui. It would be reset to 1 after running any methods from your class.
Are you sure?

Code: [Select all] [Download] GeSHi © Codebox Plus

#NoEnv
MsgBox, %A_DefaultGui% ; 1
Test.Method()
MsgBox, %A_DefaultGui% ; NewDefaultGui
Return

Class Test {
Method() {
Gui, NewDefaultGui: Default
}
}

There's no need to change the default GUI within the methods.
Remaining with AHK 1.1.25.02 until v2 will become beta.
User avatar
RUNIE
Posts: 246
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 04:23

just me wrote:Are you sure?

Yes..

Code: [Select all] [Download] GeSHi © Codebox Plus

Gui 5: Default
msgbox % A_DefaultGui ; 5
debug.InitDebugWindow()
msgbox % A_DefaultGui ; 1
return
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 05:09

dude you're messing with my head I been playing with multiple gui for 2 months now...

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
RUNIE
Posts: 246
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 05:36

icuurd12b42 wrote:dude you're messing with my head I been playing with multiple gui for 2 months now...

?? I'm using the code in your OP not some arbitrary code you just wrote to test.
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 05:55

>You can change the default gui. It would be reset to 1 after running any methods from your class.

That statement means that if you set the GUI's default within a function it resets upon the function's exit. Just Me... and myself saw that comment that way.

As for my extra calling of the Set Default and reset to 1 when done which just may not be required every call, I agree, I could be more cautious.
User avatar
RUNIE
Posts: 246
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 06:03

By that I mean you manually set the default Gui to 1. I really thought that was obvious considering the code in the OP.
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 08:05

Well your comments were a bit confusing, you have to admit.

I cleaned up the code and added the missing features and handling and I assure you all the GUI Default left are absolutely needed :) some where removed since I'm doing winapi calls on the text handle... The rest well, to use the ahk methods, they are needed
Helgef
Posts: 2251
Joined: 17 Jul 2016, 01:02
Contact:

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 08:39

You should store a_defaultgui in variable before setting the defualt to the debug gui, then set it back to what you stored, this might or might not be 1, it could be 5 as shown by RUNIE.

Cheers and thanks for sharing :thumbup:
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 08:54

Yeah, I just added that thanks

Would have helped if it had been pointed out that way from the start, his statement implied setting to 1 was pointless because the language resets it to 1 upon a function exit. And it's not just me, but just me as well that saw it that way... and I love these non nonsensical statements from weird user names...
User avatar
boiler
Posts: 1850
Joined: 21 Dec 2014, 02:44

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 09:46

He did point it out that way from the start. He started by telling you that it's not a good idea for you to be changing the default GUI to 1, and you seemed to understand that's what he meant because you said you thought it was fine because most GUI code you've seen only uses one GUI anyway. If you want your code to only be compatible most of the time, that's your choice.

Not trying to drag out this debate, but I'm just pointing out that RUNIE gave you some feedback that really improved the usability of your code, and you seem to be criticizing him for it or for the fact that you didn't understand it. And my feedback here is to try to help you not discourage others from providing useful feedback to you in the future, so please take it as intended.
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 16:39

Yes, I already fixed everything and explained why I was confused and helgef finally pointed out what runie meant, we all good now.
Helgef
Posts: 2251
Joined: 17 Jul 2016, 01:02
Contact:

Re: Debug Window, A AHK gui based console window

16 Sep 2017, 17:04

Internet is the perfect place for misunderstandings...
For the hotkey, maybe use case insensitive (=) comparisons for Exit, Clear, etc commands. And maybe something like this to get the last line instead of the loop,

Code: [Select all] [Download] GeSHi © Codebox Plus

lastLine:=substr(DebugWindow_TextBox_Control,inStr(DebugWindow_TextBox_Control,"`n",,0)+1)
where the 0 in instr says to start looking from the end.
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

17 Sep 2017, 05:23

Done! and added a > prompt on Enter Pressed

Thanks all for the feedbak
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

21 Sep 2017, 07:22

V2.3
Bug Fix, Changed
Gui, last:Default
to
Gui, %last%:Default
icuurd12b42
Posts: 111
Joined: 14 Aug 2016, 04:08

Re: Debug Window, A AHK gui based console window

22 Sep 2017, 02:58

V3.0 Major Additions
Added Debug Level to turn on and off various levels of debug information
Added appropriate commands to the console, see the code
Added Text Limit to cause a Clear when the limit is reached
Added WriteStack set of functions which basically adds leading spaces so you can push a text at the beginning of a function and pop at the end
Added Functions to play with and reset the stack value if you need to, like if you break out of multiple loops... and you are tracing the loop

Example WriteStack Result:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 20 guests