Adding players is now working

This commit is contained in:
Sebastian Lohff 2013-12-07 20:44:17 +01:00
parent afe4985bcc
commit c75098f8ce
2 changed files with 15 additions and 5 deletions

View File

@ -28,9 +28,14 @@ class SeopardyGame(QtGui.QWidget):
if self.gamestate.get_state() == "start": if self.gamestate.get_state() == "start":
QtCore.QCoreApplication.postEvent(self, GameStartEvent()) 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)) 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): def _createGui(self):
""" Create the board from questions. """ """ Create the board from questions. """

View File

@ -348,12 +348,17 @@ class PlayerStartWindow(QtGui.QDialog):
def event(self, e): def event(self, e):
if e.type() == ButtonEvent.eventType: 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 # add a new player
self._parent.add_player() self._parent.add_player(addToGui=True)
self._guiAddPlayer(self._players[-1]) 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 return True
else: else:
return super(PlayerStartWindow, self).event(e) return super(PlayerStartWindow, self).event(e)