Page 1 of 1
Problems with 'SpinGadget()'
Posted: Wed Jul 02, 2003 5:03 pm
by Naitfreak
I'm trying to add a spingadget to a tab of a panel gadget and change/update it's value later on. But somehow it doesn't work and runs into an endless loop and doesnt' respond anymore so you have to exit with the debugger. Strange thing is that it works when you are adding the spingadget to the main window instead of panel gadget.
This won't work for me:
Code: Select all
OpenWindow(0,0,0,300,200,#PB_Window_SystemMenu | #PB_Window_ScreenCentered,"untitled")
CreateGadgetList(WindowID())
PanelGadget(0,10,10,280,180)
AddGadgetItem(0,-1,"tab 1")
ButtonGadget(1,50,50,70,25,"button 1")
AddGadgetItem(0,-1,"tab 2")
ButtonGadget(2,60,60,70,25,"button 2")
AddGadgetItem(0,-1,"tab 3")
ButtonGadget(3,70,70,70,25,"button 3")
SpinGadget(4,180,80,70,25,0,100)
CloseGadgetList()
SetGadgetText(4,"5")
SetGadgetState(4,5)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventGadgetID() = 4
SetGadgetText(4,Str(GetGadgetState(4)))
WindowEvent()
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
But this works without a flow:
Code: Select all
OpenWindow(0,0,0,300,200,#PB_Window_SystemMenu | #PB_Window_ScreenCentered,"untitled")
CreateGadgetList(WindowID())
SpinGadget(4,180,80,70,25,0,100)
SetGadgetText(4,"5")
SetGadgetState(4,5)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventGadgetID() = 4
SetGadgetText(4,Str(GetGadgetState(4)))
WindowEvent()
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
It should work for panel gadgets like it does for plain windows, shouldn't it? So what the heck I'm doing wrong?
Posted: Wed Jul 02, 2003 7:44 pm
by GPI
When you change the state or the text of a spin, it will also create a message, so you can get a endless loop.
I do it so:
Code: Select all
EventType=EventType()
.
.
.
.
Case #gadget_pref_SpinTab
If GetGadgetState(#gadget_pref_SpinTab)<>Val(GetGadgetText(#gadget_pref_SpinTab))
If EventType=-1 Or EventType=1
SetGadgetText(#gadget_pref_SpinTab,Str(GetGadgetState(#gadget_pref_SpinTab)))
Else
SetGadgetState(#gadget_pref_SpinTab,Val(GetGadgetText(#gadget_pref_SpinTab)))
EndIf
EndIf
It is undocumented, but eventtype()=1/-1 when you press the up/Down button. (Fred, is this secure? When yes, why no #pb_eventtype_spinup/spindown?)
Posted: Thu Jul 03, 2003 12:35 am
by Naitfreak
#gadget_pref_SpinTab ? What on earth is going on? This looks pretty complicated compared to what I want to achieve. Now apart from the fact that it looks difficult it doesnt work at all. Neither "SetSciEdiParameter()" nor "pref_setFonts()" are found by PB ("no function, array or linked list.").
Well, I guess there is no regular/easy way to simply put a spingadget on a tab of a panel gadet? Besides this work-a-round? I can hardly belive that.
Cmon' people There must be a way!
Posted: Thu Jul 03, 2003 9:58 am
by GPI
>#gadget_pref_SpinTab ?
Its only a name of constant. Change this,
>"SetSciEdiParameter()" nor "pref_setFonts()"
It was only a small part of jaPBe and is so not function. I want only show, how it should work.
It is also only show the handling of the spingadget, not the creation etc.
Posted: Thu Jul 03, 2003 4:07 pm
by ebs
Naitfreak,
Easy!
Change:
to
This should work everywhere.
Regards,
Eric
Posted: Thu Jul 03, 2003 4:25 pm
by Naitfreak
@GPI
So #gadget_pref_SpinTab is no Windows API / PB constant but simply the gadget indentfier?
And whats is jaPBe? A special function libary for PB?
@ebs
Well, I guess I wouldn't had figured that out in a thousand years but for sure that way can be called 'easy'. Works like a charm.
Thank you both.
Posted: Thu Jul 03, 2003 5:25 pm
by GPI
>So is no Windows API / PB #gadget_pref_SpinTab constant but simply the
>gadget indentfier?
Yes
>And whats is jaPBe? A special function libary for PB?
just another PureBasic editor. look here:
viewtopic.php?t=6748&postdays=0&postorder=asc&start=0
jaPBe can fold, auocomplete, better tooltip, better dll support (the dll is automatically copy to the destination and not in the compiler directory), filelist (open all needed files of a projekt) etc. Not complete, for example the tool-menu is missing), but help and compile work.
AND don't use more then one windowevent, because it throw so messages away and maybe you lost a important message.
Posted: Thu Jul 03, 2003 5:47 pm
by ebs
GPI,
You make a good point. I believe that the chance of losing an event is small, since the code immediately follows the SpinGadget change. However, your method is safer, so something like this is probably best:
Code: Select all
#PB_EventType_SpinUp = 1
#PB_EventType_SpinDown = -1
...
Repeat
EventID = WaitWindowEvent()
EventType = EventType()
If EventID = #PB_Event_Gadget
If EventGadgetID() = 4
If EventType = #PB_EventType_SpinUp Or EventType = #PB_EventType_SpinDown
SetGadgetText(4, Str(GetGadgetState(4)))
WindowEvent()
EndIf
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Regards,
Eric
Posted: Thu Jul 03, 2003 6:10 pm
by Naitfreak
Oh great! Now you made me insecure again!
Well, but now where you say it could really happen that you lose a message event. The chance is pretty small indeed but why not optimze your code in the first place. I just integrated the new code and it seems to work as predicted.
Thanks again!
PS: jaPBe looks like a nice IDE replacement. Gonna give it a try.
Posted: Thu Jul 03, 2003 7:22 pm
by GPI
@ebs
When you make it so, you don't need windowevent():
Code: Select all
#PB_EventType_SpinUp = 1
#PB_EventType_SpinDown = -1
...
Repeat
EventID = WaitWindowEvent()
EventType = EventType()
If EventID = #PB_Event_Gadget
If EventGadgetID() = 4
if getgadgetstate(4)<>val(getgadgettext(4))
If EventType = #PB_EventType_SpinUp Or EventType = #PB_EventType_SpinDown
SetGadgetText(4, Str(GetGadgetState(4)))
else
setgadgetstate(4,val(getgadgettext(4)))
SetGadgetText(4, Str(GetGadgetState(4))) ; maybe it is not a digit, so corret it.
endif
EndIf
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Posted: Fri Jul 04, 2003 1:46 am
by ebs
GPI,
Cool!

Thanks for the hint. Did you ever get an answer from Fred about whether the EventType of 1/-1 will remain the same in future versions?
Regards,
Eric
Posted: Fri Jul 04, 2003 8:39 am
by Pupil
If you hold down the spin-up or spin-down arror for a longer period the value returned by eventtype() will change to 5/-5 and later even higher values. This was true for earlier versions of PB, i haven't tried on the lastest build but it's worth checking out...
Posted: Fri Jul 04, 2003 9:53 am
by Fred
Yes, eventtype() willn't change in future version.
Posted: Fri Jul 04, 2003 10:18 am
by GPI
I have programmed a little bit to make the handling of spingadgets simpler:
viewtopic.php?p=29610#29610
GPI