dabodemo Commit
Revision 322
Date: 2005-10-17 08:50:01 -0700 (Mon, 17 Oct 2005)
Author: ed
Changed:
U trunk/bubblet/BubbleBizobj.py
U trunk/bubblet/BubblePanel.py
U trunk/bubblet/BubbletForm.py
Log:
Fixed the annoying flicker. It was a combination of changes to the logic for
displaying selections (I'm using a draw object instead of BackColor), and
changes to dPemMixin that don't refresh an object in the color setters unless
the new color is different.
Diff:
Modified: trunk/bubblet/BubbleBizobj.py
===================================================================
--- trunk/bubblet/BubbleBizobj.py 2005-10-16 18:27:04 UTC (rev 321)
+++ trunk/bubblet/BubbleBizobj.py 2005-10-17 15:50:01 UTC (rev 322)
@@ -57,17 +57,16 @@
def newGame(self):
- for r in self.bubbles:
- for c in r:
- c.Selected = False
- c.setRandomColor(True)
+ for rr in self.bubbles:
+ for cc in rr:
+ cc.Selected = False
+ cc.setRandomColor(True)
self.Score = 0
self.GameOver = False
self.IsNewHighGame = False
def bubbleClick(self, bubble):
- r,c = bubble.row, bubble.col
ret = 0
if bubble.Selected:
ret = self.popBubbles()
@@ -83,12 +82,11 @@
def popBubbles(self):
ret = self.BubbleScore
self.Score += self.BubbleScore
- for r in self.bubbles:
- for c in r:
- if c.Selected:
- c.Color = None
- c.Selected = False
- c.repaint()
+ for rr in self.bubbles:
+ for cc in rr:
+ if cc.Selected:
+ cc.Color = None
+ cc.Selected = False
self.selCount = 0
self.shiftBubbles()
self.fillEmptyCols()
@@ -102,8 +100,8 @@
# Check if the lowest bubble is empty.
toFill = 0
- for c in range(cols):
- if self.bubbles[rows-1][c].Color is None:
+ for cc in range(cols):
+ if self.bubbles[rows-1][cc].Color is None:
toFill += 1
if toFill:
@@ -112,10 +110,10 @@
self.__callbackFunc = self.callbackShift
# Fill the columns
- for c in range(toFill):
+ for cc in range(toFill):
num = random.randrange(rows) + 1
- for i in range(rows-num, rows):
- bub = self.bubbles[i][c]
+ for ii in range(rows-num, rows):
+ bub = self.bubbles[ii][cc]
bub.Selected = False
bub.setRandomColor(True)
else:
@@ -132,25 +130,25 @@
self.__callbackFunc = None
rows = len(self.bubbles)
cols = len(self.bubbles[0])
- for c in range(cols):
+ for cc in range(cols):
gap = False
- for r in range(rows):
- if self.bubbles[r][c].Color is not None:
+ for rr in range(rows):
+ if self.bubbles[rr][cc].Color is not None:
gap = True
else:
if gap:
- for rAbove in range(r, 0, -1):
-
self.bubbles[rAbove][c].Color = self.bubbles[rAbove-1][c].Color
- self.bubbles[0][c].Color = None
+ for rAbove in range(rr, 0, -1):
+
self.bubbles[rAbove][cc].Color = self.bubbles[rAbove-1][cc].Color
+ self.bubbles[0][cc].Color = None
# Now shift columns to the right
- for r in range(rows):
+ for rr in range(rows):
gap = False
- for c in range(cols-1, 0, -1):
- currBub = self.bubbles[r][c]
+ for cc in range(cols-1, 0, -1):
+ currBub = self.bubbles[rr][cc]
if currBub.Color is None:
# See if there are any bubbles to the
left that are not empty
- for cLeft in range(c, -1, -1):
- leftBub = self.bubbles[r][cLeft]
+ for cLeft in range(cc, -1, -1):
+ leftBub =
self.bubbles[rr][cLeft]
if leftBub.Color is not None:
currBub.Color =
leftBub.Color
leftBub.Color = None
@@ -171,9 +169,9 @@
self.GameOver = True
rows = len(self.bubbles)
cols = len(self.bubbles[0])
- for r in range(rows-1, -1,-1):
- for c in range(cols-1, -1, -1):
- if self.hasMatchingNeighbor(self.bubbles[r][c]):
+ for rr in range(rows-1, -1,-1):
+ for cc in range(cols-1, -1, -1):
+ if
self.hasMatchingNeighbor(self.bubbles[rr][cc]):
self.GameOver = False
break
if not self.GameOver:
@@ -191,7 +189,7 @@
def hasMatchingNeighbor(self, bubble):
""" Need to try for matches above, below, left and right. """
- r, c = bubble.row, bubble.col
+ rr, cc = bubble.row, bubble.col
color = bubble.Color
if color is None:
return False
@@ -199,30 +197,30 @@
cols = len(self.bubbles[0])
# Above
- if r > 0:
+ if rr > 0:
try:
- bub = self.bubbles[r-1][c]
+ bub = self.bubbles[rr-1][cc]
if bub.Color == color:
return True
except: pass
# Below
- if r < rows:
+ if rr < rows:
try:
- bub = self.bubbles[r+1][c]
+ bub = self.bubbles[rr+1][cc]
if bub.Color == color:
return True
except: pass
# Left
- if c > 0:
+ if cc > 0:
try:
- bub = self.bubbles[r][c-1]
+ bub = self.bubbles[rr][cc-1]
if bub.Color == color:
return True
except: pass
# Right
- if c < cols:
+ if cc < cols:
try:
- bub = self.bubbles[r][c+1]
+ bub = self.bubbles[rr][cc+1]
if bub.Color == color:
return True
except: pass
@@ -238,39 +236,39 @@
return
bubble.Selected = True
hasMatch = False
- r, c = bubble.row, bubble.col
+ rr, cc = bubble.row, bubble.col
rows = len(self.bubbles)
cols = len(self.bubbles[0])
# We need to check the bubbles on top, bottom, left and right.
# Above
- if r > 0:
+ if rr > 0:
try:
- bub = self.bubbles[r-1][c]
+ bub = self.bubbles[rr-1][cc]
if bub.Color == color:
hasMatch = True
self.selectBubbles(bub)
except: pass
# Below
- if r < rows:
+ if rr < rows:
try:
- bub = self.bubbles[r+1][c]
+ bub = self.bubbles[rr+1][cc]
if bub.Color == color:
hasMatch = True
self.selectBubbles(bub)
except: pass
# Left
- if c > 0:
+ if cc > 0:
try:
- bub = self.bubbles[r][c-1]
+ bub = self.bubbles[rr][cc-1]
if bub.Color == color:
hasMatch = True
self.selectBubbles(bub)
except: pass
# Right
- if c < cols:
+ if cc < cols:
try:
- bub = self.bubbles[r][c+1]
+ bub = self.bubbles[rr][cc+1]
if bub.Color == color:
hasMatch = True
self.selectBubbles(bub)
@@ -283,9 +281,9 @@
def unselectBubbles(self):
- for r in self.bubbles:
- for c in r:
- c.Selected = False
+ for rr in self.bubbles:
+ for cc in rr:
+ cc.Selected = False
self.selCount = 0
self.Message = _("Bubble Points: 0")
Modified: trunk/bubblet/BubblePanel.py
===================================================================
--- trunk/bubblet/BubblePanel.py 2005-10-16 18:27:04 UTC (rev 321)
+++ trunk/bubblet/BubblePanel.py 2005-10-17 15:50:01 UTC (rev 322)
@@ -1,8 +1,13 @@
import dabo
+import dabo.dEvents as dEvents
import random
+
class BubblePanel(dabo.ui.dPanel):
def afterInit(self):
+ # Create a background that will change to indicate
+ # selected status.
+ self.back = self.drawRectangle(0,0,1,1, penWidth=0)
# Create a dummy circle, and store the reference
self.circle = self.drawCircle(0,0,1)
@@ -32,25 +37,33 @@
def onPaint(self, evt):
+ if self.Parent.noUpdate:
+ return
self.repaint(True)
def repaint(self, fromRepaint=False):
if fromRepaint:
- self.circle.AutoUpdate = False
+ self.circle.AutoUpdate = self.back.AutoUpdate = False
+ wd = self.Width
ht = self.Height
- wd = self.Width
+
+ self.back.Width, self.back.Height = wd, ht
+ if self.Selected:
+ self.back.FillColor = self.selectedBackColor
+ else:
+ self.back.FillColor = self.unselectedBackColor
pos = ( (wd/2), (ht/2) )
rad = (min(ht, wd) / 2)
self.circle.Xpos = int(wd/2)
self.circle.Ypos = int(ht/2)
self.circle.Radius = rad
self.circle.FillColor = self.Color
- self.circle.AutoUpdate = True
if self.Color:
self.circle.PenWidth = 1
else:
self.circle.PenWidth = 0
+ self.circle.AutoUpdate = self.back.AutoUpdate = True
else:
self._needRedraw = True
@@ -67,26 +80,20 @@
else:
self._color = color.lower()
- def _getParent(self):
- return self.GetParent()
-
def _getSelected(self):
return self._selected
def _setSelected(self, sel):
- if sel:
- self.BackColor = self.selectedBackColor
- else:
- self.BackColor = self.unselectedBackColor
+# if sel:
+# self.BackColor = self.selectedBackColor
+# else:
+# self.BackColor = self.unselectedBackColor
self._selected = sel
- self.Refresh()
+# self.Refresh()
Color = property(_getColor, _setColor, None,
"Color for this bubble (str or tuple)")
- Parent = property(_getParent, None, None,
- "Parent of the current object (obj)")
-
Selected = property(_getSelected, _setSelected, None,
"Selection Status (bool)")
Modified: trunk/bubblet/BubbletForm.py
===================================================================
--- trunk/bubblet/BubbletForm.py 2005-10-16 18:27:04 UTC (rev 321)
+++ trunk/bubblet/BubbletForm.py 2005-10-17 15:50:01 UTC (rev 322)
@@ -13,6 +13,8 @@
self.tmr = dabo.ui.dTimer(self, RegID="bubbleTimer")
self.timerFunc = None
self._score = 0
+ # Used to control unnecessary screen redraws
+ self.noUpdate = False
# Rows and columns
self.rows = 7
@@ -64,30 +66,10 @@
fm.append("&Statistics\tCtrl+T", bindfunc=self.onStats)
fm.append("&Reset Statistics\tCtrl+R",
bindfunc=self.onResetStats)
fm.append("&ScreenShot\tCtrl+S", bindfunc=self.saveScreenShot)
+
+ self.unbindEvent(dEvents.Paint)
- # def onSize(self, evt):
- # self._width, self._height =
self.GetClientSizeTuple()
- # # Make new off screen bitmap: this bitmap will
always have the
- # # current drawing in it, so it can be used to
save the image to
- # # a file, or whatever.
- # pass
- # #self._Buffer = wxEmptyBitmap(self._width,
self._height)
- # #self.UpdateDrawing()
-
- # def UpdateDrawing(self):
- # if USE_BUFFERED_DC:
- # dc = wxBufferedDC(wxClientDC(self),
self._Buffer)
- # self.Draw(dc)
- # else:
- # print "updating the drawing"
- # # update the buffer
- # dc = wxMemoryDC()
- # dc.SelectObject(self._Buffer)
- # self.Draw(dc)
- # # update the screen
- # wxClientDC(self).Blit(0, 0, self.Width,
self.Height, dc, 0, 0)
-
def saveScreenShot( self, evt ):
""" Completely experimental. Took this code from a message on
the wxPython list, and tried to get it to work, but didn't
succeed.
@@ -115,7 +97,7 @@
biz = self.Bizobj
if biz.GameOver:
return
-
+ self.noUpdate = True
pts = biz.bubbleClick(bubble)
if pts:
self.Score += pts
@@ -123,7 +105,10 @@
func = biz.getCallback()
if func:
dabo.ui.callAfter(func, self.updateBoard)
- self.StatusText = biz.Message
+# self.StatusText = biz.Message
+ self.noUpdate = False
+ self.repaint()
+
if biz.GameOver:
self.gameOverMsg()
@@ -136,7 +121,7 @@
self.tmr.stop()
if self.Bizobj.GameOver:
self.gameOverMsg()
- self.refresh()
+ self.repaint()
def gameOverMsg(self):
@@ -146,6 +131,7 @@
msg += "\n\nYour score was %s" % self.Score
dabo.ui.info( msg, "Game Over" )
+
def onNewGame(self, evt):
biz = self.Bizobj
if not biz.GameOver:
@@ -177,11 +163,14 @@
return
else:
biz.resetStats()
+
def repaint(self):
- self.raiseEvent(dEvents.Paint)
+ for obj in self.Children:
+ if isinstance(obj, BubblePanel):
+ obj.repaint(True)
-
+
def _getBizobj(self):
return self.PrimaryBizobj
@@ -199,3 +188,27 @@
Score = property(_getScore, _setScore, None,
"Current score of the game. (int)")
+
+
+ # def onSize(self, evt):
+ # self._width, self._height =
self.GetClientSizeTuple()
+ # # Make new off screen bitmap: this bitmap will
always have the
+ # # current drawing in it, so it can be used to
save the image to
+ # # a file, or whatever.
+ # pass
+ # #self._Buffer = wxEmptyBitmap(self._width,
self._height)
+ # #self.UpdateDrawing()
+
+ # def UpdateDrawing(self):
+ # if USE_BUFFERED_DC:
+ # dc = wxBufferedDC(wxClientDC(self),
self._Buffer)
+ # self.Draw(dc)
+ # else:
+ # print "updating the drawing"
+ # # update the buffer
+ # dc = wxMemoryDC()
+ # dc.SelectObject(self._Buffer)
+ # self.Draw(dc)
+ # # update the screen
+ # wxClientDC(self).Blit(0, 0, self.Width,
self.Height, dc, 0, 0)
+
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev