-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromotionDialog.py
More file actions
57 lines (41 loc) · 1.83 KB
/
PromotionDialog.py
File metadata and controls
57 lines (41 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from PyQt5 import QtWidgets, QtCore, QtGui
import chess
from config import CELL_SIZE, P_DIR, P_EXT, resourcePath
import uiFiles.PromotionDialogUi as PromotionDialogUi
class PromotionDialog(QtWidgets.QDialog,
PromotionDialogUi.Ui_promotionDialog):
def __init__(self, parent=None, piecesColor=chess.WHITE):
super().__init__(parent)
self.piecesColor = piecesColor
self.promotion = None
self.setupUi(self)
self.initUi()
def initUi(self):
iconSize = QtCore.QSize(CELL_SIZE + 10, CELL_SIZE + 10)
self.promoteToKnight.setIconSize(iconSize)
self.promoteToKnight.setIcon(QtGui.QIcon(self.getPathToIcon('n')))
self.promoteToBishop.setIconSize(iconSize)
self.promoteToBishop.setIcon(QtGui.QIcon(self.getPathToIcon('b')))
self.promoteToRook.setIconSize(iconSize)
self.promoteToRook.setIcon(QtGui.QIcon(self.getPathToIcon('r')))
self.promoteToQueen.setIconSize(iconSize)
self.promoteToQueen.setIcon(QtGui.QIcon(self.getPathToIcon('q')))
self.promotionButtons.buttonClicked.connect(self.promote)
def getPathToIcon(self, pieceLetter):
return resourcePath(P_DIR +
pieceLetter.lower() +
("w" if self.piecesColor == chess.WHITE
else "b") +
P_EXT)
def promote(self, button):
if button is self.promoteToKnight:
self.promotion = chess.KNIGHT
elif button is self.promoteToBishop:
self.promotion = chess.BISHOP
elif button is self.promoteToRook:
self.promotion = chess.ROOK
elif button is self.promoteToQueen:
self.promotion = chess.QUEEN
self.accept()
def getPromotion(self):
return self.promotion