Share your advanced knowledge/code with the community.
User avatar
Peter
 
Posts: 497
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Extending the Debug-Window

by Peter Tue Feb 13, 2018 2:54 pm

Hello,

here is a small snippet to extend the functionality of the debug-window.

Image

Code: Select all
Procedure ExtendDebugWindow()
 
  ! if ($(".spiderwindow-clearbutton").length==1) return;
 
  Protected CSS.s
  Protected DebugWindowContent.s
  Protected FF
 
  CSS = ".spiderwindow-clearbutton           { background-color : #E0E0E0; text-align:center; line-height: 22px; border: 1px solid #ececec; position: absolute; top: 2px; right: 36px; height: 22px; width: 30px; } " + #CRLF$ +
        ".spiderwindow-clearbutton:hover     { background-color : #A8A8A8; } " + #CRLF$ +
        ".spiderwindow-downloadbutton        { background-color : #E0E0E0; text-align:center; line-height: 22px; border: 1px solid #ececec; position: absolute; top: 2px; right: 68px; height: 22px; width: 30px; } " + #CRLF$ +
        ".spiderwindow-downloadbutton:hover  { background-color : #A8A8A8; } " + #CRLF$
 
  ! $("<style>" + v_css + "</style>").appendTo("head");
 
  ! var clearButton    = $("<div title='Clear DebugWindow'            class='spiderwindow-clearbutton    dijitEditorIcon dijitEditorIconNewPage'></div>");
  ! var downloadButton = $("<div title='Download DebugWindow-Content' class='spiderwindow-downloadbutton dijitEditorIcon dijitEditorIconSave'></div>");
  ! var closeButton    = $(".spiderwindow-closebutton")
 
  ! closeButton.before(clearButton);
  ! clearButton.before(downloadButton);
 
  ! clearButton.on("click", function() { $(".spiderwindow").find("textarea").val(""); });
 
  ! downloadButton.on("click", function() {
 
  !   v_debugwindowcontent = $(".spiderwindow").find("textarea").val();
 
  FF = CreateFile(#PB_Any, "DebugWindowContent.txt", #Null)
  If FF
    WriteString(FF, DebugWindowContent)
    ExportFile(FF, "text/plain")
    CloseFile(FF)                     
  EndIf
   
  ! });
 
EndProcedure

ExtendDebugWindow()


Greetings ... Peter
karu
 
Posts: 40
Joined: Mon Feb 24, 2014 10:16 pm

Re: Extending the Debug-Window

by karu Wed Feb 14, 2018 7:21 am

thanks but i got error:
Failed to load resource: the server responded with a status of 404 (Not Found)
dojo.js:28 Error: scriptError
at l (dojo.js:2)
at HTMLScriptElement.<anonymous> (dojo.js:27)
(anonymous) @ dojo.js:28

and error will come when i these lines are present in code:

FF = CreateFile(#PB_Any, "DebugWindowContent.txt", #Null)
If FF
WriteString(FF, DebugWindowContent)
ExportFile(FF, "text/plain")
CloseFile(FF)
EndIf
User avatar
Peter
 
Posts: 497
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Extending the Debug-Window

by Peter Wed Feb 14, 2018 10:30 am

Weird. Are you using the latest version of Spiderbasic (2.20)?

Greetings ... Peter
karu
 
Posts: 40
Joined: Mon Feb 24, 2014 10:16 pm

Re: Extending the Debug-Window

by karu Wed Feb 14, 2018 1:45 pm

Peter wrote:Weird. Are you using the latest version of Spiderbasic (2.20)?

Greetings ... Peter


Image
User avatar
Peter
 
Posts: 497
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Extending the Debug-Window

by Peter Wed Feb 14, 2018 5:19 pm

@all:

Can anyone confirm karus error?

Greetings ... Peter
User avatar
T4r4ntul4
 
Posts: 117
Joined: Wed May 21, 2014 1:57 pm
Location: Netherlands

Re: Extending the Debug-Window

by T4r4ntul4 Thu Feb 15, 2018 12:46 am

Working as expected here (V2.20)

edit: tested with FireFox 58.0.2
karu
 
Posts: 40
Joined: Mon Feb 24, 2014 10:16 pm

Re: Extending the Debug-Window

by karu Thu Feb 15, 2018 8:40 am

Now working, somehow i had missing files. Please advice, how i can put similar button also to other windows, thaks :roll:
User avatar
Peter
 
Posts: 497
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Extending the Debug-Window

by Peter Thu Feb 15, 2018 10:33 am

karu wrote:Now working

i'm glad to read that it was solved.

karu wrote:Please advice, how i can put similar button also to other windows, thaks :roll:

Image
Code: Select all
Procedure AddWindowGadget(Window, Gadget)
 
  If IsWindow(Window) = 0 : ProcedureReturn : EndIf
  If IsGadget(Gadget) = 0 : ProcedureReturn : EndIf
 
  Protected WID = WindowID(Window)
  Protected GID = GadgetID(Gadget)
 
  ! $(v_gid.div).css("right", $(v_gid.div).css("left"));
  ! $(v_gid.div).css("left", "");
 
  ! $(v_gid.div).appendTo(v_wid.title);
 
EndProcedure

Enumeration
  #myWindow
  #myButton1
  #myButton2
EndEnumeration

Procedure myButton1Event()
  Debug "myButton1Event()"
EndProcedure

Procedure myButton2Event()
  Debug "myButton2Event()"
EndProcedure

OpenWindow(#myWindow, #PB_Ignore, #PB_Ignore, 300, 300, "Window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget)

ButtonGadget(#myButton1, 64, 4, 22, 22, "!") ; Please note, that the X-Position of the button is the Right-Position in the titlebar!
GadgetToolTip(#myButton1, "This is button 1")
AddWindowGadget(#myWindow, #myButton1)
BindGadgetEvent(#myButton1, @myButton1Event())

ButtonGadget(#myButton2, 40, 4, 22, 22, "?") ; Please note, that the X-Position of the button is the Right-Position in the titlebar!
GadgetToolTip(#myButton2, "This is button 2")
AddWindowGadget(#myWindow, #myButton2)
BindGadgetEvent(#myButton2, @myButton2Event())


Greetings ... Peter
falsam
 
Posts: 263
Joined: Mon May 05, 2014 9:49 pm
Location: France

Re: Extending the Debug-Window

by falsam Thu Feb 15, 2018 10:41 am

Nice tricks, Peter. Thank you very much.

:idea: Little suggestion because I couldn't do it: Display console errors

➽ Windows 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
User avatar
Peter
 
Posts: 497
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Extending the Debug-Window

by Peter Thu Feb 15, 2018 12:28 pm

falsam wrote:Little suggestion because I couldn't do it: Display console errors


something like this?

Image

Code: Select all
Procedure SetConsole(ConsoleGadget)
 
  Protected ConsoleText.s
 
  ! // define a new console
  ! var console = (function(oldCons) {
 
  !   function ScrollDown() {
  !     var ta = spider_GadgetID(v_consolegadget).gadget.domNode;
  !     $(ta).animate({ scrollTop:$(ta)[0].scrollHeight - $(ta).height() }, 0);
  !   }
 
  !   return {
 
  !     log: function(v_consoletext) {
  SetGadgetText(ConsoleGadget, GetGadgetText(ConsoleGadget) + "Log: " + ConsoleText + #CRLF$)
  !         ScrollDown();
  !         oldCons.log(v_consoletext);
  !     },
 
  !     info: function (v_consoletext) {
  SetGadgetText(ConsoleGadget, GetGadgetText(ConsoleGadget) + "Info: " + ConsoleText + #CRLF$)
  !       ScrollDown();
  !       oldCons.info(v_consoletext);
  !     },
 
  !     warn: function (v_consoletext) {
  SetGadgetText(ConsoleGadget, GetGadgetText(ConsoleGadget) + "Warning: " + ConsoleText + #CRLF$)
  !       ScrollDown();
  !       oldCons.warn(v_consoletext);
  !     },
 
  !     error: function (v_consoletext) {
  SetGadgetText(ConsoleGadget, GetGadgetText(ConsoleGadget) + ConsoleText + #CRLF$)
  !       ScrollDown();
  !       oldCons.error(v_consoletext);
  !     }
 
  !   };
  ! }(window.console));
 
  ! //Then redefine the old console
  ! window.console = console;
 
EndProcedure

Enumeration
  #myWindow
  #myConsole
EndEnumeration

Procedure ThrowError(ErrorText.s)
  ! throw(v_errortext);
EndProcedure

! window.onerror = function(error, url, line) {
!   console.error("Line " + line + ": " + error);
! };

OpenWindow(#myWindow, #PB_Ignore, #PB_Ignore, 500, 300, "Window", #PB_Window_ScreenCentered)

EditorGadget(#myConsole, 10, 10, 480, 280)

SetConsole(#myConsole)

Debug "Hello (triggered by SB-Debug-Command)" ; -> console.log

! console.info("This is an info!");
! console.warn("This is a warning!");
! console.error("This is an error!");

! ThisFunctionDoesntExists(); // throws an "Uncaught ReferenceError"

ThrowError("This is a manually thrown error!")


Greetings ... Peter
Last edited by Peter on Thu Feb 15, 2018 4:31 pm, edited 1 time in total.
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 1 guest