...
 
Commits (3)
...@@ -7,6 +7,7 @@ pyuic5 --import-from=ui ui/game.ui -o ui/game_ui.py ...@@ -7,6 +7,7 @@ pyuic5 --import-from=ui ui/game.ui -o ui/game_ui.py
pyuic5 --import-from=ui ui/endgame.ui -o ui/endgame_ui.py pyuic5 --import-from=ui ui/endgame.ui -o ui/endgame_ui.py
pyuic5 --import-from=ui ui/options.ui -o ui/options_ui.py pyuic5 --import-from=ui ui/options.ui -o ui/options_ui.py
pyuic5 --import-from=ui ui/authquick.ui -o ui/authquick_ui.py pyuic5 --import-from=ui ui/authquick.ui -o ui/authquick_ui.py
pyuic5 --import-from=ui ui/authleague.ui -o ui/authleague_ui.py
pyuic5 --import-from=ui ui/leaderboard.ui -o ui/leaderboard_ui.py pyuic5 --import-from=ui ui/leaderboard.ui -o ui/leaderboard_ui.py
# Custom widgets # Custom widgets
......
...@@ -48,7 +48,7 @@ class MainWin(QtWidgets.QMainWindow): ...@@ -48,7 +48,7 @@ class MainWin(QtWidgets.QMainWindow):
self.ui.panels.setCurrentIndex(0) self.ui.panels.setCurrentIndex(0)
self.ui.panels.currentWidget().setFocus() self.ui.panels.currentWidget().setFocus()
self.ui.panels.currentWidget().grabKeyboard() self.ui.panels.setFocusProxy(self.ui.panels.currentWidget())
self.ui.panels.currentWidget().load() self.ui.panels.currentWidget().load()
self.displaySystemTime() self.displaySystemTime()
self.startTimer(1000) self.startTimer(1000)
......
...@@ -32,19 +32,20 @@ class Module(QtWidgets.QWidget): ...@@ -32,19 +32,20 @@ class Module(QtWidgets.QWidget):
logging.error('Unknown panel {}'.format(new_type)) logging.error('Unknown panel {}'.format(new_type))
else: else:
# Unfocus the current module # Unfocus the current module
self.mainwin.ui.panels.currentWidget().releaseKeyboard()
if QApplication.focusWidget() != None: if QApplication.focusWidget() != None:
QApplication.focusWidget().clearFocus() QApplication.focusWidget().clearFocus()
# Swap modules by unloading, changing the ui then loading # Swap modules by unloading, changing the ui then loading
self.mainwin.modules[curmod_idx].unload() self.mainwin.modules[curmod_idx].unload()
self.mainwin.ui.panels.setCurrentIndex(newmod_idx) self.mainwin.ui.panels.setCurrentIndex(newmod_idx)
self.mainwin.ui.panels.setFocusProxy(self.mainwin.modules[newmod_idx])
self.mainwin.modules[newmod_idx].setFocus()
self.mainwin.modules[newmod_idx].load() self.mainwin.modules[newmod_idx].load()
# Select first element of the Module # Select first element of the Module
self.mainwin.modules[newmod_idx].focusNextChild() self.mainwin.modules[newmod_idx].focusNextChild()
self.mainwin.modules[newmod_idx].focusPreviousChild() self.mainwin.modules[newmod_idx].focusPreviousChild()
self.mainwin.modules[newmod_idx].grabKeyboard() self.mainwin.modules[newmod_idx].focusPreviousChild()
def send(self, to, **kwargs): def send(self, to, **kwargs):
mod_idx = self.mainwin.findMod(to) mod_idx = self.mainwin.findMod(to)
......
...@@ -17,18 +17,21 @@ from player import Side, Player, PlayerGuest ...@@ -17,18 +17,21 @@ from player import Side, Player, PlayerGuest
class AuthModuleBase(Module): class AuthModuleBase(Module):
def __init__(self, parent, widget): def __init__(self, parent, widget):
super().__init__(parent, widget) super().__init__(parent, widget)
self.players = {Side.Left: list(), Side.Right: list()} self.createPlayerList()
self.numPlayers = 0
def load(self): def load(self):
pass pass
def unload(self): def unload(self):
self.players = {Side.Left: list(), Side.Right: list()} self.createPlayerList()
self.numPlayers = 0
def other(self, **kwargs): def other(self, **kwargs):
for key, val in kwargs.items(): for key, val in kwargs.items():
if key=='rfid' and 'source' in kwargs: if key=='rfid' and 'source' in kwargs:
side = kwargs['source'] side = kwargs['source']
self.numPlayers += 1
self.addPlayer(side, Player.fromRFID(val)) self.addPlayer(side, Player.fromRFID(val))
def keyPressEvent(self, e): def keyPressEvent(self, e):
...@@ -40,10 +43,10 @@ class AuthModuleBase(Module): ...@@ -40,10 +43,10 @@ class AuthModuleBase(Module):
elif e.key() == Qt.Key_Left or e.key() == Qt.Key_Right: elif e.key() == Qt.Key_Left or e.key() == Qt.Key_Right:
side = Side.Left if e.key() == Qt.Key_Left else Side.Right side = Side.Left if e.key() == Qt.Key_Left else Side.Right
rfid = -2*(side.value+1) - (self.players[side][0]!=PlayerGuest) rfid = -(2 + self.numPlayers%5)
self.send(type(self), rfid=rfid, source=side) self.send(type(self), rfid=rfid, source=side)
def addPlayer(self, side, player): def createPlayerList(self):
logging.warning('Base function meant to be reimplemented') logging.warning('Base function meant to be reimplemented')
def handleCancel(self): def handleCancel(self):
......
...@@ -8,17 +8,55 @@ Created on Wed Apr 18 18:34:40 2018 ...@@ -8,17 +8,55 @@ Created on Wed Apr 18 18:34:40 2018
import logging import logging
from PyQt5.QtWidgets import QAbstractItemView
from module import Module from module import Module
from ui.authquick_ui import Ui_Form as AuthQuickWidget from modules.auth import AuthModuleBase
from ui.authleague_ui import Ui_Form as AuthLeagueWidget
class AuthLeagueModule(Module): from player import Side, PlayerEmpty
class AuthLeagueModule(AuthModuleBase):
def __init__(self, parent): def __init__(self, parent):
super().__init__(parent, AuthQuickWidget()) super().__init__(parent, AuthLeagueWidget())
def load(self): def load(self):
logging.debug('Loading AuthLeagueModule') logging.debug('Loading AuthLeagueModule')
super().load() super().load()
self.addPlayer(Side.Left, PlayerEmpty)
def unload(self): def unload(self):
logging.debug('Loading AuthLeagueModule') logging.debug('Loading AuthLeagueModule')
super().load() super().unload()
self.ui.playersList.clear()
def createPlayerList(self):
'''
Duplicates the player list to be the same on both sides.
That way, adding a player on the left or on the right have the exact same effect,
and thus the AuthModuleBase code can remain generic.
'''
l = list()
self.players = {Side.Left: l, Side.Right: l}
def addPlayer(self, side, player):
# Add the player if not already in the list
if all([p.id!=player.id for p in self.players[side]]):
if player!=PlayerEmpty:
self.players[side].append(player)
# Update the left side description
player.displayImg(self.ui.img)
self.ui.lblName.setText(player.name)
self.ui.lblStat1.setText('{} Victories'.format(player.stats.victories))
self.ui.lblStat2.setText('{} Games Played'.format(player.stats.games_played))
self.ui.lblStat3.setText('{} Goals Scored'.format(player.stats.goals_scored))
if player!=PlayerEmpty:
# Update the right side list, making sure that the added player is showed
self.ui.playersList.addItem('{}. {}'.format(len(self.players[side]), player.name))
widgetItem = self.ui.playersList.item(self.ui.playersList.count()-1)
self.ui.playersList.scrollToItem(widgetItem, QAbstractItemView.PositionAtBottom)
def handleDone(self):
super().handleDone()
...@@ -40,7 +40,11 @@ class AuthQuickModule(AuthModuleBase): ...@@ -40,7 +40,11 @@ class AuthQuickModule(AuthModuleBase):
super().unload() super().unload()
#self.updateSides() #self.updateSides()
def createPlayerList(self):
self.players = {Side.Left: list(), Side.Right: list()}
def addPlayer(self, side, player): def addPlayer(self, side, player):
# If there is a placeholder Guest, clear it from the list, we don't need it anymore
if len(self.players[side])>0 and self.players[side][0]==PlayerGuest: if len(self.players[side])>0 and self.players[side][0]==PlayerGuest:
self.players[side].clear() self.players[side].clear()
......
...@@ -51,6 +51,13 @@ class Player(): ...@@ -51,6 +51,13 @@ class Player():
player = Player(id, 'Enzo', 'Arobaz') player = Player(id, 'Enzo', 'Arobaz')
player.stats.goals_scored = 1 player.stats.goals_scored = 1
elif id==-10:
player = Player(id, 'Name', '')
player.stats.victories = ''
player.stats.time_played = ''
player.stats.games_played = ''
player.stats.goals_scored = ''
else: else:
player = Player(id, fname, lname, pic_url) player = Player(id, fname, lname, pic_url)
...@@ -88,3 +95,4 @@ class Stat(): ...@@ -88,3 +95,4 @@ class Stat():
self.goals_scored = 0 self.goals_scored = 0
PlayerGuest = Player.fromRFID(-1) PlayerGuest = Player.fromRFID(-1)
PlayerEmpty = Player.fromRFID(-10)
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1280</width>
<height>720</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="font">
<font>
<pointsize>40</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Identify yourselves! </string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<pointsize>20</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Use the table's RFID reader with your card.</string>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>75</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="layoutP1P2">
<item>
<widget class="QWidget" name="widgetLayoutP1" native="true">
<layout class="QHBoxLayout" name="layoutP1">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="img">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>300</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblName">
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Name</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblStat1">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Stat</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblStat2">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Stat</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblStat3">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Stat</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>75</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>75</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QListWidget" name="playersList">
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="autoScroll">
<bool>true</bool>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>75</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="assets.qrc"/>
</resources>
<connections/>
</ui>