It is currently Mon Dec 16, 2019 5:30 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: [Done] PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Mon Jan 14, 2019 9:15 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Sep 20, 2004 7:12 am
Posts: 519
Location: Hell
The following example runs as expected without the QT subsystem, but fires an additional event when QT has been activated:
Code:
Procedure OnChange()
   Debug "Event"
EndProcedure

Procedure OnClick()
   ClearGadgetItems(0)
EndProcedure


If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   TreeGadget(0, 10, 10, 320, 120)
   ButtonGadget(1, 140, 130, 60, 25, "Clear")
   
   For i = 0 To 5
      AddGadgetItem(0, -1, "Line " + Str(i))
   Next i
   
   BindGadgetEvent(0, @OnChange(), #PB_EventType_Change)
   BindGadgetEvent(1, @OnClick())
   
   
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
Link dead?
Change h3x0r.ath.cx into hex0rs.coderbu.de and all will be fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Tue Jan 15, 2019 8:51 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1165
Location: right here
HeX0R wrote:
but fires an additional event when QT has been activated
Only if you select an item before 'clear'. The removal of the selected item issues a change (deselection) event. That seems right to me, so maybe the flaw is on the gtk side of things?


Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Tue Jan 15, 2019 10:34 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Sep 20, 2004 7:12 am
Posts: 519
Location: Hell
My main problem was, that DeleteGadgetItems() immediately jumps to OnChange(), while I'm in the middle of processing OnClick().
I didn't expect that, to my knowledge all BindEvents will only be processed as soon as the next message has been collected from the msg queue (via WaitWindowEvent()).

And that had me scratch my head quite a while to finally find the difference between gtk and qt.

_________________
Link dead?
Change h3x0r.ath.cx into hex0rs.coderbu.de and all will be fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Tue Jan 15, 2019 10:48 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Sep 20, 2004 7:12 am
Posts: 519
Location: Hell
I think I could live with that event, IF the gadget gets cleared BEFORE the event will be fired.
See here:
Code:
Procedure OnChange()
   Debug "OnChange() start"
   Debug "Items: " + CountGadgetItems(0)
   Debug "Event"
   Debug "OnChange() end"
EndProcedure

Procedure OnClick()
   Debug "OnClick() start"
   Debug "Clear Items"
   ClearGadgetItems(0)
   Debug "Items cleared"
   Debug "OnClick() end"
EndProcedure


If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   TreeGadget(0, 10, 10, 320, 120)
   ButtonGadget(1, 140, 130, 60, 25, "Clear")
   
   For i = 0 To 5
      AddGadgetItem(0, -1, "Line " + Str(i))
   Next i
   
   BindGadgetEvent(0, @OnChange(), #PB_EventType_Change)
   BindGadgetEvent(1, @OnClick())
   
   
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


The tree still contains all items, when the event gets called, and that made my app crash, because it tried to reach a dataitem which was no longer there.

So mainly all the problems are coming from ClearGadgetItems().

_________________
Link dead?
Change h3x0r.ath.cx into hex0rs.coderbu.de and all will be fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Tue Jan 15, 2019 12:02 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1165
Location: right here
I think that's normal. The bound callbacks get called directly at the time the event is issued, not when the event get processed in the event loop later. This can case some some surprise, I agree.


Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Tue Jan 15, 2019 1:12 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Sep 20, 2004 7:12 am
Posts: 519
Location: Hell
See here freaks last statement.
And until now this was true, for Win and Linux (gtk) at least.

_________________
Link dead?
Change h3x0r.ath.cx into hex0rs.coderbu.de and all will be fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Tue Jan 15, 2019 6:30 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2073
Location: Germany
I get an Event OnChange when an item is selected.
It helps if you remove the selection first.

I think the event come from QT
Code:
Procedure OnChange()
   Debug "OnChange() start"
   Debug "Items: " + CountGadgetItems(0)
   Debug "Event"
   Debug "OnChange() end"
EndProcedure

Procedure OnClick()
   Debug "OnClick() start"
   Debug "Clear Items"
   ;
   SetGadgetState(0, -1)
   ;
   ClearGadgetItems(0)
   Debug "Items cleared"
   Debug "OnClick() end"
EndProcedure


If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   TreeGadget(0, 10, 10, 320, 120)
   ButtonGadget(1, 140, 130, 60, 25, "Clear")
   
   For i = 0 To 5
      AddGadgetItem(0, -1, "Line " + Str(i))
   Next i
   
   BindGadgetEvent(0, @OnChange(), #PB_EventType_Change)
   BindGadgetEvent(1, @OnClick())
   
   
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Tue Jan 15, 2019 6:42 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Tue Jan 15, 2019 6:38 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Sep 20, 2004 7:12 am
Posts: 519
Location: Hell
Yes, that's exactly what I did also to get rid of this effect.

_________________
Link dead?
Change h3x0r.ath.cx into hex0rs.coderbu.de and all will be fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: PB 5.70 QT TreeGadget fires event when cleared
PostPosted: Mon Feb 18, 2019 10:31 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13663
Location: France
Fixed. The rules in PB is an event shouldn't be fired when using a PB command (ie: only when a user interact with your app).


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye