[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kajongg/sid] src: Change HandBoard.player and *Board.name to readonly properties
From: Wolfgang Rohdewald <wolfgang () rohdewald ! de>
Date: 2013-10-31 21:21:13
Message-ID: E1Vbzg1-0002lj-RE () scm ! kde ! org
[Download RAW message or body]
Git commit c2a81218cadb2abaae8393bf0caf78f8d46113ce by Wolfgang Rohdewald.
Committed on 31/10/2013 at 15:02.
Pushed by wrohdewald into branch 'sid'.
Change HandBoard.player and *Board.name to readonly properties
and make a few things non-public
M +18 -18 src/board.py
M +9 -2 src/handboard.py
M +1 -1 src/uitile.py
M +1 -0 src/uiwall.py
http://commits.kde.org/kajongg/c2a81218cadb2abaae8393bf0caf78f8d46113ce
diff --git a/src/board.py b/src/board.py
index f0ad453..7943c48 100644
--- a/src/board.py
+++ b/src/board.py
@@ -168,10 +168,10 @@ class Board(QGraphicsRectItem):
self.tileDragEnabled = False
self.setRotation(boardRotation)
self._lightSource = 'NW'
- self.xWidth = 0
- self.xHeight = 0
- self.yWidth = 0
- self.yHeight = 0
+ self.__xWidth = 0
+ self.__xHeight = 0
+ self.__yWidth = 0
+ self.__yHeight = 0
self.__fixedWidth = width
self.__fixedHeight = height
self._tileset = None
@@ -179,8 +179,8 @@ class Board(QGraphicsRectItem):
self.tileset = tileset
self.level = 0
- # pylint: disable=no-self-use
- def name(self):
+ @property
+ def name(self): # pylint: disable=no-self-use
"""default board name, used for debugging messages"""
return 'board'
@@ -301,12 +301,12 @@ class Board(QGraphicsRectItem):
tiles.append(tiles[0])
self.focusTile = tiles[tiles.index(self.focusTile)+1]
- def uiMeldWithTile(self, uiTile):
+ def _uiMeldWithTile(self, uiTile): # pylint: disable=no-self-use
"""returns the UI Meld with uiTile. A Board does not know about melds,
so default is to return a Meld with only uiTile"""
return Meld(uiTile)
- def meldVariants(self, uiTile, lowerHalf): # pylint: disable=unused-argument
+ def meldVariants(self, uiTile, lowerHalf): # pylint: disable=no-self-use,unused-argument
"""all possible melds that could be meant by dragging/dropping uiTile"""
return [Meld(uiTile)]
@@ -385,10 +385,10 @@ class Board(QGraphicsRectItem):
def setPos(self, xWidth=0, xHeight=0, yWidth=0, yHeight=0):
"""sets the position in the parent item expressing the position in tile face units.
The X position is xWidth*facewidth + xHeight*faceheight, analog for Y"""
- self.xWidth = xWidth
- self.xHeight = xHeight
- self.yWidth = yWidth
- self.yHeight = yHeight
+ self.__xWidth = xWidth
+ self.__xHeight = xHeight
+ self.__yWidth = yWidth
+ self.__yHeight = yHeight
self.setGeometry()
def setRect(self, width, height):
@@ -432,8 +432,8 @@ class Board(QGraphicsRectItem):
offsets = (-self.tileset.shadowHeight() * 2, 0)
else:
offsets = self.tileset.shadowOffsets(self._lightSource, self.sceneRotation())
- newX = self.xWidth*width+self.xHeight*height + offsets[0]
- newY = self.yWidth*width+self.yHeight*height + offsets[1]
+ newX = self.__xWidth*width+self.__xHeight*height + offsets[0]
+ newY = self.__yWidth*width+self.__yHeight*height + offsets[1]
QGraphicsRectItem.setPos(self, newX, newY)
@property
@@ -640,8 +640,8 @@ class SelectorBoard(CourtBoard):
uiTile.focusable = True
self.focusTile = self.tilesByElement(Tile('c1'))[0]
- # pylint: disable=no-self-use
- def name(self):
+ @property
+ def name(self): # pylint: disable=no-self-use
"""for debugging messages"""
return 'selector'
@@ -905,8 +905,8 @@ class DiscardBoard(CourtBoard):
self.__places = None
self.lastDiscarded = None
- @staticmethod
- def name(): # pylint: disable=arguments-differ
+ @property
+ def name(self): # pylint: disable=no-self-use
"""to be used in debug output"""
return "discardBoard"
diff --git a/src/handboard.py b/src/handboard.py
index b6a6994..464f8e9 100644
--- a/src/handboard.py
+++ b/src/handboard.py
@@ -74,10 +74,11 @@ class HandBoard(Board):
"""a board showing the tiles a player holds"""
# pylint: disable=too-many-public-methods,too-many-instance-attributes
def __init__(self, player):
+ assert player
+ self._player = player
self.exposedMeldDistance = 0.15
self.concealedMeldDistance = 0.0
self.lowerY = 1.0
- self.player = player
Board.__init__(self, 15.6, 2.0, Internal.field.tileset)
self.isHandBoard = True
self.tileDragEnabled = False
@@ -95,12 +96,18 @@ class HandBoard(Board):
self.setScale(scale)
@property
+ def player(self):
+ """player is readonly and never None"""
+ return self._player
+
+ @property
def showShadows(self):
"""the active value"""
return self._showShadows
# this is ordered such that pylint does not complain about identical code in board.py
+ @property
def name(self):
"""for debugging messages"""
return self.player.name
@@ -309,7 +316,7 @@ class ScoringHandBoard(HandBoard):
result.append(meld2)
return result
- def uiMeldWithTile(self, uiTile):
+ def _uiMeldWithTile(self, uiTile):
"""returns the meld with uiTile"""
for myMeld in self.uiMelds:
if uiTile in myMeld:
diff --git a/src/uitile.py b/src/uitile.py
index 96ce58d..5eebbcb 100644
--- a/src/uitile.py
+++ b/src/uitile.py
@@ -414,7 +414,7 @@ class UITile(QGraphicsObject):
size = ''
return '%s(%s) %d: x/y/z=%.1f(%.1f)/%.1f(%.1f)/%.2f%s%s%s%s' % \
(self.tile,
- self.board.name() if self.board else 'None', id(self) % 10000,
+ self.board.name if self.board else 'None', id(self) % 10000,
self.xoffset, self.x(), self.yoffset,
self.y(), self.zValue(), size, rotation, scale, level)
diff --git a/src/uiwall.py b/src/uiwall.py
index 4d6f3c6..e637bb6 100644
--- a/src/uiwall.py
+++ b/src/uiwall.py
@@ -35,6 +35,7 @@ class UIWallSide(Board):
Board.__init__(self, length, 1, tileset, boardRotation=boardRotation)
self.length = length
+ @property
def name(self):
"""name for debug messages"""
game = Internal.field.game
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic