Silverfrost Forums

Welcome to our forums

Run-pause-stop

13 Jul 2008 9:08 #3448

From early days of Clearwin I was surprised that this simple Run-Pause-Stop prototype code does not work. Ones it started, it does not react on anything besides %ac keys.

Is there any way to make it respond on Run-Pause-Continue-Stop button clicks with minimum changes ? No .NET multithreading, or additional windows opened where controls will reside please.

module button_controls
      double precision progress_bar
      integer start_button_enabled
      integer stop_button_enabled
      integer pause_button_enabled
      integer continue_button_enabled
      integer k_pause_butt_on
      integer k_stop_run
end module button_controls
   winapp
   use button_controls
   use clrwin	
   integer  start_run, stop_run, continue_run, pause_run, close_window
   external start_run, stop_run, continue_run, pause_run, close_window
      start_button_enabled    = 1
      continue_button_enabled = 0
      pause_button_enabled    = 0
      stop_button_enabled     = 0
      k_pause_butt_on         = 0
      k_stop_run 	      = 0
      progress_bar            = 0
   k = winio@ ('%ca[Run-pause-stop]%sy[3d_thin]&')
   k = winio@ ('%50.10cw%ff%nl&', 0)
   k = winio@ ('%50br %nl%ff&', progress_bar, RGB@(255,0,0) )
   k = winio@ ('%cn%^~bt[Start] %^~bt[Pause] %^~bt[Continue]%^~bt[Stop]%nl&', &
    & start_button_enabled, start_run, pause_button_enabled, pause_run, &
    & continue_button_enabled, continue_run, stop_button_enabled, stop_run)
   k = winio@ ('%ac[Ctrl+A]&', start_run)
   k = winio@ ('%ac[Ctrl+S]&', pause_run)
   k = winio@ ('%ac[Ctrl+Q]&', continue_run)
   k = winio@ ('%ac[Ctrl+E]&', stop_run)
   k = winio@ ('%ac[Esc]&',  '+',close_window,'exit')
   k = winio@ ('%cn%^bt[OK]','+',close_window,'exit')
end
!-------------------------------
integer function start_run ()
   use clrwin	
   use button_controls
   start_button_enabled    = 0
   stop_button_enabled     = 1
   pause_button_enabled    = 1
   continue_button_enabled = 1
   k_pause_butt_on         = 0
   k_stop_run              = 0
   call window_update@(start_button_enabled)
   call window_update@(stop_button_enabled)
   call window_update@(pause_button_enabled)
   call window_update@(continue_button_enabled)
   num_runs = 100	
   do m = 1, num_runs
      progress_bar = m / real(num_runs)
       a=2.0 
       do i=1,400000 
	 do while ( k_pause_butt_on.eq.1 )
           CALL TEMPORARY_YIELD@
	   call sleep1@(0.5)
           call sound@(3333,1)
	 enddo
	a=alog(exp(a))
	if(k_stop_run.eq.1)  goto 1000
       enddo
         print *, m, ' / ', num_runs
         call window_update@(progress_bar)
   enddo	
1000 return
   start_run = 2
end function start_run 
!------------------------------------
integer function pause_run ()
  use clrwin	
  use button_controls
  k_pause_butt_on = 1
  call window_update@(k_pause_butt_on)
  pause_run=1
end function pause_run
!-----------------------------------
integer function continue_run ()
  use clrwin	
  use button_controls
  k_pause_butt_on = 0
  call window_update@(k_pause_butt_on)
  continue_run=1
end function continue_run
!------------------------------
integer function stop_run ()
  use clrwin	
  use button_controls
  k_pause_butt_on = 0
  k_stop_run = 1
  stop_run=1
end function stop_run
!------------------------------------
integer function close_window()
  use clrwin	
  use button_controls
  k_pause_butt_on = 0
  close_window = 1	
end function close_window
14 Jul 2008 1:22 #3451

The trick is to call PERMIT_ANOTHER_CALLBACK@() at some point within the function start_run.

I put it before the 'do while' but this may not be the best place.

14 Jul 2008 5:18 #3453

While trying it out, it did occur to me that once the Pause button has been pressed, Pause and Stop needed to be disabled (greyed out). [Paul's suggested modification works better if only Continue can be selected after Pause]

That only leaves Continue as a valid selection. By default, as all the other buttons are inactive, Continue should have the focus. I spent some time looking for a way of setting the highlight on Continue to show that it has focus, and couldn't find it. (Continue must HAVE focus, because it is the only control. However it doesn't show that it has focus).

%if can give a control initial focus, but I couldn't find a way of giving focus to a specific control in Clearwin+ at a later time. This is odd, because .NET has vcFOCUS@. Maybe it is simply undocumented?

Eddie

14 Jul 2008 10:30 #3456

I'm no Clearwin expert at all, but there is a Windows API function SetFocus which takes an HWND. If you can get the handle for a contol then perhaps this can be used?

14 Jul 2008 11:55 #3457

Aha ... I knew that someone would know. It is right there in Win32api.ins

So that's how to do it.

Thanks

Eddie

15 Jul 2008 3:48 #3459

If you use a menu instead of buttons, then its very easy to grey out menu options.

I use an interrupt routine to change the grey state of menu options when interrupting the running of a program.

The art is to not test for an interrupt using temporary_yield@, too often or too infrequently.

John

15 Jul 2008 6:58 #3463

Thanks, Paul, for the trick with PERMIT_ANOTHER_callback, i completely forgot about it, but I am still fighting to achieve reliable work of the code. For example, adding 'call PERMIT_ANOTHER_callback@()' to each of these Start, Pause, Continue, Stop callback functions does not completely solves the problem (let put aside focusing questions for a moment). Now you can Pause the task, but the code stalls here etc.

Request to everyone: if you succeed to make this prototype functional please do not forget to post the final solution.

Please login to reply.