コード例 #1
0
	def __init__(self, parent=None, styleSheet=None, maxCards=None, cards=None):
		"""
		@param parent: (L{QWidget}) parent or None
		@param styleSheet: (str) stylesheet to apply to the widget
		@param maxCards: (int) maximum number of cards that can be selected or None for unlimited
		@param cards: (list) of L{PokerTools.Card}s to initialize the widget with
		QtGui.QFrame.__init__(self, parent)
		"""
		QtGui.QFrame.__init__(self, parent)
				
		self._maxCards = maxCards
		self._buttonsSelected = []
				
		# add card buttons
		self._cardButtons ={}	# card --> button
		for iCol, suitName in enumerate(PokerTools.Card.SuitNames):
			for iRow, rankName in enumerate(PokerTools.Card.RankNames[::-1]):
				card = PokerTools.Card(rankName+suitName)
				btn = CardButton(card, iRow, iCol, parent=self)
				btn.setStyleSheet(self.StyleSheet if styleSheet is None else styleSheet)
				self._cardButtons[card] = btn
				btn.toggled.connect(self.onCardButtonToggled)
		
		self.handleFontChanged()
		
		# layout
		
		box0 = QtGui.QHBoxLayout(self)
		box0.setSpacing(0)
		box0.setContentsMargins(0, 0, 0, 0)
		box1 = QtGui.QVBoxLayout()
		box0.addLayout(box1)
		
		s = QtGui.QHBoxLayout()
		s.addStretch(999)
		box0.addItem(s)
		
		grid1 = QtGui.QGridLayout()
		#grid1.setSpacing(0)
		#grid1.setContentsMargins(0, 0, 0, 0)
		for btn in self._cardButtons.values():
			grid1.addWidget(btn, btn.iRow, btn.iCol)
					
		box1.addLayout(grid1)
				
		s = QtGui.QVBoxLayout()
		s.addStretch(999)
		box1.addItem(s)
		
		# init widget with cards passed
		if cards is not None:
			for card in cards:
				self._cardButtons[card].setChecked(True)	
コード例 #2
0
		h = w
		fixedSize = QtCore.QSize(w, h)
		for btn in self._cardButtons.values():
			btn.fixedSize = fixedSize
			btn.setMinimumSize(fixedSize)
				
	def onCardButtonToggled(self, flag):
		btn = self.sender()
		if flag:
			if btn not in self._buttonsSelected:
				self._buttonsSelected.append(btn)
			if self._maxCards is not None and len(self._buttonsSelected) > self._maxCards:
				btn = self._buttonsSelected.pop(0)
				btn.setChecked(False)
		else:
			if btn in self._buttonsSelected:
				self._buttonsSelected.remove(btn)
		self.cardsSelectionChanged.emit(self)
		
#************************************************************************************
#
#************************************************************************************
if __name__ == '__main__':
	import sys
	application = QtGui.QApplication(sys.argv)
	gui = CardSelectorWidget(
			maxCards=3, 
			cards=[PokerTools.Card('Ah'), PokerTools.Card('Kd'), PokerTools.Card('Qc')])
	gui.show()
	application.exec_()
コード例 #3
0
 def HAND(klass, *cards):
     return [PokerTools.Card(card) for card in cards]