Can't (un)HideGadget()[SOLVED]

Just starting out? Need help? Post your questions and find answers here.
rule
User
User
Posts: 14
Joined: Sat Sep 02, 2006 7:56 pm
Location: Oostzaan / Netherlands

Can't (un)HideGadget()[SOLVED]

Post by rule »

I'm playing about with HideGadget(), but it wont work the way I want. I need it for a project with moving textboxes.

Code: Select all

;{- Enumerations / DataSections
;:PureFORM:Init:Start:
; PureFORM V1.99 ~ 3-6-2012 14:53:08
;{ Windows
Global Window_0
;}
;{ Gadgets
Global String_0
Global String_1
Global Button_2
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;:PureFORM:Init:End:
;}
;:PureFORM:Windows:Start:
;:PureFORM:Window_0_1:Start:
Procedure OpenWindow_Window_0()
  Window_0 = OpenWindow(#PB_Any, 450, 200, 528, 155, "Window_0", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_SizeGadget)
  If Window_0
    String_0 = StringGadget(#PB_Any, 130, 45, 80, 20, "Gadget_0", #PB_String_ReadOnly)
    String_1 = StringGadget(#PB_Any, 225, 45, 80, 20, "Gadget_1", #PB_String_ReadOnly)
    Button_2 = ButtonGadget(#PB_Any, 320, 35, 85, 35, "Go")
    ;
    HideGadget(String_0,1)
    HideGadget(String_1,1)
    ;:PureFORM:Window_0_1:End:
    ; Your code here ...

    ;
    ;:PureFORM:Window_0_2:Start:
  EndIf
EndProcedure
;:PureFORM:Window_0_2:End:
;:PureFORM:Windows:End:
;
;:PureFORM:Gadgets:Start:
;
;:PureFORM:Gadget_2_1:Start:
Procedure Button_2_OnEvent(EventType.l)
  HideGadget(String_0,0)
  Delay(500)
  HideGadget(String_0,1)
  HideGadget(String_1,0)
  Delay(500)
  HideGadget(String_1,1)
  ;:PureFORM:Gadget_2_1:End:
  ; Your code here ...

  ;
  ;:PureFORM:Gadget_2_2:Start:
EndProcedure
;:PureFORM:Gadget_2_2:End:
;:PureFORM:Gadgets:End:

OpenWindow_Window_0()
;:PureFORM:Main:Start:
;:PureFORM:Main:End:

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  ;:PureFORM:Loop:Start:
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = String_0
      ElseIf EventGadget = String_1
      ElseIf EventGadget = Button_2
        Button_2_OnEvent(EventType)
      EndIf
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = Window_0
        CloseWindow(Window_0)
        Window_0 = 0
        Break
      EndIf
  EndSelect
  ;:PureFORM:Loop:End:
ForEver
;
;}
;:PureFORM:AfterLoop:Start:
;:PureFORM:AfterLoop:End:
Am I doing wrong?

TIA,
Roel.
Last edited by rule on Sun Jun 03, 2012 4:03 pm, edited 1 time in total.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: Can't (un)HideGadget()

Post by eJan »

You have hidden gadgets already, simply comment lines 25 and 26 and it should work.

Code: Select all

;     HideGadget(String_0,1)
;     HideGadget(String_1,1)
Image
rule
User
User
Posts: 14
Joined: Sat Sep 02, 2006 7:56 pm
Location: Oostzaan / Netherlands

Re: Can't (un)HideGadget()

Post by rule »

Thank you for your reply,

But the boxes should come up and vanish with a delay of 500ms. But now they all are hidden and stay that way.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Can't (un)HideGadget()

Post by Demivec »

rule wrote:Thank you for your reply,

But the boxes should come up and vanish with a delay of 500ms. But now they all are hidden and stay that way.
Try this for your event loop instead:

Code: Select all

Define isFirstTime = #True
Repeat
  event = WaitWindowEvent()
  ;:PureFORM:Loop:Start:
  Select event
      ; ///////////////////
    Case #PB_Event_Timer
      If EventTimer() = 0 And EventWindow() = Window_0
        If isFirstTime = #True
          HideGadget(String_0,1)
          HideGadget(String_1,0)
          isFirstTime = #False
        Else
          HideGadget(String_1,1)
          RemoveWindowTimer(Window_0, 0)
          isFirstTime = #True
        EndIf 
      EndIf 
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      eventType = EventType()
      If EventGadget = String_0
      ElseIf EventGadget = String_1
      ElseIf EventGadget = Button_2
        ;Button_2_OnEvent(eventType)
        HideGadget(String_0, 0)
        AddWindowTimer(Window_0, 0, 500)
      EndIf
      ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = Window_0
        CloseWindow(Window_0)
        Window_0 = 0
        Break
      EndIf
  EndSelect
  ;:PureFORM:Loop:End:
ForEver
According to my understanding, events that repaint the gadgets are only processed when no other events are present, and all such events are processed together. In the event loop of your example the hiding and unhiding of the gadgets was done without checking for window events in-between. That meant that only the last action, the re-hiding of the gadgets, was registered in the event loop.
Last edited by Demivec on Sun Jun 03, 2012 3:39 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Can't (un)HideGadget()

Post by infratec »

Hi,

the reason why your first try fails is:
HiddenGadget() applies only in a working eventloop.
You stop inside the loop show it, wait and hide it again.
Since the eventloop is stopped, you see nothing.

To demonstarte it working:

Code: Select all

Procedure Button_2_OnEvent(EventType.l)
  HideGadget(String_0,0)
  i = 0
  Repeat
    Delay(1)
    WindowEvent()
    i + 1
  Until i = 500
  
  HideGadget(String_0,1)
  HideGadget(String_1,0)
  i = 0
  Repeat
    Delay(1)
    WindowEvent()
    i + 1
  Until i = 500
  HideGadget(String_1,1)
  ;:PureFORM:Gadget_2_1:End:
  ; Your code here ...

  ;
  ;:PureFORM:Gadget_2_2:Start:
EndProcedure
But that is not a good idea.
It is only to show you the problem.

Bernd
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Can't (un)HideGadget()

Post by Zebuddi123 »

mnemonic`s make life easier :)

I had missed the fact both gadgets were hidden already so easy to do as we scan as opposed to reading the code :oops:

so make it simpler for your self use mnemonic`s ie

Code: Select all

#hide=1     ;make it easier to follow
#show=0	  ;make it easier to follow

;{- Enumerations / DataSections
;:PureFORM:Init:Start:
; PureFORM V1.99 ~ 3-6-2012 14:53:08
;{ Windows
Global Window_0
;}
;{ Gadgets
Global String_0
Global String_1
Global Button_2
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;:PureFORM:Init:End:
;}
;:PureFORM:Windows:Start:
;:PureFORM:Window_0_1:Start:
Procedure OpenWindow_Window_0()
  Window_0 = OpenWindow(#PB_Any, 450, 200, 528, 155, "Window_0", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_SizeGadget)
  If Window_0
    String_0 = StringGadget(#PB_Any, 130, 45, 80, 20, "Gadget_0", #PB_String_ReadOnly)
    String_1 = StringGadget(#PB_Any, 225, 45, 80, 20, "Gadget_1", #PB_String_ReadOnly)
    Button_2 = ButtonGadget(#PB_Any, 320, 35, 85, 35, "Go")
    ;
;     HideGadget(String_0,#hide) ;not needed but were hidden
;     HideGadget(String_1,#hide) ;not needed but were hidden

    ;:PureFORM:Window_0_1:End:
    ; Your code here ...

    ;
    ;:PureFORM:Window_0_2:Start:
  EndIf
EndProcedure
;:PureFORM:Window_0_2:End:
;:PureFORM:Windows:End:
;
;:PureFORM:Gadgets:Start:
;
;:PureFORM:Gadget_2_1:Start:
Procedure Button_2_OnEvent(EventType.l)
  HideGadget(String_0,#show)
  Delay(500)
  HideGadget(String_0,#hide)
  HideGadget(String_1,#show)
  Delay(500)
  HideGadget(String_1,#hide)
  ;:PureFORM:Gadget_2_1:End:
  ; Your code here ...

  ;
  ;:PureFORM:Gadget_2_2:Start:
EndProcedure
;:PureFORM:Gadget_2_2:End:
;:PureFORM:Gadgets:End:

OpenWindow_Window_0()
;:PureFORM:Main:Start:
;:PureFORM:Main:End:

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  ;:PureFORM:Loop:Start:
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = String_0
      ElseIf EventGadget = String_1
      ElseIf EventGadget = Button_2
        Button_2_OnEvent(EventType)
      EndIf
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = Window_0
        CloseWindow(Window_0)
        Window_0 = 0
        Break
      EndIf
  EndSelect
  ;:PureFORM:Loop:End:
ForEver
;
;}
;:PureFORM:AfterLoop:Start:
;:PureFORM:AfterLoop:End:
Zebuddi. :D
malleo, caput, bang. Ego, comprehendunt in tempore
rule
User
User
Posts: 14
Joined: Sat Sep 02, 2006 7:56 pm
Location: Oostzaan / Netherlands

Re: Can't (un)HideGadget()

Post by rule »

@All,

Worked!
Thank you very much, I've learned allot from you.

Greets from holland,
Roel.
Post Reply