Problems with 'SpinGadget()'

Just starting out? Need help? Post your questions and find answers here.
Naitfreak
New User
New User
Posts: 4
Joined: Wed Jul 02, 2003 4:43 pm
Location: Germany
Contact:

Problems with 'SpinGadget()'

Post 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?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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?)
Last edited by GPI on Thu Jul 03, 2003 9:58 am, edited 1 time in total.
Naitfreak
New User
New User
Posts: 4
Joined: Wed Jul 02, 2003 4:43 pm
Location: Germany
Contact:

Post 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!
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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.
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

Naitfreak,

Easy!

Change:

Code: Select all

WindowEvent()
to

Code: Select all

While WindowEvent() : Wend
This should work everywhere.

Regards,
Eric
Naitfreak
New User
New User
Posts: 4
Joined: Wed Jul 02, 2003 4:43 pm
Location: Germany
Contact:

Post 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.
Last edited by Naitfreak on Thu Jul 03, 2003 5:57 pm, edited 1 time in total.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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.
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post 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
Naitfreak
New User
New User
Posts: 4
Joined: Wed Jul 02, 2003 4:43 pm
Location: Germany
Contact:

Post by Naitfreak »

Oh great! Now you made me insecure again! :P

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.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post 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
ebs
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

GPI,

Cool! :o
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
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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...
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Yes, eventtype() willn't change in future version.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

I have programmed a little bit to make the handling of spingadgets simpler:

viewtopic.php?p=29610#29610

GPI
Post Reply