|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Sun Jul 13, 2008 10:08 pm Post subject: Run-pause-stop |
|
|
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.
Code: |
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
|
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7942 Location: Salford, UK
|
Posted: Mon Jul 14, 2008 2:22 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2391 Location: Yateley, Hants, UK
|
Posted: Mon Jul 14, 2008 6:18 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Mon Jul 14, 2008 11:30 pm Post subject: |
|
|
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? |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2391 Location: Yateley, Hants, UK
|
Posted: Tue Jul 15, 2008 12:55 am Post subject: |
|
|
Aha ... I knew that someone would know. It is right there in Win32api.ins
So that's how to do it.
Thanks
Eddie |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2560 Location: Sydney
|
Posted: Tue Jul 15, 2008 4:48 am Post subject: |
|
|
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 |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Tue Jul 15, 2008 7:58 pm Post subject: |
|
|
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. |
|
Back to top |
|
|
|
|
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 You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|