October 26, 2020, 01:32:57 AM

Author Topic: How to force a gadget to refresh?  (Read 2034 times)

Offline GW

  • Full Member
  • ***
  • Posts: 202
How to force a gadget to refresh?
« on: July 09, 2017, 01:43:49 AM »
Anyone know how to make a gadget refresh in maxgui?  Im looping over some data and adding some things to a textarea.
Even with calling pollsystem(), the app will stop updating and the title bar will add the words (not responding).
When doing Gui apps in dotNet you can call a function called Application.DoEvents() to make the gui refresh.
Is there something equivalent for maxgui?


 

Offline degac

  • Full Member
  • ***
  • Posts: 159
    • graphio.net
Re: How to force a gadget to refresh?
« Reply #1 on: July 09, 2017, 11:37:19 AM »
Not at the computer at the moment, but RefreshGadget() should do the job.
I can check (later)
If there's a problem, there's at least one solution.
www.blitzmax.org

Offline TomToad

  • Hero Member
  • *****
  • Posts: 517
Re: How to force a gadget to refresh?
« Reply #2 on: July 09, 2017, 11:50:18 AM »
I think you are looking for PollEvent().  What happens is that while you are looping over the data, events are not being processed, and when the queue is filled up, you get a (not responding).  I tried out PollEvent() in an example and the program kept running fine, but when I clicked on anything, suck as the x on top, then I got a (not responding) so it fixed only half the problem.
Code: [Select]
SuperStrict

Import maxgui.drivers

Global MainWindow:TGadget = CreateWindow("Hello",50,50,640,480)
Global TextArea:TGadget = CreateTextArea(0,0,ClientWidth(MainWindow),ClientHeight(MainWindow)-100,MainWindow)
Global AddButton:TGadget = CreateButton("Add",0,ClientHeight(MainWindow)-100,ClientWidth(MainWindow),100,MainWindow)
AddHook EmitEventHook,Hook

Repeat
WaitEvent()
Forever

Function Hook:Object(id:Int,data:Object,context:Object)
Local Event:TEvent = TEvent(data)

Select Event.id
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
End
Case EVENT_GADGETACTION
DoAdd()
End Select
End Function

Function DoAdd()
SetTextAreaText TextArea,""

For Local x:Int = 0 To 100000000
AddTextAreaText TextArea,x+" "
If Not(x Mod 10)Then AddTextAreaText TextArea,"~n"
Repeat
Until Not PollEvent()
Next
End Function
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline degac

  • Full Member
  • ***
  • Posts: 159
    • graphio.net
Re: How to force a gadget to refresh?
« Reply #3 on: July 09, 2017, 12:09:36 PM »
Ah, understood the problem, but I think it's something by design in MaxGUI/OS.
One solution (not tested on all platforms) is to bypass the normal behaviour using

Textarea.LockText() and TextArea.UnlockText() before and after adding/changing the text.

This will be faster, and you still have 'control' of the window, but there's no 'interaction' (=you don't see any update in the textarea gadget until the call of UnLockText() method).
If there's a problem, there's at least one solution.
www.blitzmax.org

Offline GW

  • Full Member
  • ***
  • Posts: 202
Re: How to force a gadget to refresh?
« Reply #4 on: July 09, 2017, 07:08:23 PM »
Thanks for the help guys!
Pollsystem seems reduce the problem by about 70%. I tried lock/unlocktextarea and that seems to improve it too, but it scrolls the textarea back to the top. My textarea is a logging window, so i need to always scrolled at the bottom.
I'm calling it good enough.
Thanks!

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal