When moving a window, should events stop?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Thumper
User
User
Posts: 97
Joined: Sat Feb 01, 2014 2:16 am
Location: Alabama USA

When moving a window, should events stop?

Post 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
I enter the PureBasic world, targeting both Mac and Windows, by way of PowerBasic, Win32API, EZGUI back to CP/M via various BASIC dialects, xBase and other languages as needed.
Side project: http://www.thecomputerarchive.com
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: When moving a window, should events stop?

Post 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
Egypt my love
User avatar
Thumper
User
User
Posts: 97
Joined: Sat Feb 01, 2014 2:16 am
Location: Alabama USA

Re: When moving a window, should events stop?

Post 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?
I enter the PureBasic world, targeting both Mac and Windows, by way of PowerBasic, Win32API, EZGUI back to CP/M via various BASIC dialects, xBase and other languages as needed.
Side project: http://www.thecomputerarchive.com
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: When moving a window, should events stop?

Post 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

Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: When moving a window, should events stop?

Post 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


Egypt my love
User avatar
Thumper
User
User
Posts: 97
Joined: Sat Feb 01, 2014 2:16 am
Location: Alabama USA

Re: When moving a window, should events stop?

Post 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!
I enter the PureBasic world, targeting both Mac and Windows, by way of PowerBasic, Win32API, EZGUI back to CP/M via various BASIC dialects, xBase and other languages as needed.
Side project: http://www.thecomputerarchive.com
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: When moving a window, should events stop?

Post 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
User avatar
Thumper
User
User
Posts: 97
Joined: Sat Feb 01, 2014 2:16 am
Location: Alabama USA

Re: When moving a window, should events stop?

Post 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
I enter the PureBasic world, targeting both Mac and Windows, by way of PowerBasic, Win32API, EZGUI back to CP/M via various BASIC dialects, xBase and other languages as needed.
Side project: http://www.thecomputerarchive.com
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: When moving a window, should events stop?

Post by BarryG »

Just posted that for the benefit of future lurkers, mainly. Just so they don't get a wrong impression about PureBasic. ;)
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: When moving a window, should events stop?

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: When moving a window, should events stop?

Post by mk-soft »

For threads here are some examples

Link: Mini Thread Control
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply