dabo Commit
Revision 3560
Date: 2007-10-24 08:42:05 -0700 (Wed, 24 Oct 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3560
Changed:
U trunk/demo/DaboDemo.cdxml
A trunk/demo/samples/__init__.py
A trunk/demo/samples/bubblet.py
A trunk/demo/samples/games/
A trunk/demo/samples/games/__init__.py
A trunk/demo/samples/games/bubblet/
A trunk/demo/samples/games/bubblet/BubbleBizobj.py
A trunk/demo/samples/games/bubblet/BubblePanel.py
A trunk/demo/samples/games/bubblet/BubbletForm.py
A trunk/demo/samples/games/bubblet/StatsForm.py
A trunk/demo/samples/games/bubblet/__init__.py
Log:
Added a directory for games. Integrated the Bubblet game into DaboDemo.
Diff:
Modified: trunk/demo/DaboDemo.cdxml
===================================================================
--- trunk/demo/DaboDemo.cdxml 2007-10-24 14:32:02 UTC (rev 3559)
+++ trunk/demo/DaboDemo.cdxml 2007-10-24 15:42:05 UTC (rev 3560)
@@ -67,6 +67,8 @@
exFiles = glob.glob(os.path.join(pth, "*.py"))
for f in exFiles:
justFname = os.path.splitext(os.path.split(f)[1])[0]
+ if justFname.startswith("_"):
+ continue
exec("import %s as exx" % justFname)
maincat, subcat = exx.category.split(".")
if maincat not in demos:
Added: trunk/demo/samples/__init__.py
===================================================================
--- trunk/demo/samples/__init__.py (rev 0)
+++ trunk/demo/samples/__init__.py 2007-10-24 15:42:05 UTC (rev 3560)
@@ -0,0 +1 @@
+import games
Added: trunk/demo/samples/bubblet.py
===================================================================
--- trunk/demo/samples/bubblet.py (rev 0)
+++ trunk/demo/samples/bubblet.py 2007-10-24 15:42:05 UTC (rev 3560)
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+import datetime
+import dabo
+dabo.ui.loadUI("wx")
+import dabo.dEvents as dEvents
+from dabo.dLocalize import _
+from samples.games.bubblet.BubbletForm import BubbletForm
+
+
+class TestPanel(dabo.ui.dPanel):
+ def afterInit(self):
+ sz = self.Sizer = dabo.ui.dSizer("v")
+ sz.appendSpacer(40)
+
+ lbl = dabo.ui.dLabel(self, Caption="Bubblet is a fun and
somewhat addictive game.\nFor instructions, please see the Overview tab.")
+ sz.append(lbl, halign="center")
+ sz.appendSpacer(20)
+ btn = dabo.ui.dButton(self, Caption="Run the Bubblet Game",
+ OnHit=self.runGame)
+ sz.append(btn, halign="center")
+
+
+ def runGame(self, evt):
+ frm = BubbletForm(self.Form, Size=(400,300), Centered=True)
+ frm.show()
+
+
+
+category = "Games.Bubblet"
+
+overview = """
+<h3>About Bubblet</h3>
+<p><b>Bubblet</b> is a fun and somewhat addictive game. There are columns
+of bubbles of 4 different colors. If there are at least two adjacent
+bubbles of the same color, clicking on one of them will select the
+group. Clicking on any of the selected bubbles will pop them! When the
+bubbles pop, any bubbles above them will drop down to fill the empty
+spaces. The bubbles will also shift to the right to fill any open
+spaces. </p>
+
+<p> When a column of the board has been emptied, a new column with a
+variable number of bubbles of random colors will replace it. It will
+appear on the left of the board at first, and then immediately shift to
+the right as necessary. I'm still working on the visual effects; I don't
+have as much control of the appearance of the new column as I would
+like. </p>
+
+
+<h3>Scoring</h3>
+<p>You get points for popping bubbles. The number of
+points depends on the number of bubbles popped at once; bigger groups
+score a lot more points! When you select a group of contiguous bubbles,
+the bottom of the screen will show you the points you will receive if
+you pop that group. If you're interested, the formula for bubble points
+is: <b>n * (n-1)</b>, where 'n' is the total number of bubbles in the
+selected group. </p>
+
+
+<h3>Strategy</h3>
+<p>Since larger groups of bubbles score more points
+than smaller groups, you should try to get as many bubbles of the same
+color together as you can. Keep in mind that while a group of 10 bubbles
+would score 90 points, two groups of 5 bubbles each would only score 40
+points. And 5 groups of 2 bubbles is only worth 10 points! So even
+though you're popping the same number of bubbles, you'll do much better
+by trying to pop as many at once. </p>
+
+<p>The other thing to keep in mind is that to get really high scores,
+you need a fresh supply of bubbles! The only way to do that is to
+completely pop a column, so try to arrange the bubbles so that a column
+is all the same color. If you have two bubbles next to each other
+horizontally, and they are the only bubbles in their columns, you'll get
+two fresh columns of bubbles when you pop them. </p>
+
+
+<h3>End of Game</h3>
+<p>When there are no longer any adjacent bubbles
+of the same color, the game is over. Your score will be added to the
+statistics, which keeps track of your high game, as well as the total
+number of games you've played and your average score for those games.</p>
+"""
Added: trunk/demo/samples/games/__init__.py
===================================================================
--- trunk/demo/samples/games/__init__.py (rev 0)
+++ trunk/demo/samples/games/__init__.py 2007-10-24 15:42:05 UTC (rev
3560)
@@ -0,0 +1 @@
+import bubblet
Added: trunk/demo/samples/games/bubblet/BubbleBizobj.py
===================================================================
--- trunk/demo/samples/games/bubblet/BubbleBizobj.py
(rev 0)
+++ trunk/demo/samples/games/bubblet/BubbleBizobj.py 2007-10-24 15:42:05 UTC
(rev 3560)
@@ -0,0 +1,353 @@
+# -*- coding: utf-8 -*-
+import dabo
+import dabo.biz as biz
+from dabo.dLocalize import _
+import random
+import time
+import os
+
+class BubbleBizobj(biz.dBizobj):
+ def beforeInit(self):
+ #self.DataSource = "Bubble"
+ self.bubbles = []
+ self.selCount = 0
+ self.__score = 0
+ self.__message = ""
+ self.__callbackFunc = None
+ self.__gameOver = False
+ self.__isNewHighGame = False
+
+
+ def initProperties(self):
+ self.BasePrefKey = dabo.dAppRef.BasePrefKey
+
+
+ def newGame(self):
+ 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):
+ ret = 0
+ if bubble.Selected:
+ ret = self.popBubbles()
+ self.unselectBubbles()
+ self.Message = _("You scored %s points!" % ret)
+ else:
+ self.unselectBubbles()
+ self.selectBubbles(bubble)
+ self.Message = _("Bubble Points: ") + str(
self.BubbleScore )
+ return ret
+
+
+ def popBubbles(self):
+ ret = self.BubbleScore
+ self.Score += self.BubbleScore
+ 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()
+ return ret
+
+
+ def fillEmptyCols(self):
+ isEmpty = True
+ rows = len(self.bubbles)
+ cols = len(self.bubbles[0])
+
+ # Check if the lowest bubble is empty.
+ toFill = 0
+ for cc in range(cols):
+ if self.bubbles[rows-1][cc].Color is None:
+ toFill += 1
+
+ if toFill:
+ # Set the callback, so that the calling object knows
that further
+ # work is left
+ self.__callbackFunc = self.callbackShift
+
+ # Fill the columns
+ for cc in range(toFill):
+ num = random.randrange(rows) + 1
+ for ii in range(rows-num, rows):
+ bub = self.bubbles[ii][cc]
+ bub.Selected = False
+ bub.setRandomColor(True)
+ else:
+ # See if there are any moves remaining.
+ self.checkGameOver()
+
+
+ def shiftBubbles(self):
+ """ This can vary, depending on the type of Bubblet game. For
now,
+ stick with the standard "megashift", where both rows and columns
+ are collapsed.
+ """
+ # First, clear the callback
+ self.__callbackFunc = None
+ rows = len(self.bubbles)
+ cols = len(self.bubbles[0])
+ for cc in range(cols):
+ gap = False
+ for rr in range(rows):
+ if self.bubbles[rr][cc].Color is not None:
+ gap = True
+ else:
+ if gap:
+ 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 rr in range(rows):
+ gap = False
+ 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(cc, -1, -1):
+ leftBub =
self.bubbles[rr][cLeft]
+ if leftBub.Color is not None:
+ currBub.Color =
leftBub.Color
+ leftBub.Color = None
+ break
+
+
+ def callbackShift(self, recallFunc=None):
+ self.shiftBubbles()
+ self.checkGameOver()
+ if recallFunc:
+ recallFunc()
+
+
+ def checkGameOver(self):
+ """ Determine if there are any more moves possible. IOW, find
at least
+ one bubble with a matching neighbor.
+ """
+ self.GameOver = True
+ rows = len(self.bubbles)
+ cols = len(self.bubbles[0])
+ 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:
+ break
+ if self.GameOver:
+ self.NumberOfGames += 1
+ self.TotalPoints += self.Score
+ if self.Score > self.HighGame:
+ self.HighGame = self.Score
+ self.IsNewHighGame = True
+ # Set the message
+ self.Message = _("Game Over!")
+ return self.GameOver
+
+
+ def hasMatchingNeighbor(self, bubble):
+ """ Need to try for matches above, below, left and right. """
+ rr, cc = bubble.row, bubble.col
+ color = bubble.Color
+ if color is None:
+ return False
+ rows = len(self.bubbles)
+ cols = len(self.bubbles[0])
+
+ # Above
+ if rr > 0:
+ try:
+ bub = self.bubbles[rr-1][cc]
+ if bub.Color == color:
+ return True
+ except: pass
+ # Below
+ if rr < rows:
+ try:
+ bub = self.bubbles[rr+1][cc]
+ if bub.Color == color:
+ return True
+ except: pass
+ # Left
+ if cc > 0:
+ try:
+ bub = self.bubbles[rr][cc-1]
+ if bub.Color == color:
+ return True
+ except: pass
+ # Right
+ if cc < cols:
+ try:
+ bub = self.bubbles[rr][cc+1]
+ if bub.Color == color:
+ return True
+ except: pass
+ return False
+
+
+ def selectBubbles(self, bubble):
+ if bubble.Selected:
+ return
+ color = bubble.Color
+ if color is None:
+ # They clicked on an empty space
+ return
+ bubble.Selected = True
+ hasMatch = False
+ 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 rr > 0:
+ try:
+ bub = self.bubbles[rr-1][cc]
+ if bub.Color == color:
+ hasMatch = True
+ self.selectBubbles(bub)
+ except: pass
+ # Below
+ if rr < rows:
+ try:
+ bub = self.bubbles[rr+1][cc]
+ if bub.Color == color:
+ hasMatch = True
+ self.selectBubbles(bub)
+ except: pass
+ # Left
+ if cc > 0:
+ try:
+ bub = self.bubbles[rr][cc-1]
+ if bub.Color == color:
+ hasMatch = True
+ self.selectBubbles(bub)
+ except: pass
+ # Right
+ if cc < cols:
+ try:
+ bub = self.bubbles[rr][cc+1]
+ if bub.Color == color:
+ hasMatch = True
+ self.selectBubbles(bub)
+ except: pass
+
+ if not hasMatch:
+ bubble.Selected = False
+ else:
+ self.selCount += 1
+
+
+ def unselectBubbles(self):
+ for rr in self.bubbles:
+ for cc in rr:
+ cc.Selected = False
+ self.selCount = 0
+ self.Message = _("Bubble Points: 0")
+
+
+ def resetStats(self):
+ self.NumberOfGames = 0
+ self.TotalPoints = 0
+ self.HighGame = 0
+
+
+ def getCallback(self):
+ return self.__callbackFunc
+
+ # Begin property definitions
+ def _getBubbleScore(self):
+ return (self.selCount * (self.selCount-1))
+
+
+ def _getGameOver(self):
+ return self.__gameOver
+
+ def _setGameOver(self, val):
+ self.__gameOver = val
+
+
+ def _getHighGame(self):
+ ret = self.PreferenceManager.highgame
+ if not isinstance(ret, int):
+ ret = 0
+ return ret
+
+ def _setHighGame(self, val):
+ self.PreferenceManager.highgame = val
+
+
+ def _getIsNewHighGame(self):
+ return self.__isNewHighGame
+
+ def _setIsNewHighGame(self, val):
+ self.__isNewHighGame = val
+
+
+ def _getMessage(self):
+ return self.__message
+
+ def _setMessage(self, msg):
+ self.__message = msg
+
+
+ def _getGames(self):
+ ret = self.PreferenceManager.numbergames
+ if not isinstance(ret, int):
+ ret = 0
+ return ret
+
+ def _setGames(self, val):
+ self.PreferenceManager.numbergames = val
+
+
+ def _getScore(self):
+ return self.__score
+
+ def _setScore(self, val):
+ self.__score = val
+
+
+ def _getTotalPoints(self):
+ ret = self.PreferenceManager.totalpoints
+ if not isinstance(ret, int):
+ ret = 0
+ return ret
+
+ def _setTotalPoints(self, val):
+ self.PreferenceManager.totalpoints = val
+
+
+ BubbleScore = property(_getBubbleScore, None, None,
+ _("Current score of bubbles"))
+
+ GameOver = property(_getGameOver, _setGameOver, None,
+ _("Status of the game"))
+
+ HighGame = property(_getHighGame, _setHighGame, None,
+ _("High score"))
+
+ IsNewHighGame = property(_getIsNewHighGame, _setIsNewHighGame, None,
+ _("Is the current game the new high game?"))
+
+ Message = property(_getMessage, _setMessage, None,
+ _("Status Message"))
+
+ NumberOfGames = property(_getGames, _setGames, None,
+ _("Number of games played"))
+
+ Score = property(_getScore, _setScore, None,
+ _("Current score of the game"))
+
+ TotalPoints = property(_getTotalPoints, _setTotalPoints, None,
+ _("Total number of points recorded"))
+
+
Added: trunk/demo/samples/games/bubblet/BubblePanel.py
===================================================================
--- trunk/demo/samples/games/bubblet/BubblePanel.py
(rev 0)
+++ trunk/demo/samples/games/bubblet/BubblePanel.py 2007-10-24 15:42:05 UTC
(rev 3560)
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+import dabo
+import dabo.dEvents as dEvents
+from dabo.dLocalize import _
+import random
+
+
+class BubblePanel(dabo.ui.dPanel):
+ def afterInit(self):
+ self.Buffered = True
+ # 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)
+
+ self._selected = False
+ self._colors = ["blue", "green", "red", "yellow", "purple"]
+ self._color = self.randColor()
+
+ if self.Application.Platform == "Win":
+ self.selectedBackColor = (192,192,255)
+ else:
+ self.selectedBackColor = (128,128,192)
+ self.unselectedBackColor = (255,255,255)
+ self.row = -1
+ self.col = -1
+ self.onResize(None)
+ self.update()
+
+
+ def randColor(self):
+ return random.choice(self._colors)
+
+
+ def setRandomColor(self, repaint=False):
+ self.Color = self.randColor()
+ if repaint:
+ self.update()
+
+
+ def onResize(self, evt):
+ self.circle.AutoUpdate = self.back.AutoUpdate = False
+ wd = self.Width
+ ht = self.Height
+ self.back.Width, self.back.Height = wd, ht
+ 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.AutoUpdate = self.back.AutoUpdate = True
+ self.update()
+
+
+ def update(self, evt=None):
+ self.circle.AutoUpdate = self.back.AutoUpdate = False
+ self.circle.FillColor = self.Color
+ if self.Color:
+ self.circle.PenWidth = 1
+ else:
+ self.circle.PenWidth = 0
+ if self.Selected:
+ self.back.FillColor = self.selectedBackColor
+ else:
+ self.back.FillColor = self.unselectedBackColor
+ self.circle.AutoUpdate = self.back.AutoUpdate = True
+ super(BubblePanel, self).update()
+
+
+ def onMouseLeftClick(self, evt):
+ self.Parent.bubbleClick(self)
+
+
+ def _getColor(self):
+ return self._color
+
+ def _setColor(self, color):
+ if color is None:
+ self._color = None
+ else:
+ self._color = color.lower()
+
+
+ def _getSelected(self):
+ return self._selected
+
+ def _setSelected(self, sel):
+ self._selected = sel
+
+
+ Color = property(_getColor, _setColor, None,
+ _("Color for this bubble (str or tuple)"))
+
+ Selected = property(_getSelected, _setSelected, None,
+ _("Selection Status (bool)"))
+
Added: trunk/demo/samples/games/bubblet/BubbletForm.py
===================================================================
--- trunk/demo/samples/games/bubblet/BubbletForm.py
(rev 0)
+++ trunk/demo/samples/games/bubblet/BubbletForm.py 2007-10-24 15:42:05 UTC
(rev 3560)
@@ -0,0 +1,182 @@
+# -*- coding: utf-8 -*-
+import dabo
+dabo.ui.loadUI("wx")
+dui = dabo.ui
+import dabo.dEvents as dEvents
+from dabo.dLocalize import _
+from BubblePanel import BubblePanel
+from BubbleBizobj import BubbleBizobj
+from StatsForm import StatsForm
+import time
+
+
+class BubbletForm(dabo.ui.dForm):
+ def afterInit(self):
+ self.tmr = dabo.ui.dTimer()
+ self.tmr.bindEvent(dEvents.Hit, self.onTimer)
+ self._score = 0
+ # Used to control unnecessary screen redraws
+ self.noUpdate = False
+
+ # Rows and columns
+ self.rows = 7
+ self.columns = 10
+ bubbles = [ [] for r in range(self.rows)]
+
+ vsz = dui.dSizer("v")
+ gsz = dui.dGridSizer(MaxCols=self.columns)
+
+ for rr in range(self.rows):
+ for cc in range(self.columns):
+ pn = BubblePanel(self)
+ pn.row = rr
+ pn.col = cc
+ #pn.ToolTipText = "Row %s, Col %s" % (rr,cc)
+ bubbles[rr].append(pn)
+ gsz.append(pn, "x")
+ # Set the grid sizer to grow
+ gsz.setColExpand(True, "all")
+ gsz.setRowExpand(True, "all")
+ vsz.append1x(gsz)
+
+ # Add the score
+ sp = self.scorePanel = dabo.ui.dPanel(self)
+ sp.Sizer = hsz = dui.dSizer("h")
+ label = dabo.ui.dLabel(sp, Caption=_("Score:"), FontSize=12)
+ hsz.append1x(label, halign="right")
+ self.scoreLabel = dabo.ui.dLabel(sp, FontSize=14, FontBold=True)
+ hsz.append1x(self.scoreLabel)
+ vsz.append(sp, 0, "x")
+
+ # This should set the label, too
+ self.Score = 0
+
+ self.Sizer = vsz
+ self.layout()
+
+ biz = BubbleBizobj(None)
+ biz.bubbles = bubbles
+ biz.callbackFunc = self.update
+ self.addBizobj(biz)
+
+ self.Caption = "Bubblet"
+
+ # Add the menu items
+ mb = self.MenuBar
+ fm = mb.getMenu(_("File"))
+ quitPos = fm.getItemIndex(_("Quit"))
+ if quitPos is None:
+ # Win/Lin
+ quitPos = fm.getItemIndex(_("Exit"))
+ if quitPos is None:
+ quitPos = len(fm.Children)
+ fm.insert(quitPos, _("&ScreenShot"), HotKey="Ctrl+S",
OnHit=self.saveScreenShot)
+ fm.insert(quitPos, _("&Reset Statistics"), HotKey="Ctrl+R",
OnHit=self.onResetStats)
+ fm.insert(quitPos, _("&Statistics"), HotKey="Ctrl+T",
OnHit=self.onStats)
+ fm.insertSeparator(0)
+ fm.insert(0, _("&New Game"), HotKey="Ctrl+N",
OnHit=self.onNewGame)
+
+ self.unbindEvent(dEvents.Paint)
+
+
+ def saveScreenShot(self, evt):
+ """Saves a screenshot of the current board."""
+ dabo.ui.saveScreenShot(self)
+
+
+ def bubbleClick(self, bubble):
+ biz = self.Bizobj
+ if biz.GameOver:
+ return
+ self.noUpdate = True
+ pts = biz.bubbleClick(bubble)
+ if pts:
+ self.Score += pts
+
+ func = biz.getCallback()
+ if func:
+ dabo.ui.callAfter(func, self.updateBoard)
+ self.StatusText = biz.Message
+ self.noUpdate = False
+ self.update()
+
+ if biz.GameOver:
+ dabo.ui.callAfterInterval(500, self.gameOverMsg)
+
+
+ def updateBoard(self):
+ self.tmr.start(100)
+
+
+ def onTimer(self, evt):
+ self.tmr.stop()
+ self.update()
+ if self.Bizobj.GameOver:
+ dabo.ui.callAfterInterval(500, self.gameOverMsg)
+
+
+ def gameOverMsg(self):
+ msg = _("Game Over!")
+ if self.Bizobj.IsNewHighGame:
+ msg = _("New High Game!!")
+ 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:
+ if not dabo.ui.areYouSure(
+ message = _("Are you sure you want to
end this game?"),
+ title = _("Game Not Over"),
+ defaultNo = True, cancelButton = False):
+ return
+ biz.newGame()
+ self.Score = 0
+ self.update()
+
+
+ def onStats(self, evt):
+ biz = self.Bizobj
+ num = biz.NumberOfGames
+ pts = biz.TotalPoints
+ high = biz.HighGame
+ statsForm = StatsForm(self, Games=num, Points=pts,
HighGame=high)
+ statsForm.show()
+
+
+ def onResetStats(self, evt):
+ biz = self.Bizobj
+ if biz.NumberOfGames > 0:
+ if not dabo.ui.areYouSure(
+ message = _("Are you sure you want to
reset your statistics?"),
+ title = _("Reset Statistics"),
+ defaultNo = False, cancelButton =
False):
+ return
+ else:
+ biz.resetStats()
+
+
+# def repaint(self):
+# for obj in self.Children:
+# if isinstance(obj, BubblePanel):
+# obj.repaint(True)
+
+
+ def _getBizobj(self):
+ return self.PrimaryBizobj
+
+ def _getScore(self):
+ return self._score
+
+ def _setScore(self, score):
+ if self._score != score:
+ self._score = score
+ self.scoreLabel.Caption = str(score)
+
+ Bizobj = property(_getBizobj, None, None,
+ _("Reference to the form's bizobj"))
+
+ Score = property(_getScore, _setScore, None,
+ _("Current score of the game. (int)"))
+
Added: trunk/demo/samples/games/bubblet/StatsForm.py
===================================================================
--- trunk/demo/samples/games/bubblet/StatsForm.py
(rev 0)
+++ trunk/demo/samples/games/bubblet/StatsForm.py 2007-10-24 15:42:05 UTC
(rev 3560)
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+import dabo
+dabo.ui.loadUI("wx")
+from dabo.dLocalize import _
+
+class StatsForm(dabo.ui.dDialog):
+ def beforeInit(self):
+ self._games = 0
+ self._highGame = 0
+ self._points = 0
+
+ def addControls(self):
+ self.Caption = "Bubblet Statistics"
+ self.Centered = True
+ self.Sizer.DefaultBorder = 20
+ self.Sizer.DefaultBorderAll = True
+ sz = dabo.ui.dGridSizer(MaxCols=2, VGap=8, HGap=4)
+ self.Sizer.append1x(sz)
+
+ lb = dabo.ui.dLabel(self, Caption="Number of Games:",
+ FontSize=16, ForeColor=(0,0,128))
+ sz.append(lb, halign="right")
+ lb = dabo.ui.dLabel(self, Caption=str(self.Games), FontSize=16)
+ sz.append(lb, halign="left")
+
+ lb = dabo.ui.dLabel(self, Caption="Average:",
+ FontSize=16, ForeColor = (0,0,128))
+ sz.append(lb, halign="right")
+ if self.Games > 0:
+ avg = str( round( (float(self.Points) / self.Games), 4)
)
+ else:
+ avg = 0
+ lb = dabo.ui.dLabel(self, Caption=str(avg), FontSize=16)
+ sz.append(lb, halign="left")
+
+ lb = dabo.ui.dLabel(self, Caption="High Game:",
+ FontSize=16, ForeColor=(0,0,128))
+ sz.append(lb, halign="right")
+ lb = dabo.ui.dLabel(self, Caption=str(self.HighGame),
FontSize=16)
+ sz.append(lb, halign="left")
+
+ # OK, that does it for the display fields. Now add an OK button
+ btn = dabo.ui.dButton(self, Caption="OK", RegID="btnOK",
+ DefaultButton=True)
+ # Add a spacer
+ self.Sizer.appendSpacer(10)
+ # Add the button
+ self.Sizer.append(btn, halign="right")
+
+ self.layout()
+
+
+ def onHit_btnOK(self, evt):
+ self.release()
+
+
+ def _getGames(self):
+ return self._games
+
+ def _setGames(self, val):
+ self._games = val
+
+ def _getHighGame(self):
+ return self._highGame
+
+ def _setHighGame(self, val):
+ self._highGame = val
+
+ def _getPoints(self):
+ return self._points
+
+ def _setPoints(self, val):
+ self._points = val
+
+
+ Games = property(_getGames, _setGames, None,
+ _("Number of games played (int)"))
+
+ HighGame = property(_getHighGame, _setHighGame, None,
+ _("High score (int)"))
+
+ Points = property(_getPoints, _setPoints, None,
+ _("Total points scored (int)"))
+
Added: trunk/demo/samples/games/bubblet/__init__.py
===================================================================
--- trunk/demo/samples/games/bubblet/__init__.py
(rev 0)
+++ trunk/demo/samples/games/bubblet/__init__.py 2007-10-24 15:42:05 UTC
(rev 3560)
@@ -0,0 +1,4 @@
+from BubbleBizobj import BubbleBizobj
+from BubblePanel import BubblePanel
+from BubbletForm import BubbletForm
+from StatsForm import StatsForm
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]