[Python-checkins] CVS: python/dist/src/Mac/Lib EasyDialogs.py,1.34,1.35

Jack Jansen jackjansen@users.sourceforge.net
2001年8月27日 08:24:09 -0700


Update of /cvsroot/python/python/dist/src/Mac/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv9687
Modified Files:
	EasyDialogs.py 
Log Message:
Patch by Dean Draayer: support for indeterminate progress bars. You
get these by specifying maxval=0, which is now also the default.
Untested.
Index: EasyDialogs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Lib/EasyDialogs.py,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** EasyDialogs.py	2001年08月25日 12:04:10	1.34
--- EasyDialogs.py	2001年08月27日 15:24:07	1.35
***************
*** 215,231 ****
 	screenbounds[2]-4, screenbounds[3]-4
 
! 				
 class ProgressBar:
! 	def __init__(self, title="Working...", maxval=100, label="", id=263):
 		self.w = None
 		self.d = None
- 		self.maxval = maxval
- 		self.curval = -1
 		self.d = GetNewDialog(id, -1)
 		self.w = self.d.GetDialogWindow()
 		self.label(label)
- 		self._update(0)
- 		self.d.AutoSizeDialog()
 		self.title(title)
 		self.w.ShowWindow()
 		self.d.DrawDialog()
--- 215,231 ----
 	screenbounds[2]-4, screenbounds[3]-4
 
! kControlProgressBarIndeterminateTag = 'inde'	# from Controls.py
! 
! 
 class ProgressBar:
! 	def __init__(self, title="Working...", maxval=0, label="", id=263):
 		self.w = None
 		self.d = None
 		self.d = GetNewDialog(id, -1)
 		self.w = self.d.GetDialogWindow()
 		self.label(label)
 		self.title(title)
+ 		self.set(0, maxval)
+ 		self.d.AutoSizeDialog()
 		self.w.ShowWindow()
 		self.d.DrawDialog()
***************
*** 249,270 ****
 			self._label = lf2cr(newstr[0])
 		text_h = self.d.GetDialogItemAsControl(2)
! 		SetDialogItemText(text_h, self._label)		
! 				
 	def _update(self, value):
 		maxval = self.maxval
! 		if maxval == 0:
! 			# XXXX Quick fix. Should probably display an unknown duration
! 			value = 0
! 			maxval = 1
! 		if maxval > 32767:
! 			value = int(value/(maxval/32767.0))
! 			maxval = 32767
! 		progbar = self.d.GetDialogItemAsControl(3)
! 		progbar.SetControlMaximum(maxval)
! 		progbar.SetControlValue(value)	
 		# Test for cancel button
- 		
 		ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 )
! 		if ready : 
 			what,msg,when,where,mod = ev
 			part = Win.FindWindow(where)[0]
--- 249,269 ----
 			self._label = lf2cr(newstr[0])
 		text_h = self.d.GetDialogItemAsControl(2)
! 		SetDialogItemText(text_h, self._label)
! 
 	def _update(self, value):
 		maxval = self.maxval
! 		if maxval == 0:		# an indeterminate bar
! 			Ctl.IdleControls(self.w)	# spin the barber pole
! 		else:				# a determinate bar
! 			if maxval > 32767:
! 				value = int(value/(maxval/32767.0))
! 				maxval = 32767
! 			progbar = self.d.GetDialogItemAsControl(3)
! 			progbar.SetControlMaximum(maxval)
! 			progbar.SetControlValue(value)	# set the bar length
! 
 		# Test for cancel button
 		ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 )
! 		if ready :
 			what,msg,when,where,mod = ev
 			part = Win.FindWindow(where)[0]
***************
*** 287,292 ****
 		if max != None:
 			self.maxval = max
! 		if value < 0: value = 0
! 		if value > self.maxval: value = self.maxval
 		self.curval = value
 		self._update(value)
--- 286,298 ----
 		if max != None:
 			self.maxval = max
! 			bar = self.d.GetDialogItemAsControl(3)
! 			if max <= 0:	# indeterminate bar
! 				bar.SetControlData(0,kControlProgressBarIndeterminateTag,'\x01')
! 			else:			# determinate bar
! 				bar.SetControlData(0,kControlProgressBarIndeterminateTag,'\x00')
! 		if value < 0:
! 			value = 0
! 		elif value > self.maxval:
! 			value = self.maxval
 		self.curval = value
 		self._update(value)
***************
*** 541,556 ****
 		else:
 			Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2))
! 	text = ( "Working Hard...", "Hardly Working..." , 
 			"So far, so good!", "Keep on truckin'" )
! 	bar = ProgressBar("Progress, progress...", 100)
 	try:
 		appsw = MacOS.SchedParams(1, 0)
! 		for i in range(100):
 			bar.set(i)
! 			time.sleep(0.1)
 			if i % 10 == 0:
 				bar.label(text[(i/10) % 4])
 		bar.label("Done.")
! 		time.sleep(0.3) 	# give'em a chance to see the done.
 	finally:
 		del bar
--- 547,566 ----
 		else:
 			Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2))
! 	text = ( "Working Hard...", "Hardly Working..." ,
 			"So far, so good!", "Keep on truckin'" )
! 	bar = ProgressBar("Progress, progress...", 0, label="Ramping up...")
 	try:
 		appsw = MacOS.SchedParams(1, 0)
! 		for i in xrange(20):
! 			bar.inc()
! 			time.sleep(0.05)
! 		bar.set(0,100)
! 		for i in xrange(100):
 			bar.set(i)
! 			time.sleep(0.05)
 			if i % 10 == 0:
 				bar.label(text[(i/10) % 4])
 		bar.label("Done.")
! 		time.sleep(1.0) 	# give'em a chance to see "Done."
 	finally:
 		del bar

AltStyle によって変換されたページ (->オリジナル) /