From c75098f8cee2929bc8c7dc6a6df65c6101578748 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sat, 7 Dec 2013 20:44:17 +0100 Subject: [PATCH] Adding players is now working --- game.py | 7 ++++++- windows.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/game.py b/game.py index 0e988b8..023dc9f 100644 --- a/game.py +++ b/game.py @@ -28,9 +28,14 @@ class SeopardyGame(QtGui.QWidget): if self.gamestate.get_state() == "start": QtCore.QCoreApplication.postEvent(self, GameStartEvent()) - def add_player(self): + def add_player(self, addToGui=False): self.players.append(Player.gen_player(len(self.players)+1, self)) + if addToGui: + if len(self.players) > 1: + self.playerBar.addStretch() + self.playerBar.addWidget(self.players[-1]) + def _createGui(self): """ Create the board from questions. """ diff --git a/windows.py b/windows.py index 24e30da..657d7ca 100644 --- a/windows.py +++ b/windows.py @@ -348,12 +348,17 @@ class PlayerStartWindow(QtGui.QDialog): def event(self, e): if e.type() == ButtonEvent.eventType: - if e.get_playerno() <= len(self.players)+1: - if e.get_playerno() == len(self.players)+1: + if e.get_playerno() <= len(self._players)+1: + if e.get_playerno() == len(self._players)+1: # add a new player - self._parent.add_player() + self._parent.add_player(addToGui=True) self._guiAddPlayer(self._players[-1]) - self.playergrid.itemAtPosition(e.get_playerno()-1, 1).selectAll() + + layoutItem = self.playerGrid.itemAtPosition(e.get_playerno(), 1) + if layoutItem: + widget = layoutItem.widget() + widget.selectAll() + widget.setFocus() return True else: return super(PlayerStartWindow, self).event(e)