Page 1 of 1

When moving a window, should events stop?

Posted: Thu Dec 26, 2024 1:30 am
by Thumper
I have noticed several times that events stop in my event loop while a window move is in progress. My programs are (often) communications intensive and with relatively crude devices and can cause dropped data.

This little tester will will demonstrate it. Move that window around and note str(elapsedMilliseconds() quits updating until the mouse is released.

(And please don't fuss at the coding... It is a piece of one of my little testers that I used to learn how particular aspects of PureBasic works.)

Anyhow, is this an expected behavior and is there any way around it?

Code: Select all

     global.i id10 = 10
     global.i id14 = 14
     global.i id15 = 15

     id10 = openWindow ( #pb_any, 0, 0, 300, 300, "Base window" )
          id14 = buttonGadget ( #pb_any, 0, 50, 150, 50, "Close all" )
          id15 = textGadget ( #pb_any, 0, 100, 300, 50, "Zero" )

     repeat
          event.i = windowEvent ( )

          if event = #pb_event_gadget
               if eventGadget ( ) = id14
                    closeWindow ( id10 )
                    break
               endIf

          elseif event = #pb_event_closeWindow
               if eventWindow ( ) = id10
                    closeWindow ( id10 )
                    break
               endIf

          endIf

          setGadgetText ( id15, str(elapsedMilliseconds()) )
          delay ( 10 )
     forever

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 2:02 am
by RASHAD
Hi

Code: Select all

Global.i id10 = 10
Global.i id14 = 14
Global.i id15 = 15

Procedure moveCB()
  SetGadgetText ( id15, Str(ElapsedMilliseconds()) )
EndProcedure

id10 = OpenWindow ( #PB_Any, 0, 0, 300, 300, "Base window" )
id14 = ButtonGadget ( #PB_Any, 0, 50, 150, 50, "Close all" )
id15 = TextGadget ( #PB_Any, 0, 100, 300, 50, "Zero" )

AddWindowTimer(id10,125,10)
BindEvent(#PB_Event_Timer,@moveCB())
Repeat
  event.i = WindowEvent ( )
  
  If event = #PB_Event_Gadget
    If EventGadget ( ) = id14
      CloseWindow ( id10 )
      Break
    EndIf
  ElseIf event = #PB_Event_CloseWindow
    If EventWindow ( ) = id10
      CloseWindow ( id10 )
      Break
    EndIf
    
  EndIf
  
ForEver

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 3:11 am
by Thumper
Interesting idea. It mostly solves something like that (that it still sometimes stutters a bit after releasing the mouse button) but I was hoping my resize routine to show the results during the resizing. (BTW, I won't get getting into the resizer for another few though.)

Are there any other "artifacts" to event loop stopping?

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 3:28 am
by RASHAD
Hi again :)
The stutters because the moving could be between the 10 ms timer intervals
But the time counter is 100% right
You can use Thread instead

Code: Select all

Global.i id10 = 10
Global.i id14 = 14
Global.i id15 = 15

Procedure moveCB()
  SetGadgetText ( id15, Str(ElapsedMilliseconds()) )
EndProcedure

id10 = OpenWindow ( #PB_Any, 0, 0, 300, 300, "Base window",#PB_Window_SystemMenu |#PB_Window_SizeGadget |#PB_Window_ScreenCentered )
id14 = ButtonGadget ( #PB_Any, 0, 50, 150, 50, "Close all" )
id15 = TextGadget ( #PB_Any, 0, 100, 300, 50, "Zero" )

AddWindowTimer(id10,125,10)
BindEvent(#PB_Event_Timer,@moveCB())
Repeat
  event.i = WindowEvent ( )
  
  If event = #PB_Event_Gadget
    If EventGadget ( ) = id14
      CloseWindow ( id10 )
      Break
    EndIf
  ElseIf event = #PB_Event_CloseWindow
    If EventWindow ( ) = id10
      CloseWindow ( id10 )
      Break
    EndIf
    
  EndIf
  
ForEver


Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 3:39 am
by RASHAD
Using Thread
Enable Threadsafe in compiler option

Code: Select all

Global.i id10 = 10
Global.i id14 = 14
Global.i id15 = 15
Global Quit

Procedure moveCB(val )
  Repeat
    SetGadgetText ( id15, Str(ElapsedMilliseconds()) )
    Delay(10)
  Until Quit = 1
EndProcedure

id10 = OpenWindow ( #PB_Any, 0, 0, 300, 300, "Base window",#PB_Window_SystemMenu |#PB_Window_SizeGadget |#PB_Window_ScreenCentered )
id14 = ButtonGadget ( #PB_Any, 0, 50, 150, 50, "Close all" )
id15 = TextGadget ( #PB_Any, 0, 100, 300, 50, "Zero" )

thread = CreateThread(@moveCB(),30)
Repeat
  event.i = WindowEvent ( )
  
  If event = #PB_Event_Gadget
    If EventGadget ( ) = id14
      Quit = 1
      CloseWindow ( id10 )
      Break
    EndIf
  ElseIf event = #PB_Event_CloseWindow
    If EventWindow ( ) = id10
      CloseWindow ( id10 )
      Break
    EndIf
    
  EndIf
  
ForEver



Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 4:41 am
by Thumper
I have a previous version of this program in PowerBasic and did put the communications in a thread. It's been working great for about 15 years. Probably was going to resort to that in PureBasic.

Have you noticed other instances that will cause the loop to hang ? Of course, aside from routines that are designed to wait for something.

It was just interesting the main processing loop hangs during the move and resize events. I really did not expect that and just part of learning a new system.

One thing I'm really enjoying is the flexibility of the structures. Variable length strings, arrays. Once I get used to typing \ instead of . ! It only took me 50 years of programming to get this organized! haha

Cheers!

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 5:06 am
by BarryG
Thumper wrote: Thu Dec 26, 2024 4:41 amIt was just interesting the main processing loop hangs during the move and resize events. I really did not expect that and just part of learning a new system.
Just so you know: this is Windows doing the event pauses, not PureBasic. It's not a PureBasic bug or issue. You just have to code around it (as shown above) to fix it. As an example, the following loop in Microsoft Visual Basic will also pause the event loop if you click and drag the Form1 window while the label is updating:

Image

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 6:02 am
by Thumper
Never thought it was a bug. Each language is just different. I've just not encountered it in my other programs in inevitably, they are structured differently. I'm trying to keep this one as pure to PureBasic as I can. In fact, the rewrite of a decently sized program (was 360k lines) is progressing well.

I had already worked around one using a timer and two others (one comm, one DirectShow video) will likely be dealt with in a thread once I dig into that to understand how the threads and variables work in them and their associated tools. Anyhow, I expect to be at that stage this weekend.

Cheers

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 7:05 am
by BarryG
Just posted that for the benefit of future lurkers, mainly. Just so they don't get a wrong impression about PureBasic. ;)

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 11:09 am
by infratec
Communication stuff needs always a thread to work independent from the GUI stuff.
There are several examples here in the forum about serial communication.

Re: When moving a window, should events stop?

Posted: Thu Dec 26, 2024 12:10 pm
by mk-soft
For threads here are some examples

Link: Mini Thread Control