...
 
Commits (3)
...@@ -75,7 +75,7 @@ class Database(): ...@@ -75,7 +75,7 @@ class Database():
self._connection.commit() self._connection.commit()
def delete_playerpic(self, playerID): def delete_playerpic(self, playerID):
self._cursor.execute('UPDATE Players SET pic=null WHERE id==?', (playerID,)) self._cursor.execute('UPDATE Players SET login=null WHERE id==?', (playerID,))
self._connection.commit() self._connection.commit()
def make_player_private(self, playerID): def make_player_private(self, playerID):
......
...@@ -46,9 +46,13 @@ class Downloader(Thread, QObject): ...@@ -46,9 +46,13 @@ class Downloader(Thread, QObject):
if nAttemps==None: if nAttemps==None:
nAttemps = Downloader.N_ATTEMPS nAttemps = Downloader.N_ATTEMPS
print('Adding "{}". {} before it'.format(url_in, len(self._request_stack))) # Add if not already queued
req = (url_in, uri_out, nAttemps)
self._request_stack.append((url_in, uri_out, nAttemps)) if req not in self._request_stack:
logging.debug('Adding "{}". {} before it'.format(url_in, len(self._request_stack)))
self._request_stack.append(req)
else:
logging.debug('"{}" is already queued, ignoring.'.format(url_in))
def run(self): def run(self):
while not self._close: while not self._close:
......
...@@ -49,7 +49,7 @@ class Input(QObject): ...@@ -49,7 +49,7 @@ class Input(QObject):
def __init__(self): def __init__(self):
QObject.__init__(self) QObject.__init__(self)
if ON_RASP: if ON_RASP:
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
for pin in Input._keyButtonBindings.keys(): for pin in Input._keyButtonBindings.keys():
...@@ -62,12 +62,14 @@ class Input(QObject): ...@@ -62,12 +62,14 @@ class Input(QObject):
self.goalThread = GoalThread(self, **Input._GoalPins) self.goalThread = GoalThread(self, **Input._GoalPins)
def start(self): def start(self):
self.rfidThread.start() if ON_RASP:
self.goalThread.start() self.rfidThread.start()
self.goalThread.start()
def stop(self): def stop(self):
self.rfidThread.stop(); self.rfidThread.join() if ON_RASP:
self.goalThread.stop(); self.goalThread.join() self.rfidThread.stop(); self.rfidThread.join()
self.goalThread.stop(); self.goalThread.join()
def _handleButtonPress(self, button_pin): def _handleButtonPress(self, button_pin):
if button_pin not in Input._keyButtonBindings.keys(): if button_pin not in Input._keyButtonBindings.keys():
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
@author: Antoine Lima, Leo Reynaert, Domitille Jehenne @author: Antoine Lima, Leo Reynaert, Domitille Jehenne
""" """
import os
import logging import logging
from enum import Enum from enum import Enum
from http import HTTPStatus from http import HTTPStatus
...@@ -13,6 +14,7 @@ from PyQt5.QtGui import QPixmap ...@@ -13,6 +14,7 @@ from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QDialog, QApplication from PyQt5.QtWidgets import QDialog, QApplication
from Babyfut.babyfut import getMainWin, IMG_PATH from Babyfut.babyfut import getMainWin, IMG_PATH
from Babyfut.core.downloader import Downloader
from Babyfut.core.ginger import Ginger from Babyfut.core.ginger import Ginger
from Babyfut.core.database import Database, DatabaseError from Babyfut.core.database import Database, DatabaseError
from Babyfut.ui.consent_dialog_ui import Ui_Dialog as ConsentDialogUI from Babyfut.ui.consent_dialog_ui import Ui_Dialog as ConsentDialogUI
...@@ -57,19 +59,24 @@ class ConsentDialog(QDialog): ...@@ -57,19 +59,24 @@ class ConsentDialog(QDialog):
self.reject() self.reject()
class Player(QObject): class Player(QObject):
__query_infos = 'SELECT id, fname, lname, pic FROM Players WHERE rfid==?' __query_infos = 'SELECT id, login, fname, lname FROM Players WHERE rfid==?'
__query_time_goals_games = 'SELECT SUM(Matchs.duration) AS timePlayed, SUM(Teams.nGoals) AS goalsScored, COUNT(*) AS gamesPlayed FROM Teams INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam OR Teams.id==Matchs.losingTeam) WHERE (Teams.player1==? OR player2==?)' __query_time_goals_games = 'SELECT SUM(Matchs.duration) AS timePlayed, SUM(Teams.nGoals) AS goalsScored, COUNT(*) AS gamesPlayed FROM Teams INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam OR Teams.id==Matchs.losingTeam) WHERE (Teams.player1==? OR player2==?)'
__query_victories = 'SELECT COUNT(*) AS victories FROM Players INNER JOIN Teams ON (Players.id==Teams.player1 OR Players.id==Teams.player2) INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam) WHERE Players.id==?' __query_victories = 'SELECT COUNT(*) AS victories FROM Players INNER JOIN Teams ON (Players.id==Teams.player1 OR Players.id==Teams.player2) INNER JOIN Matchs ON (Teams.id==Matchs.winningTeam) WHERE Players.id==?'
_placeholder_pic_path = ':ui/img/placeholder_head.jpg' _placeholder_pic_path = ':ui/img/placeholder_head.jpg'
_utcPictureURL = 'https://demeter.utc.fr/portal/pls/portal30/portal30.get_photo_utilisateur?username={}'
def __init__(self, id, rfid, fname, lname, pic_path, stats=None): def __init__(self, id, rfid, login, fname, lname, stats=None):
QObject.__init__(self) QObject.__init__(self)
self.id = id self.id = id
self.rfid = rfid self.rfid = rfid
self.login = login
self.fname = fname self.fname = fname
self.lname = lname self.lname = lname
self.pic_path = pic_path if pic_path else Player._placeholder_pic_path # Default pic if None
self.pic_path = Player._placeholder_pic_path
if self.login:
self.pic_path = Player._utcPictureURL.format(self.login)
if stats==None: if stats==None:
self.stats = { 'time_played': 0, 'goals_scored': 0, 'games_played': 0, 'victories': 0 } self.stats = { 'time_played': 0, 'goals_scored': 0, 'games_played': 0, 'victories': 0 }
...@@ -89,7 +96,7 @@ class Player(QObject): ...@@ -89,7 +96,7 @@ class Player(QObject):
if consentDialog.result()==QDialog.Accepted: if consentDialog.result()==QDialog.Accepted:
player = Player._loadFromAPI(rfid) player = Player._loadFromAPI(rfid)
else: else:
logging.debug('Consent refused when retrieving a player, returning Guest') logging.info('Consent refused when retrieving a player, returning Guest')
player = PlayerGuest player = PlayerGuest
return player return player
...@@ -99,7 +106,7 @@ class Player(QObject): ...@@ -99,7 +106,7 @@ class Player(QObject):
db = Database.instance() db = Database.instance()
try: try:
# Retrieve generic informations # Retrieve generic informations
id, fname, lname, pic = db.select_one(Player.__query_infos, rfid) id, login, fname, lname = db.select_one(Player.__query_infos, rfid)
# Retrieve stats # Retrieve stats
stats = {} stats = {}
...@@ -110,7 +117,7 @@ class Player(QObject): ...@@ -110,7 +117,7 @@ class Player(QObject):
if val==None: if val==None:
stats[key] = 0 stats[key] = 0
return Player(id, rfid, fname, lname, pic, stats) return Player(id, rfid, login, fname, lname, stats)
except DatabaseError as e: except DatabaseError as e:
logging.warn('DB Error: {}'.format(e)) logging.warn('DB Error: {}'.format(e))
...@@ -123,11 +130,11 @@ class Player(QObject): ...@@ -123,11 +130,11 @@ class Player(QObject):
''' '''
response = Ginger.instance.get('badge/{}'.format(rfid)) response = Ginger.instance.get('badge/{}'.format(rfid))
if isinstance(response, HTTPStatus): if isinstance(response, HTTPStatus):
logging.debug('Request to Ginger failed ({}): returning Guest'.format(response.value)) logging.warn('Request to Ginger failed ({}): returning Guest'.format(response.value))
return PlayerGuest return PlayerGuest
else: else:
infos = json.loads(response) infos = json.loads(response)
Database.instance().insert_player(infos['rfid'], infos['nom'], infos['prenom']) Database.instance().insert_player(infos['rfid'], infos['login'], infos['nom'], infos['prenom'])
return Player._loadFromDB(rfid) return Player._loadFromDB(rfid)
...@@ -135,24 +142,28 @@ class Player(QObject): ...@@ -135,24 +142,28 @@ class Player(QObject):
self.pic_container = container_widget self.pic_container = container_widget
if self.pic_path.startswith('http'): if self.pic_path.startswith('http'):
# Download from the internet # Download from the internet but display a temporary image between
self.pic_container.setStyleSheet('border-image: url({});'.format(Player._placeholder_pic_path)) self.pic_container.setStyleSheet('border-image: url({});'.format(Player._placeholder_pic_path))
Downloader.instance().request(self.pic_path, os.path.join(IMG_PATH, '{}.jpg'.format(self.id))) Downloader.instance().request(self.pic_path, os.path.join(IMG_PATH, '{}.jpg'.format(self.id)))
Downloader.instance().finished.connect(self._downloader_callback) Downloader.instance().finished.connect(self._downloader_callback)
else: else:
# Already downloaded and stored locally # Already downloaded and stored locally
self.pic_container.setStyleSheet('border-image: url({});'.format(self.pic_path)) self.pic_container.setStyleSheet('border-image: url({});'.format(self.pic_path))
self._forceWidgetUpdate()
QApplication.processEvents() QApplication.processEvents()
@pyqtSlot(str) @pyqtSlot(str)
def _downloader_callback(self, path): def _downloader_callback(self, path):
self.pic_path = path # Take the callback if not already done and we are the targer
Downloader.instance().finished.disconnect(self._downloader_callback) if IMG_PATH in path and str(self.id) in path and IMG_PATH not in self.pic_path:
self.displayImg(self.pic_container) self.pic_path = path
Downloader.instance().finished.disconnect(self._downloader_callback)
if self.pic_container!=None:
self.displayImg(self.pic_container)
def forgetPicture(self): def forgetPicture(self):
self.pic_path = Player._placeholder_pic_path self.pic_path = Player._placeholder_pic_path
self.login = None
Database.instance().delete_playerpic(self.id) Database.instance().delete_playerpic(self.id)
def make_private(self): def make_private(self):
......
This diff is collapsed.
...@@ -97,36 +97,15 @@ ...@@ -97,36 +97,15 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QLabel" name="img"> <widget class="QWidget" name="img" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>300</width> <width>300</width>
<height>300</height> <height>300</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="styleSheet">
<size> <string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
<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> </property>
</widget> </widget>
</item> </item>
......
...@@ -107,9 +107,9 @@ ...@@ -107,9 +107,9 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QLabel" name="imgP1"> <widget class="QWidget" name="imgP1" native="true">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
...@@ -126,17 +126,8 @@ ...@@ -126,17 +126,8 @@
<height>200</height> <height>200</height>
</size> </size>
</property> </property>
<property name="text"> <property name="styleSheet">
<string/> <string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</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> </property>
</widget> </widget>
</item> </item>
...@@ -185,9 +176,9 @@ ...@@ -185,9 +176,9 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
<widget class="QLabel" name="imgP2"> <widget class="QWidget" name="imgP2" native="true">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
...@@ -204,14 +195,8 @@ ...@@ -204,14 +195,8 @@
<height>200</height> <height>200</height>
</size> </size>
</property> </property>
<property name="text"> <property name="styleSheet">
<string/> <string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -337,9 +322,9 @@ ...@@ -337,9 +322,9 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QLabel" name="imgP3"> <widget class="QWidget" name="imgP3" native="true">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
...@@ -356,14 +341,8 @@ ...@@ -356,14 +341,8 @@
<height>200</height> <height>200</height>
</size> </size>
</property> </property>
<property name="text"> <property name="styleSheet">
<string/> <string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -412,9 +391,9 @@ ...@@ -412,9 +391,9 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_9"> <layout class="QHBoxLayout" name="horizontalLayout_9">
<item> <item>
<widget class="QLabel" name="imgP4"> <widget class="QWidget" name="imgP4" native="true">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
...@@ -431,14 +410,8 @@ ...@@ -431,14 +410,8 @@
<height>200</height> <height>200</height>
</size> </size>
</property> </property>
<property name="text"> <property name="styleSheet">
<string/> <string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property>
<property name="pixmap">
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
......
...@@ -69,13 +69,7 @@ ...@@ -69,13 +69,7 @@
<widget class="QWidget" name="widgetLayoutP1" native="true"> <widget class="QWidget" name="widgetLayoutP1" native="true">
<layout class="QVBoxLayout" name="layoutP1"> <layout class="QVBoxLayout" name="layoutP1">
<item> <item>
<widget class="QLabel" name="imgP1"> <widget class="QWidget" name="imgP1" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>400</width> <width>400</width>
...@@ -84,18 +78,18 @@ ...@@ -84,18 +78,18 @@
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>300</width> <width>400</width>
<height>300</height> <height>400</height>
</size> </size>
</property> </property>
<property name="text"> <property name="baseSize">
<string/> <size>
</property> <width>400</width>
<property name="pixmap"> <height>400</height>
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap> </size>
</property> </property>
<property name="scaledContents"> <property name="styleSheet">
<bool>true</bool> <string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -159,13 +153,7 @@ ...@@ -159,13 +153,7 @@
<widget class="QWidget" name="widgetLayoutP2" native="true"> <widget class="QWidget" name="widgetLayoutP2" native="true">
<layout class="QVBoxLayout" name="layoutP2"> <layout class="QVBoxLayout" name="layoutP2">
<item> <item>
<widget class="QLabel" name="imgP2"> <widget class="QWidget" name="ImgP2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>400</width> <width>400</width>
...@@ -174,18 +162,18 @@ ...@@ -174,18 +162,18 @@
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>300</width> <width>400</width>
<height>300</height> <height>400</height>
</size> </size>
</property> </property>
<property name="text"> <property name="baseSize">
<string/> <size>
</property> <width>400</width>
<property name="pixmap"> <height>400</height>
<pixmap resource="assets.qrc">:/ui/img/placeholder_head.jpg</pixmap> </size>
</property> </property>
<property name="scaledContents"> <property name="styleSheet">
<bool>true</bool> <string notr="true">border-image: url(:/ui/img/placeholder_head.jpg);</string>
</property> </property>
</widget> </widget>
</item> </item>
......