From kde-commits Thu Oct 31 21:21:13 2013 From: Wolfgang Rohdewald Date: Thu, 31 Oct 2013 21:21:13 +0000 To: kde-commits Subject: [kajongg/sid] src: Change HandBoard.player and *Board.name to readonly properties Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=138325485206745 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 =3D False self.setRotation(boardRotation) self._lightSource =3D 'NW' - self.xWidth =3D 0 - self.xHeight =3D 0 - self.yWidth =3D 0 - self.yHeight =3D 0 + self.__xWidth =3D 0 + self.__xHeight =3D 0 + self.__yWidth =3D 0 + self.__yHeight =3D 0 self.__fixedWidth =3D width self.__fixedHeight =3D height self._tileset =3D None @@ -179,8 +179,8 @@ class Board(QGraphicsRectItem): self.tileset =3D tileset self.level =3D 0 = - # pylint: disable=3Dno-self-use - def name(self): + @property + def name(self): # pylint: disable=3Dno-self-use """default board name, used for debugging messages""" return 'board' = @@ -301,12 +301,12 @@ class Board(QGraphicsRectItem): tiles.append(tiles[0]) self.focusTile =3D tiles[tiles.index(self.focusTile)+1] = - def uiMeldWithTile(self, uiTile): + def _uiMeldWithTile(self, uiTile): # pylint: disable=3Dno-self-use """returns the UI Meld with uiTile. A Board does not know about me= lds, so default is to return a Meld with only uiTile""" return Meld(uiTile) = - def meldVariants(self, uiTile, lowerHalf): # pylint: disable=3Dunused-= argument + def meldVariants(self, uiTile, lowerHalf): # pylint: disable=3Dno-self= -use,unused-argument """all possible melds that could be meant by dragging/dropping uiT= ile""" return [Meld(uiTile)] = @@ -385,10 +385,10 @@ class Board(QGraphicsRectItem): def setPos(self, xWidth=3D0, xHeight=3D0, yWidth=3D0, yHeight=3D0): """sets the position in the parent item expressing the position in= tile face units. The X position is xWidth*facewidth + xHeight*faceheight, analog fo= r Y""" - self.xWidth =3D xWidth - self.xHeight =3D xHeight - self.yWidth =3D yWidth - self.yHeight =3D yHeight + self.__xWidth =3D xWidth + self.__xHeight =3D xHeight + self.__yWidth =3D yWidth + self.__yHeight =3D yHeight self.setGeometry() = def setRect(self, width, height): @@ -432,8 +432,8 @@ class Board(QGraphicsRectItem): offsets =3D (-self.tileset.shadowHeight() * 2, 0) else: offsets =3D self.tileset.shadowOffsets(self._lightSource, self= .sceneRotation()) - newX =3D self.xWidth*width+self.xHeight*height + offsets[0] - newY =3D self.yWidth*width+self.yHeight*height + offsets[1] + newX =3D self.__xWidth*width+self.__xHeight*height + offsets[0] + newY =3D self.__yWidth*width+self.__yHeight*height + offsets[1] QGraphicsRectItem.setPos(self, newX, newY) = @property @@ -640,8 +640,8 @@ class SelectorBoard(CourtBoard): uiTile.focusable =3D True self.focusTile =3D self.tilesByElement(Tile('c1'))[0] = - # pylint: disable=3Dno-self-use - def name(self): + @property + def name(self): # pylint: disable=3Dno-self-use """for debugging messages""" return 'selector' = @@ -905,8 +905,8 @@ class DiscardBoard(CourtBoard): self.__places =3D None self.lastDiscarded =3D None = - @staticmethod - def name(): # pylint: disable=3Darguments-differ + @property + def name(self): # pylint: disable=3Dno-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=3Dtoo-many-public-methods,too-many-instance-attribut= es def __init__(self, player): + assert player + self._player =3D player self.exposedMeldDistance =3D 0.15 self.concealedMeldDistance =3D 0.0 self.lowerY =3D 1.0 - self.player =3D player Board.__init__(self, 15.6, 2.0, Internal.field.tileset) self.isHandBoard =3D True self.tileDragEnabled =3D 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 c= ode 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 =3D '' return '%s(%s) %d: x/y/z=3D%.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=3DboardRota= tion) self.length =3D length = + @property def name(self): """name for debug messages""" game =3D Internal.field.game