Permalink
Browse files

Merge branch 'master' of git://github.com/KenMacD/tarabish

Conflicts:
	client/qt/src/tarabish/qt/table.py
  • Loading branch information...
2 parents ebe95a2 + c928b8b commit 6320eacad15ab1493f461b52ac0f48866a831386 @mstead committed Sep 8, 2011
Showing with 94 additions and 10 deletions.
  1. +85 −6 client/qt/src/tarabish/qt/table.py
  2. +9 −4 client/qt/test/test_events.py
@@ -1,13 +1,18 @@
+from functools import partial
+
from tarabish.thrift.constants import (CLUBS, SPADES, HEARTS, DIAMONDS)
from tarabish.thrift.constants import (JACK, QUEEN, KING, ACE)
from tarabish.thrift.ttypes import (Card, EventType)
-
-from PySide.QtCore import QSize
+from PySide.QtCore import (Signal, QSize, QPoint, Qt)
from PySide.QtGui import *
+# General cards seem to be 2.5" by 3.5", so match that ratio
+CARD_WIDTH = 64
+CARD_HEIGHT = 90
+
class ChatWidget(QWidget):
- def __init__(self):
- super(ChatWidget, self).__init__()
+ def __init__(self, parent=None):
+ super(ChatWidget, self).__init__(parent)
send_button = QPushButton("Send")
self.message_box = QLineEdit()
self.messages = QTextBrowser()
@@ -28,7 +33,45 @@ def _send_message(self):
self.messages.append(self.message_box.text())
self.message_box.clear()
+class TableTopWidget(QWidget):
+ MARGIN = 6
+
+ def __init__(self, parent=None):
+ super(TableTopWidget, self).__init__(parent)
+
+ self.width = CARD_WIDTH * 3 + self.MARGIN * 2
+ self.height = CARD_HEIGHT * 3 + self.MARGIN * 2
+ self.setFixedSize(self.width, self.height)
+
+ self.north_position = QPoint(CARD_WIDTH + self.MARGIN, 0)
+ self.west_position = QPoint(0, CARD_HEIGHT + self.MARGIN)
+ self.south_position = QPoint(CARD_WIDTH + self.MARGIN,
+ CARD_HEIGHT * 2+ self.MARGIN * 2)
+ self.east_position = QPoint(CARD_WIDTH * 2 + self.MARGIN * 2,
+ CARD_HEIGHT + self.MARGIN)
+
+ n = CardWidget(Card(2, SPADES), self)
+ n.move(self.north_position)
+
+ s = CardWidget(Card(4, SPADES), self)
+ s.move(self.south_position)
+
+ e = CardWidget(Card(3, SPADES), self)
+ e.move(self.east_position)
+
+ w = CardWidget(Card(5, SPADES), self)
+ w.move(self.west_position)
+
+ def sizeHint(self):
+ return self.minimumSizeHint()
+
+ def minimumSizeHint(self):
+ return QSize(self.width, self.height)
+
+
class CardWidget(QWidget):
+ doubleclicked = Signal()
+
suit = {CLUBS: "C", SPADES: "S", HEARTS: "H", DIAMONDS: "D"}
value = {JACK: "J", QUEEN: "Q", KING: "K", ACE: "A"}
@@ -38,7 +81,7 @@ def __init__(self, pyCard, parent=None):
self.card = pyCard
frame = QFrame(self)
frame.setFrameStyle(QFrame.Box);
- frame.setFixedSize(70, 90)
+ frame.setFixedSize(CARD_WIDTH, CARD_HEIGHT)
suit = CardWidget.suit[pyCard.suit]
if pyCard.value > 10:
@@ -55,10 +98,14 @@ def sizeHint(self):
return self.minimumSizeHint()
def minimumSizeHint(self):
- return QSize(70, 90)
+ return QSize(CARD_WIDTH, CARD_HEIGHT)
+ def mouseDoubleClickEvent(self, event):
+ self.doubleclicked.emit()
class CardBoxWidget(QWidget):
+ doubleclicked = Signal(Card)
+
def __init__(self, cards=None, trump=None, parent=None):
super(CardBoxWidget, self).__init__(parent)
@@ -76,10 +123,14 @@ def __init__(self, cards=None, trump=None, parent=None):
def add_cards(self, cards):
for card in cards:
item = CardWidget(card)
+ item.doubleclicked.connect(partial(self.cardDoubleClickEvent, card))
self.cards.append(item)
self.cardLayout.insertWidget(self.cardLayout.count() - 1, item)
+ def cardDoubleClickEvent(self, card):
+ self.doubleclicked.emit(card)
+
def del_card(self, index):
self.cards.pop(index)
card = self.cardLayout.takeAt(index)
@@ -99,13 +150,37 @@ def __init__(self, tableId, eventDispatcher, logger, parent=None):
vbox = QVBoxLayout()
+ top_grid = QGridLayout()
+
+ self.north_label = QLabel("<empty>")
+ self.north_label.setAlignment(Qt.AlignCenter)
+ top_grid.addWidget(self.north_label, 0, 1)
+
+ self.west_label = QLabel("<empty>")
+ self.west_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
+ top_grid.addWidget(self.west_label, 1, 0)
+
+ self.east_label = QLabel("<empty>")
+ self.east_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
+ top_grid.addWidget(self.east_label, 1, 2)
+
+ self.south_label = QLabel("<empty>")
+ self.south_label.setAlignment(Qt.AlignCenter)
+ top_grid.addWidget(self.south_label, 2, 1)
+
+ table_top = TableTopWidget()
+ top_grid.addWidget(table_top, 1, 1)
+
+ vbox.addLayout(top_grid)
+
testButton = QPushButton("Create cards")
testButton2 = QPushButton("Remove first card")
vbox.addWidget(testButton)
vbox.addWidget(testButton2)
cards = [Card(10, CLUBS), Card(ACE, HEARTS)]
self.cardBox = CardBoxWidget(cards)
+ self.cardBox.doubleclicked.connect(self.play_card)
vbox.addWidget(self.cardBox)
vbox.addLayout(hbox)
@@ -116,6 +191,10 @@ def __init__(self, tableId, eventDispatcher, logger, parent=None):
testButton.clicked.connect(self.testNewCard)
testButton2.clicked.connect(self.testDelCard)
+ def play_card(self, card):
+ self.logger.append("Table %d Playing card %s %s" % (self.tableId,
+ str(card.value), str(card.suit)))
+
def testNewCard(self):
self.cardBox.add_cards([Card(JACK, SPADES), Card(9, DIAMONDS)])
@@ -7,23 +7,28 @@
from tarabish.thrift.ttypes import EventType, Event
+class StubSignal(object):
+ def connect(self, method):
+ pass
+
+
class EventRegistryTests(unittest.TestCase):
def test_connect_adds_new_type(self):
- dispatcher = EventDispatcher()
+ dispatcher = EventDispatcher(StubSignal())
self.assertFalse(EventType.CHAT in dispatcher.event_connections)
dispatcher.connect(EventType.CHAT, self.a_method)
self.assertTrue(EventType.CHAT in dispatcher.event_connections)
def test_connect_adds_dispatchable(self):
- dispatcher = EventDispatcher()
+ dispatcher = EventDispatcher(StubSignal())
dispatcher.connect(EventType.CHAT, self.a_method)
self.assertTrue(EventType.CHAT in dispatcher.event_connections)
self.assertEquals(1, len(dispatcher.event_connections[EventType.CHAT]))
self.assertEquals(self.a_method, dispatcher.event_connections[EventType.CHAT][0].method)
def test_connect_adds_multiple_displatchables(self):
- dispatcher = EventDispatcher()
+ dispatcher = EventDispatcher(StubSignal())
dispatcher.connect(EventType.CHAT, self.a_method)
dispatcher.connect(EventType.CHAT, self.b_method)
self.assertTrue(EventType.CHAT in dispatcher.event_connections)
@@ -37,7 +42,7 @@ def test_dispatch_called_on_all_dispatchables(self):
def update_count(type):
self.calls += 1
- dispatcher = EventDispatcher()
+ dispatcher = EventDispatcher(StubSignal())
dispatcher.connect(EventType.CHAT, update_count)
dispatcher.connect(EventType.CHAT, update_count)
dispatcher.connect(EventType.SIT, update_count)

0 comments on commit 6320eac

Please sign in to comment.