SXXXXXXX_RadarDataReader/_src_idl/pcrdv_E/GUI/ProgressBar.pro
VALLONGOL 5de2650675 add
2025-11-12 13:43:30 +01:00

196 lines
4.8 KiB
Prolog

; -------- UTILIZZO DELLA PROGRESSBAR COME WIDGET ESTERNO-----------------------------------
;
;ESEMPIO:
;progress=NewProgressBarWin(Event.Top,'Loading batches...',/cancel)
;
; loop ...
;
; FOR i = 1, N DO $
; BEGIN
;
; ...
;
; stop_req = SetProgressBarWin(progress,1.*i/N)
;
; IF stop_req THEN BREAK
; END
;
;
; -------- UTILIZZO DELLA PROGRESSBAR ALL'INTERNO DI UN WIDGET -----------------------------
;
;
; Qui si definisce l'oggetto ProgressBar ed i relativi metodi
;
; esempio di utilizzo:
;
; si crei un oggetto WIDGET_DRAW con il GUI builder o manualmente.
; si indichi con WID_progress l'id del widget DRAW ed in fase di Realize del Top Widget
; si scriva:
;
; MyProgressBar = obj_new('ProgressBar',WID_progress,30)
; WIDGET_CONTROL,WID_progress,SET_UVALUE=MyProgressBar
;
; (con 30 si intende dividere la barra in 30 blocchi)
; in qualunque momento per impostare un valore alla posizione della barra si scriva
;
; WID_MyProgressBar = widget_info(Event.top, FIND_BY_UNAME=widget_name)
; WIDGET_CONTROL,WID_MyProgressBar,GET_UVALUE=MyProgressBar
;
; MyProgressBar->setDecimalValue,0.4
;
; con 0.4 si intende barra al 40 %
function ProgressBar::getDecimalValue
return,self.value
end
pro ProgressBar::setDecimalValue,value
COMPILE_OPT IDL2
n=fix(((value<1)>0)*self.count)
old_n = fix(((self.value<1)>0)*self.count)
self.value=((value<1)>0)
if (n ne old_n) then begin
WSET,self.Win_ID
image=BYTARR(self.Xsize-4,self.Ysize-4)+255
tv,image,2,2
block = BYTARR(self.Xsize/self.count-2,self.Ysize-6,3)
block[*,*,2] = 128
for i=0,n-1 do tv,block,i*self.Xsize/self.count+1,3,true=3
end
end
function ProgressBar::init,WID_widget_draw,count
COMPILE_OPT IDL2
geom = widget_info(WID_widget_draw,/geometry)
self.Xsize = geom.scr_Xsize
self.Ysize = geom.scr_Ysize
WIDGET_CONTROL, WID_widget_draw, GET_VALUE = Win_ID
self.Win_ID = Win_ID
self.count = count
WSET,Win_ID
image=BYTARR(self.Xsize,self.Ysize)+255
image[*,self.Ysize-[1,2],*]=100
image[[0,1],*,*]=100
image[self.Xsize-1,*,*]=255
image[self.Xsize-2,*,*]=200
image[*,0,*]=255
image[*,1,*]=200
tv,image
return,1
end
pro ProgressBar__define
struct={ProgressBar,Win_ID:0,value:0.,Xsize:0,Ysize:0,count:0}
end
function NewProgressBarWin,groupLeader,title,cancel = cancel,MODAL=MODAL,FLOATING=FLOATING
COMPILE_OPT IDL2
xsize = 200
ysize = 15
LeaderGeometry = WIDGET_INFO (groupLeader,/GEOMETRY)
wBase = widget_base( $
;/ROW, $
FLOATING=FLOATING, $
GROUP_LEADER=groupLeader, $
MODAL = MODAL, $
TITLE=title, $
YSIZE=YSIZE+25 , $
XSIZE = xsize+120 , $
XOFFSET = LeaderGeometry.XOFFSET + LeaderGeometry.XSIZE/2-(xsize+120)/2, $
YOFFSET = LeaderGeometry.YOFFSET + LeaderGeometry.YSIZE/2-(ysize+25)/2 , $
_EXTRA=_extra)
wDraw = widget_draw(wBase, XSIZE=xsize, YSIZE=ysize,sensitive=0,YOFFSET=10,XOFFSET = 10)
wLabel = widget_label(wBase,xsize=30,value=' 0 %',XOFFSET=xsize+15,YOFFSET=10)
if keyword_set(Cancel) then wCancel = $
widget_button(wBase, VALUE=' Cancel ', EVENT_PRO='ProgressBarCancel',XOFFSET=xsize+50,YOFFSET=5) $
else wCancel = 0L
widget_control, wBase, /REALIZE
MyProgressBar = obj_new('ProgressBar',wDraw,20)
; Cache my state information
state = { $
wBase: wBase, $
wDraw: wDraw, $
wCancel: wCancel, $
wLabel: wLabel , $
ProgBar: MyProgressBar, $
BaseTitle : Title , $
stopReq: 0 $
}
widget_control, wBase, SET_UVALUE=state
return,wBase
end
function SetProgressBarWin,Id,value,Title=Title
COMPILE_OPT IDL2
widget_control, Id, Bad_ID=bad
if ~bad then $
BEGIN
ev = WIDGET_EVENT(/NOWAIT)
widget_control, Id, GET_UVALUE=state
state.ProgBar -> setDecimalValue,value
WIDGET_CONTROL,state.wLabel,SET_VALUE=STRING(value*100,format='(i3)')+' %'
if keyword_set(title) THEN $
BEGIN
state.BaseTitle = title
widget_control, Id, SET_UVALUE=state
END
widget_control, Id,BASE_SET_TITLE = state.BaseTitle +' '+$
STRING(value*100,format='(i3)')+' %'
fine = (value EQ 1) OR (state.stopReq)
if fine then $
widget_control,Id,/DESTROY
return,fine
ENDIF ELSE return,2
end
pro ProgressBarCancel,Event
COMPILE_OPT IDL2
widget_control, event.top, GET_UVALUE=state
state.stopReq = 1
widget_control, event.top, SET_UVALUE=state
end