It is currently Thu Jun 21, 2018 7:21 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Needing a wee bit of help
PostPosted: Fri Jan 12, 2018 8:21 pm 
Offline
User
User

Joined: Fri Jul 15, 2016 8:55 pm
Posts: 13
I have written a program that sends a password (or text) to a Window :-

Image

It works as intended but with a slight issue ...

I was trying to be clever and have the send button disable and grey out when pressed, this was so that after pressing the send button, the program would move on to the main procedure mainprog() to actually send the password and stop the send button being pushed multiple times. The problem was that the button did not grey out or disable until the mainprog() finished and returned to the main waitwindow event, the only way I could come up with a solution was to introduce a loop delay, that would loop within the waiteventwindow to give time for the window to redraw before moving on to the mainprog() procedure. This does not work on all systems, timing, CPU etc.

Code:
If Event = #PB_Event_CloseWindow Or GetGadgetState(Button_1)=1 Or sent>=lpdel
 
  DisableGadget(button_0,0)
  SetGadgetState(button_0,0)
 
   tb.s=""
 
  MainProg() ; call main program procedure that kicks of the actual sending of the password
 
EndIf


Other wise program loops within waitwindow event.

Basically I am really struggling to have the send button grey out and disable before moving on to the mainprog() and then re-enable.

Any ideas, I hope I am making sense :-)

I have this at the start of the waitwindow loop :-

Code:
Event = WaitWindowEvent() ;Wait for a Window event
    If sent>0 And sent<lpdel ;sent is set to 1 if Send button is pressed or hotkey key is used, this starts off a counter from 1 to the value of lpdel (This loop delay forces the main window loop routine to repeat (only fix I could come up with to make the gadget update state in the window before exiting main loop to run mainprog()
      sent=sent+1
    EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Needing a wee bit of help
PostPosted: Fri Jan 12, 2018 8:48 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3485
Location: Utah, USA
Perhaps have your button event code disable the button and post a custom event for the main window event loop. In that event loop catch the custom event and call MainProg() before reenabling the button.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Needing a wee bit of help
PostPosted: Fri Jan 12, 2018 9:07 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2665
Location: Boston, MA
Don't think of your spawned program as MainProg().
The primary window of your app and its event loop is Main().
Interrupting that event loop will be noticed by the user.
So, your worker function should be started as a thread and it should PostMessage() back to the gui.
This way your event loop never stalls.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Needing a wee bit of help
PostPosted: Fri Jan 12, 2018 9:19 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3011
Try
Code:
AddWindowTimer(#win,100,10) ;10 ms timeut

Repeat

    Case #PB_Event_Timer
      If pressed = 1
        DisableGadget(#button,1)
        Run + 1
        If Run >= 10 ;10*10 = 100 ms use
          DisableGadget(#button,0)
          pressed = 0
          Run = 0
        EndIf
      EndIf           
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #button
          pressed = 1  ;you may need pressed to be global var.
          ;Send your password         
         
Until .....

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Needing a wee bit of help
PostPosted: Sat Jan 13, 2018 1:36 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 449
Location: Linz, Austria
Evil1 wrote:
Basically I am really struggling to have the send button grey out and disable before moving on to the mainprog() and then re-enable.
Is following example working for you?
Code:
OpenWindow(0, 0, 0, 200, 150, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

ButtonGadget(0, 50, 55, 100, 30, "click me")

Repeat 
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
         
        Case 0         
          DisableGadget(0, 1)         
          While WindowEvent()
            Delay(15)
          Wend         
          Delay(2000) ; <- your MainProg() goes here         
          DisableGadget(0, 0)
         
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow


Top
 Profile  
Reply with quote  
 Post subject: Re: Needing a wee bit of help
PostPosted: Mon Jan 15, 2018 12:17 pm 
Offline
User
User

Joined: Fri Jul 15, 2016 8:55 pm
Posts: 13
chi wrote:
Evil1 wrote:
Basically I am really struggling to have the send button grey out and disable before moving on to the mainprog() and then re-enable.
Is following example working for you?
Code:
OpenWindow(0, 0, 0, 200, 150, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

ButtonGadget(0, 50, 55, 100, 30, "click me")

Repeat 
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
         
        Case 0         
          DisableGadget(0, 1)         
          While WindowEvent()
            Delay(15)
          Wend         
          Delay(2000) ; <- your MainProg() goes here         
          DisableGadget(0, 0)
         
      EndSelect
  EndSelect
Until event = #PB_Event_CloseWindow


Perfect, just what I was after - now works as intended. I should have called mainprog() from within the waitwindow event, the way I was trying to do it was after exiting the waitwindow event :-)

Thanks for all the advice, appreciated.


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 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