Page 1 of 1

Updating WebGadget URL then refreshing

Posted: Tue Nov 19, 2024 8:06 pm
by PBJim
I'm not sure what I need to change in order to make this work. I'm using PB 6.00 Windows 64-bit and I note the F1 help confirms that SetGadgetText can be used with the web gadget to change the URL, furthermore that SetGadgetState(x, #PB_Web_Refresh) will refresh the gadget.

Two aspects that don't work :

1. When I enter a new URL and click the Update button, it requires two separate clicks before the change takes effect (I can see the browser refresh but it only refreshes same web page)
2. If I set the string gadget to an empty initial value (line 3), it won't ever work, despite what I later enter.

Code: Select all

OpenWindow(0,0,0,800,800,"", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

StringGadget(2,5,5,750,25,"https://time.is")
ButtonGadget(3,5,35,165,25, "Update URL to Web Gadget")
If WebGadget(1,0,70,WindowWidth(0), WindowHeight(0) - 80,GetGadgetText(2))
  Debug "WebGadget created successfully"
EndIf

; ** Below courtesy of Rashad to suppress script messages
Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(1), #GWL_USERDATA)
Browser\put_Silent(1)

Repeat
  event = WaitWindowEvent()
  Select event
      
    Case #PB_Event_CloseWindow
      Break
      
    Case #PB_Event_Gadget
      
      Select EventGadget()
        Case 3
          
          Debug "Updating URL"
          Debug "> " + GetGadgetText(2)
          
          If GetGadgetText(2) <> ""
            SetGadgetText(1, GetGadgetText(2))
            SetGadgetState(1, #PB_Web_Refresh)
          EndIf
          
      EndSelect
  EndSelect
ForEver

Re: Updating WebGadget URL then refreshing

Posted: Tue Nov 19, 2024 9:16 pm
by infratec
Comment out:

Code: Select all

;SetGadgetState(1, #PB_Web_Refresh)
You override the new setting by loading the old one again.

Re: Updating WebGadget URL then refreshing

Posted: Wed Nov 20, 2024 10:13 am
by PBJim
infratec wrote: Tue Nov 19, 2024 9:16 pm Comment out:

Code: Select all

;SetGadgetState(1, #PB_Web_Refresh)
You override the new setting by loading the old one again.
Thanks Infratec, it works superbly.

Incidentally I also needed to be able to clear the contents of the webgadget and happened to find this in another forum post. Strangely it appears to be undocumented and the page for WebGadget, under SetGadgetItemText(), refers only to an html switch for streaming into the gadget.

Code: Select all

SetGadgetItemText(Wbg, 1, "")                               ; Clear webgadget