[PYTHONMAC-SIG] EasyDialogs.ProgressBar

Steven D. Majewski sdm7g@virginia.edu
18 Nov 96 20:07:46 +0000


One other minor bug to EasyDialogs.ProgressBar :
  Method  'set' doesn't update self.curval, so it's always = -1. 

I noticed this when I tried to add an 'inc' method so I wouldn't 
have to track the numbers myself. 

( Those changes and the previous fix are included below) 


Re: previous note about adding 'BringToFront' :
 
 I assume that problem is due to using what is supposed to be a Modal 
Dialog in a basically un-Modal way from Python.  ( Thus my comment 
that this seemed to be "A solution" but perhaps not "THE solution" ) 
After stumbling over that one, I'm actually surprised that it isn't a more
frequent problem ( or *IS* it? ) 


- Steve Majewski
<sdm7g@Virginia.EDU>


class ProgressBar:
	def __init__(self, label="Working...", maxval=100):
		self.label = label
		self.maxval = maxval
		self.curval = -1
		self.d = GetNewDialog(259, -1)
		tp, text_h, rect = self.d.GetDialogItem(2)
		SetDialogItemText(text_h, label)
		self._update(0)
		
	def _update(self, value):
		self.d.BringToFront()	# sdm7g -- this seems to cure Modal bus-error crash
		tp, h, bar_rect = self.d.GetDialogItem(3)
		Qd.SetPort(self.d)
		
		Qd.FrameRect(bar_rect)	# Draw outline
		
		inner_rect = Qd.InsetRect(bar_rect, 1, 1)
		l, t, r, b = inner_rect

		Qd.ForeColor(QuickDraw.blackColor)
		Qd.BackColor(QuickDraw.blackColor)
		Qd.PaintRect((l, t, int(l + (r-l)*value/self.maxval), b))	# Draw bar

		Qd.ForeColor(QuickDraw.whiteColor)
		Qd.BackColor(QuickDraw.whiteColor)
		Qd.PaintRect((int(l + (r-l)*value/self.maxval), t, r, b))	# Clear rest
				
		# Restore settings
		Qd.ForeColor(QuickDraw.blackColor)
		Qd.BackColor(QuickDraw.whiteColor)
		
		# Test for cancel button
		if ModalDialog(_ProgressBar_filterfunc) == 1:
			raise KeyboardInterrupt
			
	def set(self, value):
		if value < 0: value = 0
		if value > self.maxval: value = self.maxval
		self.curval = value			# sdm7g -- didn't update curval 
		self._update(value)

	def inc( self, *n ):			# sdm7g
		if not n: n = 1
		else: n = n[0] 
		self.set( self.curval + n )





=================
PYTHONMAC-SIG  - SIG on Python for the Apple Macintosh

send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
=================